In C++ Write a loop that will step through the entire array you define below and
ID: 3585582 • Letter: I
Question
In C++ Write a loop that will step through the entire array you define below and set all the product description to an empty string, all part numbers to zero , and all costs to zeroClass product { String description; Int partNum; Double Cost; }; In C++ Write a loop that will step through the entire array you define below and set all the product description to an empty string, all part numbers to zero , and all costs to zero
Class product { String description; Int partNum; Double Cost; };
Class product { String description; Int partNum; Double Cost; };
Explanation / Answer
// please commnet below if you have any doubts
// as it is not give that the variables in class are public or private, assuming it as public
Class product
{
String description;
Int partNum;
Double Cost;
};
// let the size of array be 10
product p[10];
// assuming that the valriabes in product class are public,
// we can directly assign enpty string or 0 to the variables
// else if the variables are private we need to use setter and getter
//loop that will step through the entire array
for(i=0;i<10;i++)
{
// set all the product description to an empty string, all part numbers to zero , and all costs to zero
p[i].description = "";
p[i].partNum = 0;
p[i].Cost = 0;
}