CIS 33A Programming in PERL
Assignment G

Please staple the assignment together. At the top of the first page print, in this order: your first name, your last name, CIS33A, and the assignment letter. Print the problem number at the beginning of each problem. Assignments are due at the beginning of class, and will be marked down if turned in later.

Authorship note: These assignments have been adapted from assignments given by Clare Nguyen, who adapted them from the work of Behrouz Forouzan.

Programming Problems are to be done on the computer. Hand in your your source code and program output.

Programming problems

Problem G1

Write a program with subs that will manipulate test scores in a hash in various ways. The following lists the steps that your program should do:

1.   In your program, create a hash as follows:

    %hash = ( "testA"  => [77,88,65,89,90],
       	  "testB"  => [64,55],
       	  "testC"  => [70,85,99,76,89],
      	  "testD"  => [88,100,87,65,93],
       	  "testE"  => [60],
       	  "testF"  => [70,70,90,80,76,98,99,79],
       	  "testG"  => [55,32,44],
       	  "testH"  => [65,69,70,80,77,76,59] );

The keys of %hash are the test names. Each %hash value is a reference to a list of scores for a particular test. Call a sub to print the hash to the screen.

2.   Prompt the user for a test name. Call a sub to calculate statistics on that particular test. Pass to the sub the hash reference and the test name. The sub will calculate the highest, lowest, and average scores for the test and return these 3 values. Call a sub from the main code to print the result to the screen.

3.   Prompt the user for a test name to be deleted. Call a sub to delete the test from the hash. Pass to the sub the hash reference and the test name. The sub will delete the test name and associated score reference. From the main code, call the sub to print the resulting hash.

4.   Prompt the user for a test name to be added. Call a sub to add a score for a test to the hash. Pass to the sub the hash reference, the test name and the score. If the test name exists in the hash, add the score to the end of the list of scores. If the test name doesn't exist in the hash, add the test name and corresponding score to the hash. From the main code, call the sub to print the resulting hash. Repeat step 4 twice, once for a test name that already exists and once for a new test name.

You are not required to build a menu to allow the user to select the steps that modify the data, and provide the new data. You may build such a menu, if you wish.

Use test data to produce the following results, with similar format.

testA: 77 88 65 89 90
testB: 64 55
testC: 70 85 99 76 89
testD: 88 100 87 65 93
testE: 60
testF: 70 70 90 80 76 98 99 79
testG: 55 32 44
testH: 65 69 70 80 77 76 59

The stats for testF
Lowest: 70
Highest: 99
Average: 82.75

Removing testC
testA: 77 88 65 89 90
testB: 64 55
testD: 88 100 87 65 93
testE: 60
testF: 70 70 90 80 76 98 99 79
testG: 55 32 44
testH: 65 69 70 80 77 76 59

Adding testA with score 90
testA: 77 88 65 89 90 90
testB: 64 55
testD: 88 100 87 65 93
testE: 60
testF: 70 70 90 80 76 98 99 79
testG: 55 32 44
testH: 65 69 70 80 77 76 59

Adding testK with score 90
testA: 77 88 65 89 90 90
testB: 64 55
testD: 88 100 87 65 93
testE: 60
testF: 70 70 90 80 76 98 99 79
testG: 55 32 44
testH: 65 69 70 80 77 76 59
testK: 90