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

CPSC 231: Assignment 7 (Worth 6%)

New concepts to be applied in this assignment

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

Introduction

For this assignment you are to write a Pascal program that allows a person to track a list of potential vacation sites.  In the full version of the assignment your program will read the initial information from file called 'vacation.dat' into an array of records.   The user can perform all the common list management functions, such as editing existing sites or inserting new sites into the collection.   When the person has finished with the program, he or she can then save the updated information back to original data file and to reload the updated information later. 

Assignment description

Each site will be described by four fields with each field residing on a separate line in the following order:

  1. Site name

  2. Travel cost

  3. Vacation type

  4. Site rating

Description of the fields

1. Site name

The name of the site will be stored as a string of characters up to 80 characters in length.

2. Travel cost

This field only tracks only travel costs and excludes other expenses such as accommodations and meals.

3. Vacation type

This field describes the main reason for traveling to this location.  There will be five different categories of sites with each one being representing by a single character code: relaxation (r), excitement (e), culture (c), nature (n) or food (f).   For this assignment you can assume a particular site will not be categorized in multiple ways.

4. Rating

This field is a numerical value from 1 - 10 that indicates how much that the person wants to go to a particular vacation spot with 10 being the most desirable and 1 being the least desirable.   

The information for each site will be separated in the data file by a blank space which is only used to visually separate the information and is not to be read into the array.

Grades for working assignments:

Basic assignment: C

Your program reads the information from the input file 'sites.dat'  into the array.   The contents of that array can be displayed onscreen with write's and writeln statements.  Each site will be separated onscreen by a line of stars.  To prevent the output from scrolling off the screen your program should 'pause' the display of sites ever so often (say after displaying every 3rd or 4th site) while it waits for a response from the user to tell it to continue (e.g., 'Hit return to continue').  The output must be displayed in a neat and legible format (try running the sample executable for an example).    Finally your program must be able to write the site list back to a file whose name will be specified by the user when the program runs.  The blank space that separated each site in the input file must be written back to the output file.   Similar to previous assignments, your program has menu driven interface.  The basic program should display a menu similar to the one shown below:

Site Manager: Menu options

(d)isplay collection (show the collection onscreen).

(l)oad a collection from disk (reads the information for the collection from disk, any existing information in the array will be overwritten by the information that was loaded).

(s)ave the collection to disk (saves the information to a separate output file and not the one that it was originally read from.

(q)uit the program.

You should add additional menu options as you implement the extra features that are listed below.

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 'C+'.  Except for features two, four  and six you can complete as many of the features below as you wish in whatever combination that you desire.   In the case of those three features you must have completed feature two before you can get credit for feature four or six.   Successful completion of all seven features will make you eligible for an A+.   (You must also fulfill style requirement as well as the general submission assignment requirements).

Feature one (Alphabetize the site list according to name):

Sort the list into alphabetical order according to the name of the vacation spot.

Feature two (Find additional details about a site):

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

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

This feature allows the user of the program to display onscreen only sites that meet a specific criteria for the 'vacation type' field.  The user can type in one of the rating categories and your program will display all the places which are categorized under that type of vacation.

Feature four (Edit site information - requires that you have already completed feature two):

Edit the information for a site in the list.  In order to complete the requirements for this feature you must have completed feature two because the user of the program must indicate to the program which site that they wish to edit by entering the name of the site and the program searches for that site and the user of the program will then be able to re-enter the information for all the fields of that site one field at a time.  If site cannot be found in the list then the program will display a suitable error message.

Feature five (Insert a new site):

When this feature is selected by the user, he or she will prompted to enter in information for all the fields of the new site.  If the information for the site has not yet been entered and there is room in the array, the new site will then be added to the end of the list.  Otherwise a suitable error message will be displayed to the user.

Feature six (Remove a site from the list - requires that you have already completed feature number two):

Again, the user must type in the name of the site in order to indicate which site that he or she wishes to remove from the list so you need have complete the lookup contact feature first (feature two).  When the collection is displayed, no information about that site 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'.

Feature seven (Write an enhanced Save feature)

In order to get credit for this feature, the program will now use only one data file.  The program will load the site information from the "sites.dat" file.  When the user of the program selects the 'save' option then the program can write the modifications to the "sites.dat" file rather than a separate file.  To get credit for this feature your program must be able to reload the updated information from the modified file.   This latter requirement means that your program must write the information to disk in the exact same format that it was originally stored.  If there any differences from the original data file and the modified version your program will not be able to properly read it back into the array.

Grades for non-functional assignments

D level assignment

The student has invested considerable work in the assignment and the code compiles but it doesn't fulfill any of the above requirements.

D- level assignment

The student has invested considerable work in the assignment but it doesn't compile.

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 if your submission was implemented using bad style conventions (e.g., 'A' to 'A-' for employing poor naming conventions for identifiers, insufficient documentation, the use of global variables, using non-modular design or having an excessively large amount of redundant code in your program).

  2. Include a README file in your submission:  For this assignment your README file must indicate what grade level that you think your assignment should receive (e.g., 'A', 'B' or 'C') and the features that you have implemented.  This will allow your marker to quickly determine what he or she must look for and speed up the marking process.

  3. Assignments (source code/dot-p files 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 for the tutorial that you are registered in (located on the second floor of the Math Sciences building).  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.

Relevant Files

In the directory for this assignment you will be able to run a sample executable called "sites".  It has all features of this assignment working with only a slight modification.  Because you won't have permission in Unix to write updates to the assignment directory I've disabled all features that save the information to disk (such as feature #7).  In this directory you will also find the full input file called "sites.dat" as well as a smaller form of the input file called "miniSites.dat".  The program that you hand for marking must be able to run using the full input file but you can use the second file, which is smaller, for testing purposes.