|
Second Summer 2002 |
Please write your name or username here: __________________________________
This exam has two parts:
Mon Jul 15 17:00:00 EST 2002.
protected) do it as
for a homework assignment, clearly indexed, and with as many comments
or explanations as you consider necessary. The exam is open-book, open-notes. Here's the problem; consider the following Perl program:
#!/usr/bin/perl
print "Welcome to the machine. We sell stamps. \n";
print "10-stamps books are now \$3.70 each and we accept coins.\n";
print "Please start entering coins: ";
$credit = 0;
while ($line = <STDIN>) {
chop($line);
if ($line =~ /^dollar$/ ) { $credit += 100; }
elsif ($line =~ /^quarter$/) { $credit += 25; }
elsif ($line =~ /^dime$/ ) { $credit += 10; }
elsif ($line =~ /^nickel$/ ) { $credit += 5; }
elsif ($line =~ /^cent$/ ) { $credit += 1; }
else { print " We don't accept/understand ***(", $line, ")***\n"; }
print "Your credit now is: ", $credit, " cents.\n";
if ($credit >= 370) {
print "Great, the stamps are yours.\n";
if ($credit > 370) {
print "Your change is: ", ($credit - 370), " cents.\n";
}
last;
} else {
print "You still need to provide ",
(370 - $credit), " cents to get the stamps.\n";
print "Please enter coin: ";
}
}
Here's how it works:
frilled.cs.indiana.edu%vending Welcome to the machine. We sell stamps. 10-stamps books are now $3.70 each and we accept coins. Please start entering coins: dime Your credit now is: 10 cents. You still need to provide 360 cents to get the stamps. Please enter coin: dollar Your credit now is: 110 cents. You still need to provide 260 cents to get the stamps. Please enter coin: dollar Your credit now is: 210 cents. You still need to provide 160 cents to get the stamps. Please enter coin: quarter Your credit now is: 235 cents. You still need to provide 135 cents to get the stamps. Please enter coin: dollar Your credit now is: 335 cents. You still need to provide 35 cents to get the stamps. Please enter coin: nickel Your credit now is: 340 cents. You still need to provide 30 cents to get the stamps. Please enter coin: cent Your credit now is: 341 cents. You still need to provide 29 cents to get the stamps. Please enter coin: cent Your credit now is: 342 cents. You still need to provide 28 cents to get the stamps. Please enter coin: quarter Your credit now is: 367 cents. You still need to provide 3 cents to get the stamps. Please enter coin: dime Your credit now is: 377 cents. Great, the stamps are yours. Your change is: 7 cents. frilled.cs.indiana.edu%
Implement a web equivalent of this program and post it at:
http://burrowww.cs.indiana.edu:102xx/cgi-bin/exams/midterm
where 102xx is your web server port number.
Graduate Standing:
LH102 9:30pm-10:45pm Thu Jul 11, 2002