HW5: Cheat Check Program
Due
3/11 Fri 5 pm.
Description
You are going to write a program cheat.pl to find out which students copies other student's homework.
I will use your program to find out which students cheat on their previous homework :)
Method
The method I use is very simple. I have a list of keywords. For each hw, I count the number of occurence of
each keywords. I then compare the number of keywords between 2 homewords.
For example, if the keyword list is if, elsif, print.
Suppose Andy's HW1 has 3 if, 5 elseif, 6 print. Ben's HW1 has 2 if, 6 elseif, 10 prints.
The total difference is |3-2| + |5-6| + |6-10| = 3. (here |.| is the absolute value).
If the difference is small, then the chance of cheating is high.
Files
- key.txt: a list of key words.
Example
print
if
elsif
sub
for
foreach
while
chomp
keys
values
open
index
substr
pop
push
|
filelist.txt : a list of files for comparison
Example
andyhw.pl
charleshw.pl
amyhw.pl
|
You may have more than 3 files.
Output
The file read in key.txt and filelist.txt.
Then counts the number of occurence of the keyword in each file of filelist.txt.
Then the program analysis the result by calculating the total difference.
The output is saved to a file named report.txt. Here is the sample output
****** andyhw.pl ******
chomp 1
elsif 0
for 0
foreach 2
if 1
index 0
keys 1
open 8
pop 0
print 2
push 1
sub 0
substr 0
values 0
while 2
****** charleshw.pl ******
chomp 1
elsif 0
for 0
foreach 2
if 2
index 0
keys 1
open 4
pop 0
print 3
push 0
sub 0
substr 0
values 0
while 2
****** amyhw.pl ******
chomp 1
elsif 0
for 2
foreach 2
if 2
index 0
keys 1
open 4
pop 2
print 0
push 0
sub 0
substr 0
values 0
while 2
****** Difference ******
andyhw.pl charleshw.pl 7
andyhw.pl amyhw.pl 12
charleshw.pl andyhw.pl 7
|
Sample Ouput
Suppose we have the following files:
a.pl
$num1 = <STDIN>; # input num1
chomp($num1);
$num2 = <STDIN>; #input num2
chomp($num2);
if($num1 < $num2) { # if num1 is smaller
print "num2 is bigger.\n";
} elsif ($num1 > $num2) {
print "num1 is begger.\n";
} else {
print "equal\n";
}
|
b.pl
$num1 = <STDIN>; # input num1
chomp($num1);
$num2 = <STDIN>; #input num2
chomp($num2);
if($num1 < $num2) {
print "num2 is bigger."; #print
print "\n";
}
if($num1 > $num2) {
print "num1 is begger."; #print
print "\n";
}
if($num1 == $num2) {
print "equal.";
print "\n"; # print
}
|
c.pl
$num1 = <STDIN>; # input num1
chomp($num1);
$num2 = <STDIN>; #input num2
chomp($num2);
#if($num1 <= $num2) {
# print "num2 is bigger.\n";
#}
if($num1 < $num2) { # if num1 is smaller
print "num2 is bigger.\n";
} elsif ($num1 > $num2) {
print "num1 is begger.\n";
} else {
print "equal";
print "\n";
}
|
filelist.txt
key.txt
print
if
elsif
else
chomp
|
Then after you run cheat.pl, the file report.txt becomes
****** a.pl ******
chomp 2
else 1
elsif 1
if 1
print 3
****** b.pl ******
chomp 2
else 0
elsif 0
if 3
print 6
****** c.pl ******
chomp 2
else 1
elsif 1
if 1
print 4
****** Difference ******
a.pl b.pl 7
a.pl c.pl 1
b.pl c.pl 6
|
Pay attention to:
- all the words in the comments (after
#) are ignored
- the keys words are rearrange in alphabetical order.
Submission
Name your file cheat.pl. Put the file in the submit folder!
All source code submitted must contain the following information at the beginning of each file:
* Your full name.
* Your student ID number.
* Your PIC login ID.
* Your e-mail address.
* Your discussion section number and TA's name.
* The assignment number and description.
* Honesty pledge.
Properly formatted, this information should appear as follows:
# Name: Charles Li
# Student ID: 000 000 000
# PIC ID: ccli
# E-mail: ccli@math.ucla.edu
# Assignment: hw1
#
# I, Charles Li, pledge that this is my own independent work, which
# conforms to the guidelines of academic honesty as described in the course
# syllabus.