Lab Assignment 9

This assignment is due at the end of lab on Friday, December 4.

Choose a partner for this assignment, someone you haven't worked with already.

(a) Do exercises 35.2.2, 35.2.3, and 35.4.1. Then do exercises 37.5.1, 37.5.2, and 37.5.3.

Submit your definitions via Checkmate.

(b) Professor Andrea Anteater wants you to design a grade management system for her students in Applied Epistemology 101. This system will read and write students' scores from a file and allow the user to produce statistics and histograms (frequency graphs) of the scores.

Your task this week is to create this program from scratch. It's not really from scratch, though: We provide a set of specifications for you to implement and you can use all of the example programs we've seen all quarter. Hardly any programming today is totally from scratch; we have application frameworks (skeleton programs with all the infrastructure supplied), we have function libraries that provide commonly useful tasks, we have object libraries and class hierarchies that we can adopt and adapt to our own purposes.

To help you along, here are five pieces of development advice:

You'll be using Advanced Student Scheme for this program, with the advanced-file-io.ss teachpack. (Download the file; don't just copy and paste the code.)

(b.1) Your program will handle these classes of data:

To start out, make sure you understand these data structures: Make up some examples; draw a picture; get comfortable with how they're organized. Then you'll want to define functions that create objects in each of these classes (these can be quite simple) and that display those objects. [Note on terminology]

(b.2) When your program starts, it will read the collection of assignments from a plain text file called Assignments.txt. (If you place your program file and these data files in the same directory/folder, DrScheme will find them without your having to do anything fancy.) Then it will read the collection of students from a text file called Students.txt. Since the user can create these files without knowing any Scheme, your program won't have to handle changes to the data (although that's an enhancement we discuss below).

The user can create these files using a plain ASCII text editor like NotePad (or from Word by using Save As and the Text Only format, which saves plain ASCII without the additional Word formatting information that your program can't read).

For a course with a 75-point midterm worth 40% of the grade and a 100-point final worth 60%, the assignments file would look like this:

Midterm Exam
40 75
Final Exam
60 100

The first line contains the number of assignments. Then each assignment has two lines, the first containing the assignment's name and the second containing two numbers, the weight followed by the possible points.

A file of students for this course would look like this:

Aardvark, Aaron
68 85
Tapir, Tamara
74 92

The first line contains the number of students. Then each student has three lines, the first containing the student's name, the second containing the student's ID, and the third containing the student's scores on each assignment, in order.

As you read these files, remember that the read-line function reads an entire line of input and returns a string (this is useful for reading strings that may contain blanks, without requiring the user to enclose the strings in quotation marks). The read function reads the next Scheme expression (e.g., a single number) from the input. You'll also want to call read-line (ignoring its return value) after reading numbers from a line; this will put you at the start of the next line so you're ready to read what's there. Some sample code using read-line is available.

[This organization of the input files should make it easy for you to use read and read-line to create the internal representation of the data in your program; your task is to fit these components together, and you should spend some time trying to do that. But if you decide you need some additional guidance, start here: (a) As always when designing programs with more than one "layer" of data structures, you should treat one layer at a time. For the file of students, for example, you should have a function to read and create the collection of n students (where n is the number specified on the first line of the file); that function will call a function to read and create the strucure for one student; that function, in turn, will call a function to read m numbers from one line (where m is the number of assignments, from the first line of the assignments file) and create a vector of those scores. (b) Make sure you understand how to use read and read-line: Choose the right function for the right kind of data, as described above.]

Define functions that will fill the assignment and student collections by reading these files. It will also be helpful to write functions that print out these collections legibly; they'll help you in testing.

(b.3) Since assignments don't necessarily all have the same number of points possible, it will be useful to compute and store a scaled score on each assignment (i.e., a number from 0 to 100, calculated from the student's raw score and the number of points possible on the assignment). It might be easiest to implement this by storing for each student a second, parallel vector of scaled scores.

You should also compute and store for each student the weighted overall score in the course, a number from 0 to 100 calculated from the scaled scores and the weights of each assignment.

To make the output look reasonable, use the function format-decimal. It takes two numbers (the first is the value to display, the second is the number of digits after the decimal point) and returns a string, suitable for use as an argument to display. So, (format-decimal 25 2) returns "25.00" and (format-decimal 17.9876 3) returns "17.988".

(b.4) Your program will have a text-based menu interface like the one in the restaurants programs. It should include commands to

[Your first step here should be to write the menu-handling code, based on the restaurants programs, before writing code to do anything when the user selects a given command. For each menu command besides Quit, just print out "Received command X," where X is the command; we call this a "program stub," a simple placeholder so you can see that the menu framework works before you write the code that actually performs each command. Then take each command, one by one, and code and test its implementation. You should use the restaurants code as a starting point, just changing the things you need to change for this task; don't try to create a new view/controller from scratch. Start with displaying the assignment information (because that's the easiest).]

(b.5) A histogram is a bar graph showing the distribution of all the students' scores, from highest to lowest. Given a list of scores, for example

(list 23 23 20 18 25 14 16 18 15 16 23)

the histogram should display

   25 *
   23 ***
   20 *
   18 **
   16 **
   15 *
   14 *

Hints: You might find it particularly convenient to create a vector of frequencies where (vector-ref freqency-vector N) contains the number of students whose score was N. A simpler histogram would display the frequencies of scaled (0 to 100) scores, with 101 lines from 100 down to 0; start by implementing it that way. You'll want to use the predefined round function to convert all the scores to integers.

(b.6) Implement at least one of the following enhancements. In a comment at the top of your definitions, list which one(s) you implemented. Note that it is never acceptable (in class or in the real world) to submit buggy code. It is much better to deliver fewer features, but features that work correctly, than to provide fancier functionality that "almost works." [This doesn't mean that you have to implement every single aspect of a bullet item below, but it does mean that whatever you do implement must work correctly and consistently with the rest of your program.]

(b.7) Submit the file containing all your definitions as usual via Checkmate.

(c) Fill out your last partner evaluation form at eee.uci.edu. Please do this by noon on Saturday at the latest, or you won't get credit.

Based in part on ICS H21assignments by David G. Kay from Fall 2003; modified by David G. Kay, Fall 2004, Fall 2008, Fall 2009..

David G. Kay, kay@uci.edu
Saturday, November 21, 2009 9:57 AM