Read a collection of movie ratings (each containing a title, year, and rating) and calculate an average rating for each movie.
For example, given the following input (this is the required input format, see below):
Harold & Kumar Go to White Castle
2004
9
Fahrenheit 9/11
2004
8
There's Something About Mary
1998
9
Star Wars
1977
7
Harold & Kumar Go to White Castle
2004
4
Star Wars
1977
6
The average ratings would be (this is the required output format, see below);
2004: Harold & Kumar Go to White Castle, rating = 6.5
2004: Fahrenheit 9/11, rating = 8
1998: There's Something About Mary, rating = 9
1977: Star Wars, rating = 6.5
Notice that if a movie appears only once in the input (such as "Fahrenheight 9/11" above), its printed rating is that given in the single rating. If a movie appears multiple times, its printed rating is the average of all the input ratings.
Read movie ratings from standard input. The input will be in this exact form:
movie title
year
rating
movie title
year
rating
...
There may be 0 or more ratings. The movie title, year, and rating will always be on their own line. The movie title will be an arbitrary string and may contain any printable characters (including spaces). The year and the rating will be integers. We will only test your program with input that meets these requirements, and thus your program does not have to handle bad input.
A movie may appear one or more times in the input.
After all the input has been read, write all ratings to standard output using the following form. Make sure you write them in the same order as in the input:
year: movie title, rating = n
Note: n is a double. Notice that there is exactly one space after the :, no spaces after the title, one space after the "," and one space before and after the "=". There are no spaces after the n.
If there are no ratings in the input (i.e. the input is empty), write nothing to standard output.
Your system should be able to handle up to 100 different movies and any number of ratings. If more than 100 movies are given, your program should print the following to standard error (cerr << "Too many ...") and print nothing to standard output.
Too many movies specified.
The system can only handle 100 movies.
Giving up...
Required classes:
Use two classes to implement your rating system:
class Movie // store each movie in a separate Movie object
class Movie_db // store all the Movie objects in one Movie_db
Each should be in its own files:
movie.h
movie.cpp
movie_db.h
movie_db.cpp
In addition to these files, you will need to turn in a file containing your main() function:
main.cpp
% movies < t01 > t01.myout 2> t01.myerr
% diff t01.myout t01.out
% diff t01.myerr t01.err
%
while (getline(cin, title) != 0) // while the getline did not return end of fileSince the year and rating are integers, it is easiest to read them using the standard cin operator:
{
// now read the year and the rating
...
}
cin >> year;
cin >> rating;
cin >> year;Windows warning: If you are programming in the microsoft windows world, this won't work. Windows has two characters at the end of each line. You can fix the problem by using the command dos2unix to turn your input files into UNIX like files (that is, with only a '\n' at the end of each line). It would not be a good idea to write your code so that it only works in the windows world because we will grade it in the UNIX world.
cin >> rating;
cin.ignore();
I will deduct 10 percent if your program does not compile on the lab machines using my Makefile. Thus you must make sure to use the filenames listed below (do not capitalize your filenames), and if you are working on windows, you should compile and test your program on one of the department's Sun workstations (the machines in OCNL 244) before turning it in (you can log on to these machines from home using the putty program).
We will grade your program using another program, so if your program does not work exactly as specified above you will lose points. For example, if you put an extra space at the end of the line, or a blank line at the end of the output, you will lose points. Test your program using the sample tests in the test directory (see above).
The first lines of all your files (.h and .cpp) must contain:
/****
last name, first name
ecst_username@ecst.csuchico.edu
112 Program p2: Movie Database
****/
You must turn in the following files:See lab2 for instructions on how to turn in the assignment if you did it on your home machine.
copy the above files into the directory:movie.h
movie.cpp
movie_db.h
movie_db.cpp
main.cpp
where USERNAME is your ecst username./user/projects/csci112/p2/USERNAME
If you do not finish by the deadline (see top for the deadline), you may turn your assignment in up to 24 hours late. You will lose 15% for turning your assignment in 1-24 hours late.
If you turn your assignment in late, copy your assignment into the following directory:
Assignments will not be accepted if more than 24 hours late./user/projects/csci112/p2_late/USERNAME