Question

Given a type Money that is a structured type with two int fields, dollars and cents. Assume that an array named monthlyS...

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.
0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include
#include
struct Money
{
int dollars;
int cents;
};
void main()
{
int i;
Money monthlySales[12];
Money yearlySales;
cout<<"Enter the dollars of each month :";
for(i=0;i<12;++i)
cin>>monthlySales[i].dollars;
cout<<"Enter the cents of each month :";
for(i=0;i<12;++i)
cin>>monthlySales[i].cents;
cout<<"\nMONTHLY SALES\n";
for(i=0;i<12;++i)
{ cout<<"month -> "< yearlySales.dollars+=monthlySales[i].dollars;

yearlySales.cents +=monthlySales[i].cents;

}
cout<<"\nyearly sales \n dollars :"<< yearlySales.dollars<<" cents :
< }
Add a comment
Answer #2

#include

using namespace std;

struct Money

{

int dollars;

int cents;

};

int main()

{

struct Money monthlySales[12];

struct Money yearlySales = { 0,0};

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

{

monthlySales[i].dollars = 0.0;

monthlySales[i].cents = 0.0;

}

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

{

yearlySales.dollars = yearlySales.dollars + monthlySales[i].dollars;

yearlySales.cents = yearlySales.cents +monthlySales[i].cents;

}

return 0;

}

Add a comment
Answer #3

#include
struct Money{
     int dollars;
     int cents;
   };
int main() {
   int i , sumDollar=0 , sumCent=0;
   Money monthlySales[12];
   Money yearlySales;
   cout<<"Enter the dollars of each month :";
   for(i=0;i<12;++i){
        cin>>monthlySales[i].dollars;
        sumDollar += monthlySales[i].dollars;
    }
   cout<<"Enter the cents of each month :";
   for(i=0;i<12;++i) {
       cin>>monthlySales[i].cents;
        sumCent += monthlySales[i].cents ;
     }
   cout<<"\nMONTHLY SALES\n";

    yearlySales.dollars=sumDollar + sumCent/100;

     yearlySales.cents = sunCent%100;
cout<<"\nyearly sales \n" ;

cout<< dollars :"<< yearlySales.dollars<<" cents : << yearlySales.cents ;

return 0 ;
}

Add a comment
Know the answer?
Add Answer to:
Given a type Money that is a structured type with two int fields, dollars and cents. Assume that an array named monthlyS...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Arrays of Structure in C++ (Help for codelab assignment in C++)

    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 Moneyhas 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...

  • using c++ Assume that BlogComment is a structured type with these fields, comment (a string, the...

    using c++ 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 arraynamed 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 a string variable mostControversial...

  • 1. Define a structure named StockItem with two string fields, supplier and productName and one int field, catalogNumber...

    1. Define a structure named StockItem with two string fields, supplier and productName and one int field, catalogNumber. Then define a structure named Customer with string fields name, streetAddress, city, postalCode, phone. Assume that structures named Date and Money have already been defined (representing a date and a monetary amount respectively. Finally, define a structure named Purchase that has these fields: buyer of type Customer, itemSold of type StockItem, dateOfSale of type Date, paid of type Money, returnable of type...

  • a) Declare and instantiate an array named scores of twenty-five elements of type int.   (b)Write a...

    a) Declare and instantiate an array named scores of twenty-five elements of type int.   (b)Write a statement that declares an array namedstreetAddress that contains exactly eighty elements of typechar. 2. In a single statement: declare, create and initialize an arraynamed a of ten elements of type int with the values of the elements (starting with the first) set to 10, 20,..., 100 respectively. 3. Declare an array reference variable, week, and initialize it to an array containing the strings "mon",...

  • Given the prototype: int countPassing(double arr[], int num); Assume that array arr contains num elements with...

    Given the prototype: int countPassing(double arr[], int num); Assume that array arr contains num elements with a value. You may assume that the array has been declared with at least num elements. Write the the function definition including the function header for countPassing() so that the number of values greater than or equal to 69.5 in arr[] is returned.

  •     (10 pts) Define a two-dimensional array named temp with three rows and four columns of type int such that the first...

        (10 pts) Define a two-dimensional array named temp with three rows and four columns of type int such that the first row is initialized to 6, 8, 12, 9; the second row is initialized to 10, 13, 6, 16; and the third row is initialized to 27, 5, 10, 20.     (10 pts) Consider the following declarations, and see p.566: enum brands = { GM, FORD, TOYOTA, BMW, KIA }; const int N_BRANDS = 5; const int COLOR_TYPES = 6; double...

  • Structures as Function of C++ (myprogramminglab.com assignment)

    1. Define a structure named StockItem with two string fields, supplier and productName and one int field, catalogNumber. Then define a structure named Customerwith string fields name, streetAddress, city, postalCode, phone. Assume that structures named Date and Money have already been defined (representing a date and amonetary amount respectively.Finally, define a structure named Purchase that has these fields: buyer of type Customer, itemSold of type StockItem, dateOfSale of type Date, paid of type Money,returnable of type bool.2. In mathematics, the...

  • Assume the existence of a class Arr with two (public) data members: a pointer to integer...

    Assume the existence of a class Arr with two (public) data members: a pointer to integer named arr_ptr, and an integer variable namedlength that will contain the number of elements in the array. Assume the variable a has been declared to be of type Arr, an array has been allocated and assigned to arr_ptr, and length has been assigned the proper value (i.e., the number of elements in the array). Write the code to add 1 to each element of...

  • Define a two-dimensional int array which has 5 rows and 3 columns. The elements in array...

    Define a two-dimensional int array which has 5 rows and 3 columns. The elements in array is randomly initialized (using Math.random()). Write a method to find the maximum value in this two dimensional array; Write a method to find the average value in the array; Write a method to count how many elements are smaller than average; Write a method to copy contents in a two-dimensional array to a one-dimensional array. The method will return this one-dimensional array. Method is...

  • write in java 1. Assume the availability of a method  named  makeLine that can be passed a non-negative...

    write in java 1. Assume the availability of a method  named  makeLine that can be passed a non-negative integer  n and a character  c and return a String consisting of n identical characters that are all equal to c. Write a method  named  printTriangle that receives two integer  parameters  n and k. If n is negative the method does nothing. If n happens to be an even number, itsvalue is raised to the next odd number (e.g. 4-->5). Then, when k has the value zero, the method prints...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT