SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,julia Lobur
Chapter:
Standard Template Library
Exercise:
Programming Projects
Question:9 | ISBN:9780321531346 | Edition: 7

Question

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

Harry Potter and the Order of the Phoenix

4

Harry Potter and the Order of the Phoenix

5

The Bourne Ultimatum

3

Harry Potter and the Order of the Phoenix

4

The Bourne Ultimatum

4

Wall-E

4

Glitter

1

Write a program that reads 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:

Glitter: 1 review, average of 1 / 5

Harry Potter and the Order of the Phoenix: 3 reviews, average

of 4.3 / 5

The Bourne Ultimatum: 2 reviews, average of 3.5 / 5

Wall-E: 1 review, average of 4 / 5

Use a map or multiple maps to calculate the output. Your map(s) 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.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Sorry the answer is not available at the moment…

If you are able to find the answer, please make sure to post it here. So that your Juniors have smile on their lips and feel happy.

Spread the 'tradition of sharing'.