Computer Sciences Department logo

CS 368-1 (2010 Summer) — Day 3 Homework

Due Friday, July 16th, at the start of class.

Description

Write a Perl script that maintains a simple movie review aggragator like Metacritic.

Details

The user will run the script and be presented with a list of movie critics and their associated scores for a films. The order that the critics are listed in is not important. An average score for all of the reviews is also shown. The user can add and remove reviews. After each operation, the process repeats, with the list of reviews being shown, the average, and user input. The script will only allow a given reviewer to have a single score. If the user adds a score for an existing reviewer, the new score replaces the old score, and the user is warned that the program has done so. You may include a way to quit the program, but it is acceptable to require the user to use Ctrl-C or similar to terminate it.

When started, the program should know about the following three critics and associated scores. That is, they should be “hard coded” in. Despite being hard coded in, the user can delete or replace them.

Movie CriticRating
Manohla Dargis90
Roger Ebert 88
Keith Phipps 58

(Source: Reviews for Public Enemies from Metacritic)

The program should not attempt to save its state. When the program is re-run later, it will again have the hard coded reviews and nothing else.

A typical interaction might look like the following. The exact formatting is not required. In this sample interaction, the yellow highlighting shows what the user typed.

% ./homework-03-script
Current reviews
  Keith Phipps: 58
  Roger Ebert: 88
  Manohla Dargis: 90
  AVERAGE: 78.6666666666667

(a)dd review, (d)elete review: a

ADDING:
  Reviewer name: Test
  Review score: 100

Current reviews
  Keith Phipps: 58
  Test: 100
  Roger Ebert: 88
  Manohla Dargis: 90
  AVERAGE: 84

(a)dd review, (d)elete review: d

DELETING:
  Reviewer name: Keith Phipps
Deleted Keith Phipps

Current reviews
  Test: 100
  Roger Ebert: 88
  Manohla Dargis: 90
  AVERAGE: 92.6666666666667

(a)dd review, (d)elete review: a

ADDING:
  Reviewer name: Roger Ebert
  Review score: 50
Replacing old review score of 88

Current reviews
  Test: 100
  Roger Ebert: 50
  Manohla Dargis: 90
  AVERAGE: 80

(a)dd review, (d)elete review: 

Tip: Like most programming languages Perl will preserve whitespace like tabs and spaces in strings. So “Roger Ebert” and “Roger Ebert ” (note the trailing space) are different. An errant space or tab in your input could cause two critics that look identical to appear in your list. This is okay.

Reminders

Do the work yourself, consulting reasonable reference materials as needed; any reference material that gives you a complete or nearly complete solution to this problem or a similar one is not OK to use. Asking the instructors for help is OK, asking other students for help is not.

Hand In

A printout of your output on a single sheet of paper. Be sure to put your own name in the initial comment block of the code. Identifying your work is important, or you may not receive appropriate credit.