Introduction to Computer Science I by James Tam Return to the course web page

CPSC 231: Assignment 8 (Worth 8%)

 

New Concepts to be applied for the assignment

  1. Records
  2. File input and output
  3. Arrays of records
  4. Sorting
  5. Basic list management functions

 

Introduction

For this assignment you are to write a Pascal program that allows a person to track the courses that he or she has taken.  In the full version of the assignment your program will read the initial course information from a file called 'courses.dat' into an array of records.  The array must be large enough to read in the information for all the courses in the input file plus it should allow the user to insert a few additional courses (just make the array size reasonable, say 100 elements).  The user can perform all the common list management functions, such as removing courses from the list or inserting new courses into the list.   When the person has finished with the program, he or she can then save the updated information back to the original file and reload that information again.

 

Assignment description

Each course will be described by four fields with each field residing on a separate line in the input file:

  1. Course identifier (name and number): This field will consist of a string of 8 characters.   The first four characters will consist of 4 upper cases alphabetic characters followed by a space which in turn is followed by three numerical characters to represent the course name and number e.g., CPSC 231.  (Since you should reserve one element in the string to mark the end of the string the string should consist of 9 elements)
  2. Course description: The maximum length for the description of the course is 80 characters (again you should leave one place to hold the marker for the end of the string which should be 81 elements long).
  3. Grade: This field will consist a real number to represent the grade received in the course: A = 4.0, A- = 3.7, B+ = 3.3, B = 3.0, B- = 2.7, C+ = 2.3, C = 2.0, C- = 1.7, D+ = 1.3, D = 1.0, F = 0.0.  You can assume that withdraws won't be tracked by the system.  The grades will be stored in the input file as a real number and displayed as a real number with one decimal point of precision.  However your program must store the number as an integer value e.g., 4.0 is stored as 40, 3.7 is stored as 37 etc.  This is to avoid rounding problems that may occur when the user wants to look up all the courses for which a particular grade was received.  (Reminder: you should never try to do an equality comparison with a real number!)  In order to read the real values from file you should declare the 'grades' field as an integer so when you read the grades from file you should first read the information into a temporary real variable.  Then you can convert the real value to an integer value (hint: consider the 'ROUND' function which takes a real number as a parameter and returns an integer) and this integer can be stored in the 'grade' field.  When the grades are written back to the output file they must be written in real format.

 

Grading: Working submissions

Features of assignments that receive a 'C+':

Your program reads the information from the input file 'courses.dat'  into the array.   (Although the grades field is an integer your program must be able to real in the real number grade points). The contents of that array can be displayed onscreen with write's and writeln statements with each course separated by a line of stars.  To prevent the output from scrolling off the screen your program should 'pause' the display of courses every so often (say after displaying every half dozen or dozen courses) while it waits for a response from the user to tell it to continue (e.g., 'Hit enter to continue').  The output must be displayed in a neat and legible format that clearly labels each field of each course (try running the sample executable for an example of how your output could look).    Also the grade must be shown in the form of real number (one decimal place) GPA: A = 4.0, A- = 3.7, B+ = 3.3, B = 3.0, B- = 2.7, C+ = 2.3, C = 2.0, C- = 1.7, D+ 1.3, D = 1.0, F = 0.0.   Finally your program must be able to write the information for the courses back to a file.  The grades must be written to the file in the same real number format as the input file.  The user should be able to specify the name of the input and output file as the program runs.  The line of stars that separated each course when they were displayed onscreen should not be written to this file but an empty line should be written instead (i.e., the format of the output file should be the same as the courses.dat input file). Similar to previous assignments, your program has menu driven interface.  The basic program should display a menu similar to the one shown below:

Course Manager: Menu options

(d)isplay courses
(l)oad the course information from a file
(s)ave the information about courses to a file
(q)uit the program
 

You should add additional menu options as you implement the extra features that are listed below. Also when your program detects when the input file is empty it should display an appropriate status message.  Finally your program should prevent overflow of the array (trying to add more elements to an array that is already full).   For this version, your program will need to perform this check as the information for the courses is read in from file.  If you implement the 'insert' feature then your program will have to perform this check at that point too.

Missing the features listed above:  You have the potential to receive a maximum grade of 'C+' if you implement all of the above features.  If features are missed or improperly implemented then your mark may be reduced by a letter step for each feature that is missed (down to a minimum grade of a 'D' assuming of course that it actually compiles):

  1. Program does not display the list onscreen in a neat and presentable fashion.
  2. Program cannot write the list information to a file (e.g., grades must be written back to the output file in real format).
  3. The user cannot quit the program.
  4. The user cannot specify the names of the input and output file at runtime (i.e., the file names are the same each time that the program is run).
  5. Program does not detect and display an appropriate message when an empty file is opened.
  6. Program does not prevent/check for overflow of the array.
  7. Grade points are not displayed in a (neat) real number format.

Extra features:

Completion of each of these extra features will result in the increase of a "one step" to your grade e.g., 'C+' to 'B-'.  Unless there is a compelling reason to do otherwise you may complete as many of the features below as you wish in whatever combination that you desire.  Successful completion of all six features will make you eligible for an 'A+'.   (You must also fulfill style requirements as well as the general submission assignment requirements

Feature one (Arrange the list of courses according to the course name and number):

To receive credit for this feature you need to sort the list of courses by the course name and number (i.e., the program will order courses first according the ASCII value of the course names and when the course names are identical it will perform the sort according the ASCII values of the course number).  To do this you need to implement a sort procedure that compares the entire 'course name identifier' field.  Unlike the way that you compared the character arrays in the sixth assignment you can compare the entire field/string (i.e., if (string1 > string 2) and you do not have to perform a character-by-character comparison (if string1[1] > string[2]).

Feature two (Find additional details about a course):

The user of the program can type a course identifier (case sensitive for the name) to find additional information about that course .  If the course is not in the list, then your program should indicate that the course could not be found under that identifier.  If the course is in the list, then your program will display additional details about that course (all the fields will be displayed onscreen).

Feature three (Present all courses that meet a certain criteria):

The user can type a real number grade point (e.g., 4.0)  and your program will display all the courses for which such a grade was awarded.

Feature four (Insert a new course):

When this feature is selected by the user, he or she will prompted to enter in information for all the fields of the new course.  If the course doesn't already exist in the list (as determined by the course identifier field) and there is room in the array, the new course will then be added into it's proper place in the list (according the ASCII value of the course identifier field).  All the courses that follow will be shifted 'down' the list.  If the course already exists in the list or if the list is already full then a suitable error message will be displayed to the user.  A simple error check that the grade is one of the valid integer values should be performed.  All of these requirements must be met in order to get credit for this feature.

Feature five (Remove a course from the list):

When this feature is invoked the user must type in the course identifier to indicate which course that he or she wishes to remove from the list.  When the list is displayed, no information about the deleted course should be displayed - not even blank spaces.  You can implement this feature by shifting the array elements that follow the element to be deleted 'up'.  To get credit for this feature your program must not allow the user to remove elements from the array when it is already empty.

Feature six (Write an enhanced Save feature)

In order to get credit for this feature, the program must be able to re-read information from the output file. When the user of the program opts to save the updated information your program will still ask for the name of the output file.  The difference is that you program now must be able to write the updated course information back to the original data file AND it must be able reload the course information from this same file.  It is the last point that is the key to this feature.  In the previous versions of your program it could write the updated information to a file but the program did not have to be able to read the updated information back into the program.  If there were small discrepancies between the input and output file that weren't visible to the human eye you could still get full credit for your work.  In this case these discrepancies will cause problems when your program tries to re-read the updated information (the key is to write it back to file in a format that is identical to the format of the input file).  Your TA will be checking if it can: 1) read the information 2) write the modified information to a file 3) re-read the modified information back into the program.

Note: The user should not be able to invoke features one, two, three, five and six when the list is empty.  If the operation is invoked then an error message should be displayed.  As previously mentioned, feature five should not be invoke able when the list is empty.

Grading: Non-working submissions

D submissions:

D- submissions:

 

Other submission requirements

  1. Good coding style and documentation:  They will play a role in determining your final grade for this assignment.  Your grade can be reduced by a letter step or more (e.g., 'A' to 'A-' for poor programming style such as employing poor naming conventions for identifiers, insufficient documentation or the use of global variables other than the debugging variable or variables).  For additional details see the marking guide for coding style.
  2. Assignments (source code/'dot-p' file and the README file) must be electronically submitted via submit.  In addition a paper print out of the source code and README must be handed into the assignment drop box (located on the second floor of the Math Sciences building) for the tutorial that you are registered in.  Your README file must indicate what grade level has been completed (e.g., 'A') and which features have been implemented.   Also you should include your contact information: your name, university identification number and UNIX login name so that your marker knows whose assignment that he or she is marking.  Omitting the necessary information from this file will result in the loss of a letter 'step' (assuming that the marker can actually figure out who the assignment belongs to).  Electronically submitting the assignment allows your marker to run the code in order to quickly determine what features were implemented.  Providing a paper printout makes it easier for your marker to read and flip through your source code.  Omitting the paper printout of your program will result in the loss of a letter 'step'.  Omitting the electronic submission of your program will only allow you to receive a maximum grade of D-.
  3. As a reminder, you are not allowed to work in groups for this class.   Copying the work of another student will be regarded as academic misconduct (cheating).  For additional details about what is and is not okay for this class please refer to the following link.

 

Relevant files

You can run a sample executable called 'courses' which can be found in the UNIX directory:  /home/231/assignments/assignment8.  In addition there is a data file that your TA's will use when they are marking your program called 'courses.dat'.

1 What does and doesn't constitute a sufficient amount of time and effort?  It's a judgment call on the part of your marker.  More often than not if you put in a reasonable amount of effort into your assignment and for some reason you just couldn't get it to work then you will receive some credit for your work.   An example of when you wouldn't receive credit is when you simply handed someone else's work.  This latter case assumes that you properly cited the other person's work, if you didn't cite your source and tried to claim that it was your own work then it would be an example of academic misconduct (cheating).