Question

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

\\ The code for specified task given below

int id_of_max=0;

int max_contro=0;

for (int i=0; i<nComments; i++){

  if (blogComments[i].like * blogComments[i].dislike > max_contro ){

     max = blogComments[i].like * blogComments[i].dislike;

     maxID = i;

  }

}

mostControversial = blogComments[maxID].comment;

Add a comment
Know the answer?
Add Answer to:
using c++ Assume that BlogComment is a structured type with these fields, comment (a string, the...
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...

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

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

  • #include <iostream> #include <string> using std::string; using std::cout; using std::endl; void testAnswer(string testname, int answer, int...

    #include <iostream> #include <string> using std::string; using std::cout; using std::endl; void testAnswer(string testname, int answer, int expected) { if (answer == expected) cout << "PASSED: " << testname << " expected and returned " << answer << "\n"; else cout << "FAILED: " << testname << " returned " << answer << " but expected " << expected << "\n"; } // Implement printArray here void printArray(int array[],int b) { for(int i = 0; i<b;i++) { std::cout<< array[i] << "...

  • Answer this in c++ #include <iostream> #include <fstream> #include <string> using namespace std; class Person {...

    Answer this in c++ #include <iostream> #include <fstream> #include <string> using namespace std; class Person { public: Person() { setData("unknown-first", "unknown-last"); } Person(string first, string last) { setData(first, last); } void setData(string first, string last) { firstName = first; lastName = last; } void printData() const { cout << "\nName: " << firstName << " " << lastName << endl; } private: string firstName; string lastName; }; class Musician : public Person { public: Musician() { // TODO: set this...

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

  • the coding language is in c++ An array named testScores has already been declared. -size= 5...

    the coding language is in c++ An array named testScores has already been declared. -size= 5 -data type = float - the array has already been initialized these values: 77, 88.5, 90, 93, 71.5 -Write one statement to declare a pointer named: ptr - in the same statement, assign the address to the testScores array to the pointer -write one statement to output the memory address of the array element at testScores[0] -Write a for loop to output the values...

  • Let’s build a dynamic string tokenizer! Start with the existing template and work on the areas...

    Let’s build a dynamic string tokenizer! Start with the existing template and work on the areas marked with TODO in the comments: Homework 8 Template.c Note: If you turn the template back into me without adding any original work you will receive a 0. By itself the template does nothing. You need to fill in the code to dynamically allocate an array of strings that are returned to the user. Remember: A string is an array. A tokenizer goes through...

  • Question 1 When you declare a variable of type Single, it contains 0 by default. True...

    Question 1 When you declare a variable of type Single, it contains 0 by default. True False Question 2 The following line declares an array that can contain whole numbers, with 10 elements. Dim Variables(9) As Integer True False Question 3 Once a variable is declared we can not change the variable's data type. True False Question 4 If A is False and B is True, then A Or B is True because A is False. True False Question 5...

  • whats the answer When defining a class which has the field name of type String. How...

    whats the answer When defining a class which has the field name of type String. How is the name field declared? String nam name Opublic String name; private name; private String name; Given the following class definition, Which operation can a class user perform on an object of type Restaurant? public class Restaurant // Info about a restaurant // Internal fields public void setName(String restaurant Name) { // Sets the restaurant's name } public void setRating(int user Rating) { //...

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