7 Pages
Unlock Document

Computer Science
Diane Horton

CSC207H1S March Midterm 2005 Duration — 50 minutes Student Number: Aids allowed: none Last Name: First Name: CDF login: Do not turn this page until you have received the signal to start. (Please fill out the identification section above, and read the instructions below.) Good Luck! # 1: /10 This midterm consists of 4 questions on 7 pages (including this one). When you receive the signal to start, please make sure that your copy is complete.# 2: /15 Comments are not required except where indicated, although they may help # 3: /15 us mark your answers. They may also get you part marks if you can’t figure out how to write the code. # 4: /10 If you use any space for rough work, indicate clearly what you want marked. TOTAL: /50 Total Pages = 7 Page 1 cont’d... Question 1. [10 marks] Consider these files: e1.txt, e2.txt, and e3.txt – lists of e1, e2, and e3 marks. marks.txt – A summary file containing all marks. gather.py – Produces the file marks.txt, a summary of the marks in e1.txt, e2.txt, and e3.txt. Part (a) [5 marks] Write a makefile that has two targets: clean – Removes marks.txt. marks.txt – Runs gather.py if marks.txt is older than any of e1.txt, e2.txt, or e3.txt. Part (b) [5 marks] Assume that you have been asked to generalize gather.py so that it works with any number of individual marks files rather than working explicitly with e1.marks, e2.marks, and e3.marks. It should do this by reading the names of those files as command line arguments using getopt. It also should read the name of the file summarizing all the marks that way as well, rather than assuming the name will be marks.txt. 1. Assume that the individual marks files are called m1, m2, m3, and m4, and the summary file is called total.txt. Circle the true statement below: Only total.txt can be specified using an option parameter. Only m1 through m4 can be specified using option parameters. All five files can be specified using option parameters. None of the files can be specified using option parameters. 2. Call gather.py on those files so that it matches your circled choice. (Pick any option names you like.) Student #: Page 2 of 7 cont’d... Question 2. [15 marks] This question has you write regular expressions for a marks file in the format used by many CS instructors. Part (a) [9 marks] At the beginning of the file is a set of marks definitions, each on a separate line. Each mark name must start with an upper- or lowercase letter, and contain only alphanumeric characters (’a’ through ’z’, ’A’ through ’Z’, 0 through 9). There are the three kinds of mark definitions: • String mark: the name of the mark, whitespace, a double-quote, whitespace. • Numeric mark: the name of the mark, whitespace, a forward slash, whitespace, an integer (which is what the mark is out of), whitespace. • Computed mark: the name of the mark, whitespace, an equals sign, and a list of 1 or more mark names and weights, where each name/weight pair is separated by a colon, and the pairs are separated by whitespace. Here is an example that contains a string mark, two numeric marks, and a computed mark. cdfId " e1 / 100 e2 / 100 final = e1:50 e2:50 Write regular expressions that will match these mark definitions. In case it helps, \d matches digits, \s matches whitespace, . matches anything except the end of a line, and \t is the tab character. Numeric mark: String mark: Computed mark: Part (b) [4 marks] After the marks definitions come student lines. Each student line in the grades file has a 9-digit id, exactly 4 spaces, the name of the student (which must have at least one character and may be arbitrarily long; any character except a tab is allowed), and any number of marks, each preceded by a tab. Here is an example (there are tabs before pgries, the 80, the 40, and the 60; this example corresponds with the examples of mark definitions from Part (a)): 999888777 Gries Paul pgries 80 40 60 Write a regular expression that will match any student line following this format and extract the student number as a group, the name as a group, and the entire list of grades (including ta
More Less

Related notes for CSC207H1

Log In


Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.