[50pts] Part 1: p1.cpp

ratings.tsv

Download ratings.tsv. This file contains data for real-world movie ratings. If you click on the the above link, you will see that each line of that file contains three numbers.

In total, there are 9724 movies and 610 users. Of course, not all users have watched all 9724 movies, so many user-movie parings have no rating listed.

Your task

We're going to ask some simpler questions.
  • What is the average rating for different movies?
  • What's the average rating from individual users?
Sample run is shown on the right.
$ ./p1
movie 7
4.03165
user 2
2.4359
quit

Your program should run, answering queries about movies and users, until the user of your program enters quit.

Don't forget to delete your arrays, and use Valgrind to double-check for memory errors!

Organizing a 2D matrix for ratings

Start your program by turning ratings.tsv into a 2D matrix, which has 610 rows (number of users) and 9724 columns (number of movies).

Our suggestion is:
  1. Initalize the 2D matrix such that all entries have value 0.
  2. For each rating from the file, replace the corresponding entry in the 2D matrix according with that rating.
Naturally, all this should happen in a function which returns your array.

You'll then add some more functions to be able to print out the average values of individual movies and users.

Note

Submit

~/bin/submit -c=IC210 -p=lab09 p*.cpp

[50pts] Part 2: p2.cpp

Write a program named p2.cpp that works as follows:
  1. Asks user for a "map" that shows how many accidents occurred at each intersection.
    • In the map, the first row represents 0th Street, and the second row 1st Street, etc.
    • The first column represents 0 Avenue, and the second 1 Avenue, etc.
    • For example, in the sample run, the accident status is as follows:
      • 1 Accident at 1st Street, 0 Avenue
      • 4 Accidents at 2nd Street, 4 Avenue
      • 1 Accident at 5th Street, 0 Avenue
      • 3 Accidents at 7th Street, 2 Avenue
  2. Each time, the program gets a crash report and shows the updated map.

Submit

~/bin/submit -c=IC210 -p=lab09 p*.cpp
Sample run (user input in red):
~/$ ./p2
8 Streets, 5 Avenues
0 0 0 0 0
1 0 0 0 0
0 0 0 0 4
0 0 0 0 0
0 0 0 0 0
1 0 0 0 0
0 0 0 0 0
0 0 3 0 0
> crash 2nd Street, 1 Avenue
0 0 0 0 0
1 0 0 0 0
0 1 0 0 4
0 0 0 0 0
0 0 0 0 0
1 0 0 0 0
0 0 0 0 0
0 0 3 0 0
> crash 7th Street, 4 Avenue
0 0 0 0 0
1 0 0 0 0
0 1 0 0 4
0 0 0 0 0
0 0 0 0 0
1 0 0 0 0
0 0 0 0 0
0 0 3 0 1
> crash 2nd Street, 4 Avenue
0 0 0 0 0
1 0 0 0 0
0 1 0 0 5
0 0 0 0 0
0 0 0 0 0
1 0 0 0 0
0 0 0 0 0
0 0 3 0 1
> quit