Question

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 it all up and stores theresulting 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 oftype 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 mostcontroversial and assign its comment field to mostControversial. Measure the degree of controversy by multiplying likes and dislikes. (See how it works? Imagine 10comments. 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 5is 25... a lot more than 0.)
0 0
Add a comment Improve this question Transcribed image text
✔ Recommended Answer
Answer #1

For number 3:

 

int max=0;
int i;
int maxID;

for(i=0; i<nComments; i++)
{
if((blogComments[i].like*blogComments[i].dislike)>=max)
{
max=blogComments[i].like*blogComments[i].dislike;
maxID=i;
}
}
mostControversial=blogComments[maxID].comment;

Add a comment
Know the answer?
Add Answer to:
Arrays of Structure in C++ (Help for codelab assignment in C++)
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • 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...

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

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

  • 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",...

  • C++ problem with dynamic arrays is that once the array is created using the new operator...

    C++ problem with dynamic arrays is that once the array is created using the new operator the size cannot be changed. For example, you might want to add or delete entries from the array similar to the behavior of a vector. This project asks you to create a class called DynamicStringArray that includes member functions that allow it to emulate the behavior of a vector of strings. The class should have: A private member variable called dynamicArray that references a...

  • Hi this is C++, I'm really struggle with it please help me.... ************************ Here is the...

    Hi this is C++, I'm really struggle with it please help me.... ************************ Here is the original high score program,: Write a program that records high-score data for a fictitious game. The program will ask the user to enter five names, and five scores. It will store the data in memory, and print it back out sorted by score. The output from your program should look exactly like this: Enter the name for score #1: Suzy Enter the score for...

  • Word Guessing Game Assignment Help Needed. This C++ (I'm using Visual Studio 2015) assignment is actually...

    Word Guessing Game Assignment Help Needed. This C++ (I'm using Visual Studio 2015) assignment is actually kind of confusing to me. I keep getting lost in all of the words even though these are supposed to instruct me as to how to do this. Can I please get some help as to where to start? Word guessing game: Overview: Create a game in which the user has a set number of tries to correctly guess a word. I highly recommend...

  • I am currently stuck with this portion of my assignment: Pointers review: to help determine how...

    I am currently stuck with this portion of my assignment: Pointers review: to help determine how many fields are presented from the form at run time, the program will count the '=' signs from the QUERY_STRING and dynamically create a name_value_pairs array of cnt elements to be used by parse() and param(). Here is what to do, in order: As directed above, make a back up of the work so far and work with the new version named retrieve_form_OOP_2.cpp. These...

  • Using C programming

    Using C, create a data file with the first number being an integer. The value of that integer will be the number of further integers which follow it in the file. Write the code to read the first number into the integer variable how_many.Please help me with the file :((This comes from this question:Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory allocation) and have it pointed to by a pointer (of type int...

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