Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Given a type Money that is a structured type with two int fields, dollars and

ID: 3630328 • Letter: 1

Question

1. Given a type Money that is a structured type with two int fields, dollars and cents declare an array monthlySales with 12 elements of type Money.
2. Given a type Money that is a structured type with two int fields, dollars and cents. Assume that an array named monthlySales with 12 elements, each of type Money has been declared and initialized.
Assume that a Money variable yearlySales has also been declared. Write the necessary code that traverses the monthlySales array and adds it all up and stores the resulting total in yearlySales. Be sure make sure that yearlySales ends up with a valid value, i.e. a value of cents that is less than 100.
3. Assume that BlogComment is a structured type with these fields, comment (a string, the actual comment), and two int fields: like, dislike which count the number of "likes" and "dislikes" of the comment by visitors. Assume that nComments is an int variable that holds the length of an array named blogComments whose elements are of type BlogComment. This array has been declared and initialized. You may assume that the array is not empty.
Assume that an string variable mostControversial has been declared. Write the necessary code that traverses the blogComments array and find the entry that is most controversial and assign its comment field to mostControversial. Measure the degree of controversy by multiplying likes and dislikes. (See how it works? Imagine 10 comments. If that is 10 likes and no dislikes, it is not controversial and 10 times 0 is 0. But if it is evenly split, 5 and 5, then it is controversial, and 5 times 5 is 25... a lot more than 0.)

Explanation / Answer

1. Given a type Money that is a structured type with two int fields, dollars and cents declare an array monthlySales with 12 elements of type Money.

struct Money

{

int dollars;

int cents;

};

struct Money monthlySales[12];

for(int i=0; i<12; i++)

{

monthlySales[i].dollars = 0;

monthlySales[i].cents = 0;

}