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, 24.06.2019 07:20
3pointsyou've found an image you want to insert into your slide presentation. youwant to make the image look more gray so that it looks like an older imagewhat would you need to adjust? 0.00o a. sizeo b. hueo c. contrasto d. tones
Answers: 2
question
Computers and Technology, 24.06.2019 10:30
Which of the following types of software is most applicable to the promotion of new products through advertising? a.databases b. spreadsheets c. web design programs d. word processing tools
Answers: 2
question
Computers and Technology, 24.06.2019 11:00
In three to five sentences, describe how you can organize written information logically and sequentially
Answers: 1
question
Computers and Technology, 25.06.2019 05:00
The ratio of men to women in a certain factory is 3 to 4 .there are 210 men.how many workers are there?
Answers: 2
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
question
Biology, 06.05.2020 21:04
question
Social Studies, 06.05.2020 21:04
question
Mathematics, 06.05.2020 21:04