#!/usr/bin/perl #****************************************************************** #******************** Tables ************************************* #****************************************************************** @grade_table = ('Congrat! You Pass with a Perfect Score!', 'You Pass!', 'You are on the border!', 'You barely Pass!', 'You need at least 2 more points to pass!', 'Sorry! You Fail!'); #****************************************************************** #******************** Subroutines ******************************** #****************************************************************** #******************************************************* #****** Get "state" info passed up from Browser ******** #******************************************************* sub GET_FORM_DATA { #** When the user clicks on the Submit button labled #** "submit" this CGI program is called, and the form #** data is passed in STDIN. read(STDIN, $save_string, $ENV{CONTENT_LENGTH}); @prompts = split(/&/,$save_string); foreach (@prompts) { ($tmp1, $tmp2) = split(/=/,$_); $tmp2 =~ s/\x2b/\x20/g; $tmp2 =~ s/%2C/\x2c/g; $tmp2 =~ s/%28/\x28/g; $tmp2 =~ s/%29/\x29/g; $fields{$tmp1}=$tmp2; } #Input Questions $q1 = $fields{'q1'}; $q2 = $fields{'q2'}; $q3 = $fields{'q3'}; $q4 = $fields{'q4'}; $q5 = $fields{'q5'}; $q6 = $fields{'q6'}; #Input Gender $gender = $fields{'Gender'}; #Input Nationality $nationality = $fields{'Nationality_is'}; #Input Name $yourname = $fields{name}; #Input Email $email = $fields{email}; } #******************************************************* #************ Send back Report Page **************** #******************************************************* sub SHOW_SCORE { print("Content-Type: text/html\n\n"); print("Here's Your Score\n"); print("\n"); print "

Post Submission!

"; print "

Your Name: ", $yourname; print"
"; print "Your Email: ", $email; print "
"; if ($gender == 1) { print "Your Gender: Male"; print "
"; } if ($gender == 2) { print "Your Gender: Female"; print "
"; } if ($nationality == 1) { print "Nationality: Vietnamese"; print "
"; } if ($nationality == 2) { print "Nationality: Spanish"; print "
"; } if ($nationality == 3) { print "Nationality: India"; print "
"; } if ($nationality == 4) { print "Nationality: Chinese"; print "
"; } if ($nationality ==5) { print "Nationality: Others"; print "
"; } if ($q1 == 1) { print "

Your answer for No. 1 is correct!"; print "
"; }elsif ($q1 ==0){ print "

Your answer for No. 1 is incorrect. The correct answer is England."; print "
"; }else{ print "

You forgot to answer No. 1 ??"; print "
"; } if ($q2 == 1) { print "Your answer for No. 2 is correct!"; print "
"; }elsif ($q2 ==0){ print "Your answer for No. 2 is incorrect. The correct answer is Patrick Henry."; print "
"; }else{ print "You forgot to answer No. 2 ??"; print "
"; } if ($q3 == 1) { print "Your answer for No. 3 is correct!"; print "
"; }elsif ($q3 ==0){ print "Your answer for No. 3 is incorrect. The correct answer is N_400."; print "
"; }else{ print "You forgot to answer No. 3 ??"; print "
"; } if ($q4 == 1) { print "Your answer for No. 4 is correct!"; print "
"; }elsif ($q4 ==0){ print "Your answer for No. 4 is incorrect. The correct answer is Congress."; print "
"; }else{ print "You forgot to answer No. 4 ??"; print "
"; } if ($q5 == 1) { print "Your answer for No. 5 is correct!"; print "
"; }elsif ($q3 ==0){ print "Your answer for No. 5 is incorrect. The correct answer is Democratic and Republican."; print "
"; }else{ print "You forgot to answer No. 5 ??"; print "
"; } if ($q6 == 1) { print "Your answer for No. 6 is correct!"; print "
"; }elsif ($q6 ==0){ print "Your answer for No. 6 is incorrect. The correct answer is The Electoral College."; print "
"; }else{ print "You forgot to answer No. 6 ??"; print "
"; } $score = $q1 + $q2 + $q3 + $q4 + $q5 + $q6; print "

Number of Correct: ", $score; print "
"; print "Number of Missed: ", 6-$score; print "
"; print "Your total point out of 24 point is: ", $score*4; print "
"; print "Your Grade Percentage is: ", int($score*4/24*100); print "

Your Status is: "; print $grade_table[6-$score], ""; print "


"; print "

See the Perl for this page"; print "
"; print "Back to Review Questionares"; print "


"; print"\n"; print(""); print(""); } #******************************************************* #******************** Main Rtn ************************ #******************************************************* &GET_FORM_DATA; &SHOW_SCORE;