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: 1

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 19:30
Write a function processpeople() that takes the name of a file as a parameter. each line of the file corresponds to information about a person. in particular a line contains either a name (in the form lastname,firstname with no spaces in it) or a name (lastname,firstname) and a year. the function will process the file, creating a person object for each line in the file. the function will print information about each line as it processes it, as well as appending the new person object into a list. make sure to use person methods to display information rather than recreating the work you did for the first problem. once the entire file has been processed, the function returns the list of person objects created from the file. if the file is empty, the function should return an empty list. if the input file cannot be opened, the function should print a message to that effect and then return an empty list. the following shows what would be displayed for two example files which have been provided in the link. the file none.txt does not exist. note that your function must work on an arbitrary file that consists of valid lines. you cannot assume anything about the file except that it contains lines that have the format described above.
Answers: 2
question
Computers and Technology, 21.06.2019 22:40
State the parts of a variable declaration?
Answers: 2
question
Computers and Technology, 23.06.2019 13:30
Drag the tiles to the correct boxes to complete the pairs. match the errors with their definitions. #name #value #ref when a formula produces output that is too lengthy to fit in the spreadsheet cell arrowright when you enter an invalid cell reference in a formula arrowright when you type text in cells that accept numeric data arrowright when you type in a cell reference that doesnā€™t exist arrowright reset next
Answers: 1
question
Computers and Technology, 24.06.2019 00:00
Visualizing a game of ā€œtagā€ to remember the meaning of contagious
Answers: 3
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, 29.09.2020 02:01
question
Social Studies, 29.09.2020 02:01
question
Mathematics, 29.09.2020 02:01
Questions on the website: 13722360