205k views
0 votes
Consider the following statements:

struct supplierType
{
string name;
int supplierID;
};

struct applianceType
{
supplierType supplier;
string modelNo;
double cost;
};

applianceType applianceList[25];

Which of the following statements correctly initializes the cost of each appliance to 0?
A. cost = 0;
B. applianceList.cost = 0;
C. applianceList[i].cost = 0;
D. applianceType.cost = 0;

User Fahad Abid
by
9.2k points

1 Answer

1 vote

Final answer:

The correct statement to initialize the cost of each appliance to 0 in an array of structures is 'applianceList[i].cost = 0;' using a for loop to iterate through each element of the array.

Step-by-step explanation:

The question pertains to the initialization of an array of structures in C++. To correctly initialize the cost of each appliance to 0 in the array applianceList, you would need to use a loop to iterate through each element and set the cost for each one. The correct option is:

C. applianceList[i].cost = 0;

To implement this, you could use a for loop like so:

for(int i = 0; i < 25; i++) { applianceList[i].cost = 0; }

This loop goes through each index of the applianceList array and initializes the cost field to 0 for each applianceType object.

User Suraj Nayak
by
7.6k points