CSC325 2010F Web and Databases

Warning! The Web site for this class is in beta form.

Mid-Semester Exam

Assigned: Wednesday, 27 October 2010

Due: 8 p.m., Friday, 5 November 2010


Exam Format

This is a take-home examination. You may use any time or times you deem appropriate to complete the exam, provided you return it to me by the due date.

There are four problems on this examination. They are not necessarily of equal difficulty. Each problem may include subproblems. Four correct or mostly-correct solutions will earn you an A. Three correct or mostly-correct solutions will earn you a B. Two correct or mostly-correct solutions will earn you a C. One correct or mostly-correct solutions will earn you a D. Zero correct or mostly-correct solutions will earn you an F. Failure to attempt the exam will earn you a 0. Partially-correct solutions may or may not earn you a partial grade, at the discretion of the grader.

Read the entire exam before you begin.

I expect that someone who has mastered the material and works at a moderate rate should have little trouble completing the exam in a reasonable amount of time. In particular, this exam is likely to take you about eight hours, depending on how well you've learned the topics and how fast you work. You should not work more than twelve hours on this exam. Twelve hours of work, documented attempts on all four problems, and a signed statement that There's more to life than computer science will earn you at least a C on this exam.

I would also appreciate it if you would write down the amount of time each problem takes.

Academic honesty

This examination is open book, open notes, open mind, open computer, open Web. However, it is closed person. That means you should not talk to other people about the exam. Other than as restricted by that limitation, you should feel free to use all reasonable resources available to you.

As always, you are expected to turn in your own work. If you find ideas in a book or on the Web, be sure to cite them appropriately. If you use code that you wrote for a previous lab or homework, cite that lab or homework and the other members of your group. If you use code that you found on the course Web site, be sure to cite that code. You need not cite the code provided in the body of the examination.

Although you may use the Web for this exam, you may not post your answers to this examination on the Web. And, in case it's not clear, you may not ask others (in person, via email, via IM, by posting a please help message, or in any other way) to put answers on the Web.

Because different students may be taking the exam at different times, you are not permitted to discuss the exam with anyone until after I have returned it. If you must say something about the exam, you are allowed to say This is among the hardest exams I have ever taken. If you don't start it early, you will have no chance of finishing the exam. You may also summarize these policies. You may not tell other students which problems you've finished. You may not tell other students how long you've spent on the exam.

You must include both of the following statements on the cover sheet of the examination.

  1. I have neither received nor given inappropriate assistance on this examination.
  2. I am not aware of any other students who have given or received inappropriate assistance on this examination.

Please sign and date each statement. Note that the statements must be true; if you are unable to sign either statement, please talk to me at your earliest convenience. You need not reveal the particulars of the dishonesty, simply that it happened. Note also that inappropriate assistance is assistance from (or to) anyone other than Professor Rebelsky (that's me).

Presenting your work

You must present your exam to me in two forms: both physically and electronically. That is, you must write all of your answers using the computer, print them out, number the pages, put your name on the top of every page, and hand me the printed copy. You must also email me a copy of your exam. You should create the emailed version by copying the various parts of your exam and pasting them into an email message. In both cases, you should put your answers in the same order as the problems. Failure to name and number the printed pages will lead to a penalty. Failure to turn in both versions may lead to a much worse penalty. Failure to turn in a legible version of the exam is also likely to lead to a penalty.

In many problems, I ask you to write code. Unless I specify otherwise in a problem, you should write working code and include examples that show that you've tested the code.

Unless I explicitly tell you not to document a procedure, you should assume that you must document every procedure you write using six-P style documentation. You need not document main or procedures whose primary purpose is to run unit tests.

Just as you should be careful and precise when you write code and documentation, so should you be careful and precise when you write prose. Please check your spelling and grammar. Since I should be equally careful, the whole class will receive one point of extra credit for each error in spelling or grammar you identify on this exam. I will limit that form of extra credit to five points.

I may give partial credit for partially correct answers. I am best able to give such partial credit if you include a clear set of work that shows how you derived your answer. You ensure the best possible grade for yourself by clearly indicating what part of your answer is work and what part is your final answer.

Getting help

I may not be available at the time you take the exam. If you feel that a question is badly worded or impossible to answer, note the problem you have observed and attempt to reword the question in such a way that it is answerable. If it's a reasonable hour (before 10 p.m. and after 8 a.m.), feel free to try to call me in the office (269-4410) or at home (236-7445).

I will also reserve time at the start of each class before the exam is due to discuss any general questions you have on the exam.


Problem 01: Extreme Programming and Homework Assignments

Topics: Extreme Programming

In Section 2 of Extreme Programming Explained, Kent Beck provides a list of twelve key practices of Extreme Programming (XP).

Suppose you were told to adapt XP to your project for this class. Clearly, not all of the XP practices would work as given (e.g., a 40-hour week for one class is probably not appropriate). Nonetheless, we could adapt them (e.g., a 15-hour week for this class may be appropriate).

Identify the four most important practices to adapt or adopt for this class's project and explain why these four practices are more important than the rest.

Identify the least important practice to adapt or adopt for this class's project and explain why this practice is less important than the rest.

Problem 02: Safer SQL

Topics: SQL, Reliability

In our consideration of the books database, we noted that it was important to avoid entering duplicate authors. While we could rely on practices to ensure that there are no duplicates (e.g., locking the table and checking for the author before adding an author) such practices are just that, practices.

However, Bowman et al. suggest that we should be designing our databases so that they ensure consistency. We would therefore hope that we could use SQL to specify that duplicates are not permitted.

a. Provide SQL code to create an authors table that will not allow duplicate author names. You must preserve the AuthorID field as primary key, since the books table relies on it.

Another reliability issue that has cropped up in the database is that we can delete authors, leaving the AuthorID link in the books table dangling.

b. Provide instructions for creating the books and authors tables in such a way that either (1) an author whose ID is used by the books table cannot be deleted or (2) when an author's ID is deleted, all books by that author are also deleted.

Problem 03: Generalized Queries

Topics: SQL, PHP

In your interface for querying the books database, you wrote fairly repetitious code. In essence, for each possible field that you might use, you extended the WHERE clause.

Write a PHP procedure, makeSelect(tables, desired), that takes two parameters, an array of table names and an associative array of whose keys are attribute names and whose values are desired values for those attributes, and builds a select query that looks for all the values in the combination of the tables in which the designated fields contain the designated values.

Your procedure must ensure that when two tables have the same field name, the query requires that those two fields be the same.

Problem 04: A Generalized UI for Inserting Data


In a recent assignment, you wrote a user interface to insert data into a group of related tables. Clearly, it would be useful to generalize that code.

a. Write a function, generateForm(tables) that builds a appropriate form for inserting into a set of linked tables. You should not include the ID fields (which link the tables) in that form.

b. Write a function, insertData(tables,info), that has two parameters, an array of table names and an associative array of attribute/value pairs, and inserts the data appropriately. You should do your best to avoid duplicating values. (You may design the policy that says when a new entry is a duplicate.)

c. Using these functions, build a new user interface (UI) for the books database.


Here you will find answers to questions of general interest. Please check here before emailing your questions!


Can we get extra credit for finding errors in the Q&A section or the errata?
No. I'd still appreciate hearing about the errors, but the policy only applies to the main part of the test.
Who makes the decision as to whether or not a correction is acceptable.
I do.
Is that fair?
I don't care.


Here you will find errors of spelling, grammar, and design that students have noted. Remember, each error found corresponds to a point of extra credit for everyone. We usually limit such extra credit to five points. However, if I make an astoundingly large number of errors, then I will provide more extra credit.



Tuesday, 26 September 2010 [Samuel A. Rebelsky]

  • Created.

Wednesday, 3 November 2010 [Samuel A. Rebelsky]

  • Fixed some errors.

Friday, 5 November 2010 [Samuel A. Rebelsky]

  • Fixed more errors.


Disclaimer: I usually create these pages on the fly, which means that I rarely proofread them and they may contain bad grammar and incorrect details. It also means that I tend to update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.

This document was generated by Siteweaver on Fri Nov 5 08:45:28 2010.
The source to the document was last modified on Fri Nov 5 08:45:26 2010.
This document may be found at

You may wish to validate this document's HTML ; Valid CSS! ; Creative Commons License

Samuel A. Rebelsky,