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, 22.06.2019 16:20
Octothorpe is another name for what common computer keyboard symbol?
Answers: 1
question
Computers and Technology, 22.06.2019 23:50
You need to design a circuit that implements the functions in the following table: s0 s1 function0 0 a + 10 1 a – b1 0 a + b1 1 a – 1s0 and s1 are 1-bit control inputs to select the function of the circuit. inputs a and b are 4-bitnumbers in 2s complement form. the output is also a 4-bit number in 2s complement form.you are allowed to use only one ttl 7483 4-bit adder to implement all the functions. but anynumber of other components (except the adder) can be used.hint: design a combinational logic circuit to modify the input b and the “carry input” of theadder depending on the control inputs s0 and s1.important: lab grade will depend on the working of the circuit & will be checked of by your labinstructor.1. is the output valid for the following input combinations: a. s0 = 0, s1 = 0, a = 7, b = 3? b. s0 = 0, s1 = 1, a = 7, b = 3? c. s0 = 1, s1 = 0, a = -4, b = -5? d. s0 = 1, s1 = 1, a = -8, b = 6? 2. what is the range of inputs (for both a and b) that will produce the valid output for all the functions?
Answers: 3
question
Computers and Technology, 23.06.2019 03:00
State 7 common key's for every keyboard
Answers: 1
question
Computers and Technology, 23.06.2019 12:00
If you're using an existing powerpoint presentation that will receive new slides based on a word outline, select the a. slide that will appear after the new slides. b. first slide in the presentation. c. slide that will appear before the new slides. d. last slide in the presentation.
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
History, 02.02.2020 18:59
question
Social Studies, 02.02.2020 18:59
Questions on the website: 13722360