=========================preview======================
(COMP111)comp111_01s_final_sol.pdf
Back to COMP111 Login to download
======================================================
COMP111: Software Tools
Final Exam C Dickson Chiu
Spring 2001 (May 31, 2001 Thursday 13:30-15:30)
Student Name: _______________________________________________

Student Number: _____________________________________________

Email: ______________________________________________________

Lab Section: ________________________________________________

Instructions:
1.
There are 8 problems worth 100 points total.

2.
Check that you have all 10 pages.

3.
Close book, close notes, work on your own, and you cannot use any computer.

4.
Answer all questions in the space provided. Rough work can be done only on the back pages.

5.
Leave all pages stapled together.

6.
The examination period will last for 120 minutes.

7.
Stop writing immediately when the time is up.



For Grading Purposes Only:
Page 2: Problems 1 ______________ / 19
Page 3: Problems 2-4 ______________ / 20
Page 4: Problems 5-6 ______________ / 11
Page 5: Problems 7 ______________ / 9
Page 6: Problem 8a ______________ / 6
Page 7: Problem 8b ______________ / 4
Page 8: Problem 8c ______________ / 6
Page 9: Problem 8d ______________ / 14
Page 10:Problem 8e,f ______________ / 11

Total: ______________ /100

1) (19 points) Output Identification. What are the output of the following Perl code fragments?
Perl Code Fragments Output Marks
$a=b; $b=a; $aa=ab; $ab=ba; print $$a, 1, $$$a, 2, ${a.$a}; a1b2ba 3
@a = (3,5,7,9); $tmp = $a[0]; $a[0] = $a[-2]; $a[$#a] += $tmp; $a[@a-3] = 6; $a[-1] = 1; print @a; 7671 2
$n=2; @a=1; @b = ($n, @a, 4); unshift(@a, 3); push(@a, 3); $n = pop(@a); unshift(@a, @b); @a = reverse(@a); push(@a, @b); @a = sort(@a); pop(@a); print @a; 1112234 3
$bill{"Gates"} = "rich"; @bill{"Chan ","Mr."} = qw(very big); @bill{4..7} = qw(very famous + nervous); delete($bill{5}); delete($bill{6}); @a = sort values %bill; %bill = reverse %bill; print @a; bignervousrichveryvery 2.5
$n1=9;$n2=2;$n3=6; $n1 = test($n2,$n3); print "$n1 $n2 $n3"; sub test{ my($n1,$n2) = @_; print "$n1 $n2 "; return $n2 -= $n1; } 26426 2.5
$n=2; while($n--){ if($n > 10){ last; } $n += 2; if($n <= 3){ next;} $n += 3; if($n <= 7){ redo;} $n += 1; } print $n; 12 2
$_ = "03-5-2000"; s/(\d+)/($1)/g; print; (03)-(5)-(2000) 2
$_ = "the quick brown fox"; print /^(\w+)[\w\s]+\s+(\w+)$/; thefox 2

2) (10 marks) Regular Expression matching Below is a list of regular expressions and a list of strings. Each of the strings has a letter. Fill in the blank by each regular expression listing the letters for all of the strings for which that regular expression is true. Scoring: 2 points if answer is correct and complete; 1 point if answer contains some but not all of the correct letters; 0 points if any incorrect letters or if left blank. The first entry is an example: the expression /o/ matches all of the strings except "The answer is 42",soput "A,B,C" in the blank after /o/:
Regular Expressions