subject

You have collected a file of movie ratings where each movie is rated from 1 (bad) to 5 (excellent). the first line of the file is a number that identifies how many ratings are in the file. each rating then consists of two lines: the name of the movie followed by the numeric rating from 1 to 5. here is a sample rating file with four unique movies and seven ratings:

7

happy feet

4

happy feet

5

pirates of the caribbean

3

happy feet

4

pirates of the caribbean

4

flags of our fathers

5

gigli

1

write a program that reads in a file in this format, calculates the average rating for each movie, and outputs the average along with the number of reviews. here is the desired output for the sample data:

happy feet: 3 reviews, average of 4.3 / 5

pirates of the caribbean: 2 reviews, average of 3.5 / 5

flags of our father: 1 review, average of 5 / 5

gigli: 1 review, average of 1 / 5

use a map or multiple maps to generate the output. your map should index from a string representing each movie’s name to integers that store the number of reviews for the movie and the sum of the ratings for the movie. you will need to use the fstream library to read in file data. it may be to discard the newline character as you read the file data. you can do this using the following line: fin. ignore(2,'\n'); . use it after reading any movie ratings. you will also need to clean up the title as it will contain a linefeed character at the end of it, just remove it after reading the movie name. assume a file named "movies. txt" is used as the input file and it contains the list of movies above. this will be the test file for your program, make sure the output matches the output above.

this is in the programming language c++. i have already started with the code below. me finish this problem with the code i already started instead of starting from scratch. explain each added line of code well:

#include
#include
#include
#include
using namespace std;

int main()
{
int numberratings, rating;
string moviename;
map mapratings; //maps movie rating to total amount of specific movie ratings
map> mapreviews; //maps above map to movie name

ifstream input; //reads header file
input. open("movies. txt"); //opens movies. txt
input > > numberratings; //inputs the number of ratings
input. ignore(); //ignores next line

for (int i = 0; i < numberratings; ++i) {
getline(input, moviename); //inputs the movie name
input > > rating; //inputs that movie's rating
input. ignore(); //ignores next line
++mapreviews[moviename][rating]; //increments map which will store the movie name and rating
}

map: : iterator mapiter1;
map> : : iterator mapiter2;

for (mapiter2 = mapreviews. begin(); mapiter2 ! = mapreviews. end(); ++mapiter2) {
cout < < endl < < mapiter2-> first < < ": ";
for (mapiter1 = mapiter2-> second. begin(); mapiter1 ! = mapiter2-> second. end(); ++mapiter1) {
cout < < mapiter1-> first < < " reviews, average of " < < / mapiter-> first < < " / 5" < < endl;
}
}

return 0;
}

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 18:00
Budgets you to do all of the following expect a) send frivolously b) avoid over spending c) gain financial independence d) examine your priorities and goals
Answers: 2
question
Computers and Technology, 23.06.2019 06:30
You are consulting for a beverage distributor who is interested in determining the benefits it could achieve from implementing new information systems. what will you advise as the first step?
Answers: 1
question
Computers and Technology, 24.06.2019 11:20
Print "censored" if userinput contains the word "darn", else print userinput. end with newline. ex: if userinput is "that darn cat.", then output is: censoredex: if userinput is "dang, that was scary! ", then output is: dang, that was scary! note: if the submitted code has an out-of-range access, the system will stop running the code after a few seconds, and report "program end never reached." the system doesn't print the test case that caused the reported message.#include #include using namespace std; int main() {string userinput; getline(cin, userinput); int ispresent = userinput.find("darn"); if (ispresent > 0){cout < < "censored" < < endl; /* your solution goes here */return 0; }
Answers: 3
question
Computers and Technology, 24.06.2019 14:30
Alison is having a hard time at work because hee inbox is flooded with emails every day. some of these emails are unsolicited. some of other she don’t need. which action should she take to better manager her emails?
Answers: 1
You know the right answer?
You have collected a file of movie ratings where each movie is rated from 1 (bad) to 5 (excellent)....
Questions
Questions on the website: 13722367