Spring Semester 2002


Please write your name or username here: __________________________________


This exam has two parts:

  1. Solve the problem below, turn your solution at the end of time.
  2. Take your solution with you, implement it, post it on-line within four days.

The second part is optional. Your grade for the exam will be the average of the grade for part [1] and part [2]. The due date for part [2] is Monday March 4, 2002, at the end of the day (11:59pm).

The exam is open-book, open-notes. Here's the problem; consider the following Perl program:

#!/usr/bin/perl

$count = 1; 
$correct = 0; 

print "Welcome to the Addition Quiz. \n"; 

while ($count <= 10) {
  $one = int(rand(100) - 50); 
  $two = int(rand(100) - 50); 
  print "Question $count: What is $one + $two?\n"; 
  print "    Answer: "; 
  $answer = <STDIN>; 
  if ($answer == $one + $two) {
    $correct += 1; 
    print "Very good, that was the answer.\n"; 
  } else {
    print "Sorry. The right answer was: ", 
          ($one + $two) , "\n"; 
  }
  $count += 1; 
}

print "End of quiz. Thanks for your interest.\n"; 

print "Your score is: $correct out of ", 
      ($count - 1), "\n"; 
Here's how it works:
frilled.cs.indiana.edu%./quiz
Welcome to the Addition Quiz. 
Question 1: What is -26 + -25?
    Answer: -51
Very good, that was the answer.
Question 2: What is -41 + 20?
    Answer: -21
Very good, that was the answer.
Question 3: What is 38 + 26?
    Answer: 64
Very good, that was the answer.
Question 4: What is 22 + 15?
    Answer: 37
Very good, that was the answer.
Question 5: What is -27 + 29?
    Answer: -2
Sorry. The right answer was: 2
Question 6: What is 0 + -11?
    Answer: -11
Very good, that was the answer.
Question 7: What is -4 + -20?
    Answer: -24
Very good, that was the answer.
Question 8: What is 11 + 33?
    Answer: 44
Very good, that was the answer.
Question 9: What is 30 + 25?
    Answer: 65
Sorry. The right answer was: 55
Question 10: What is -27 + 46?
    Answer: 19
Very good, that was the answer.
End of quiz. Thanks for your interest.
Your score is: 8 out of 10
frilled.cs.indiana.edu%
Implement a functionally equivalent version of this program using PHP or CGI with Perl.

Things to keep in mind:

Graduate Standing:

Notes for graduate standing: choose ONE or the OTHER, but not both.

General notes:

  1. The exam is open-book, open-notes, but individual work.
  2. Good luck and do well!


LH102 5:45pm-7:00pm Feb 28, 2002