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. File input and output
  2. Arrays of records
  3. Common list management functions (including sorting)

 

Writing a list management program:

For this assignment you are to write a Pascal program that allows a person to manage a list of audio CD's.  In the full version of the assignment your program will read the initial information a file into an array of records. The user can perform common list management functions, such as adding or removing entries or sorting the list.  When the person has finished with the program, he or she can then save the updated information back to the data file and to reload the updated information later. 

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

  1. The name of the CD

  2. The artist

  3. The genre that best describes the CD (rock, dance, rap, hip-hop, etc.)

  4. Price

Description of the fields

1. The CD name

This field will consist of string of characters (max 80).

2. Artist

This field will consist of string of characters (max 80). You can assume that each CD will only have one artist associated with it.

3. The genre

This field will consist of string of characters (max 80). You ignore cases where a CD falls under multiple categories.

4. Price

The program stores the price of the CD as an integer value in cents (e.g., $19.99 = 1999 cents).

 

Features to be implemented
 
  1. Correctly declares a new type 'CD' that tracks all the pertinent information for a CD.
 
  1. Correctly declares a new type 'CDList' that is an array of type 'CD' with 100 elements.
 
  1. Declares an instance of the array, type 'CDList'.
 
  1. Displays instructions on how to use the program each time that it is run.
 
  1. Display a signoff message to indicate to the user that he or she has quit the program.
 
  1. Some form of debug mode has been implemented.
 
  1. Displays a menu showing the list management functions.
 
  1. Program repeats until the user quits the program. Each time that program repeats the main menu (above) is displayed. The (Q)uit option of the main menu has been implemented.
 
  1. (D)isplay: Displays the list in a neat and presentable form (try running the sample executable for an example). Only the occupied array elements will be displayed. If the array is empty then some sort of status message should be provided (e.g., "List is empty: nothing to display"). Each CD should be separated by a line of stars. When the list is long, to prevent the output from scrolling off the screen your program should 'pause' the display every often (say after displaying a half a dozen list elements) while it waits for a response from the user to tell it to continue (e.g., "Hit enter to continue").  In order to receive credit for this feature you must have already implemented some way of adding elements to the list either by reading from file or by allowing the user to type in the information for a new element.
 
  1. Each time that CD's are shown (display, find, present) the price shown in dollars instead of cents. (JT's hint: after you convert from dollars to cents you need to convert the real dollar value to a integer value in cents so consider using something like the round function).
 
  1. (L)oad: The user will be prompted for the name of the input file and the program loads the information for the list from that file. The file that you can use for simple testing is 'mini.txt'. Before handing in your assignment you should make sure that it also works with the full sized input file 'cd.txt'. What was in the collection previous to the load is lost. Your program should check that the array capacity hasn't been exceeding during the loading process.
 
  1. Program can detect and properly handle the case of an empty file (e.g., 'empty.txt') by displaying some sort of status message (e.g., "File is empty: nothing to read").
 
  1. (S)ave: The user can save the list to a file (name specified at run time). In order to receive credit for this feature your program must be to read and write to the input file multiple times (that means that you must write the information in a format that is identical to how the information was originally stored).
 
  1. (F)ind: Program can find details about a particular CD. The user enters the CD name and if a match was found all the information for that CD will be displayed onscreen. Otherwise a suitable error message should be displayed. The program should not allow the user to search an empty list (a suitable error message should be displayed).
 
  1. (P)resent: You can get credit for either the basic or the enhanced version (but not both). However in both cases the price for min and max should be entered in dollars by the user so your program needs to somehow convert it to cents (JT's hint: after you convert from dollars to cents you need to convert the real dollar value to a integer value in cents so consider using something like the round function). As with the find feature, the user should not be able to invoke this feature if the list is currently empty (a suitable error message should be displayed).
   
  1. Basic version: Program will present all the CD's within a given min and max price range.
   
  1. Enhanced version: The user can enter a negative value for either the min or the max to ignore either criteria: 1) If the user enters a negative value when prompted for the min value then the min value becomes zero (effectively having no minimum price) 2) If the user enters a negative value when prompted for the max value then the max value becomes an arbitrary value that is higher than the price of any of the CD's e.g., 65000 effectively removing the upper bound on the search.
 
  1. (A)dd: New CDs can be added to the list if the list is not yet full (a suitable error message should be displayed if it is). When this option is selected the user will be prompted to enter the information for the CD to be added to the end of the list.
 
  1. (R)emove: Allows CD's to be removed from the list. You can implement one of two versions of this features (shown below). In both cases the program should produce some sort of error message if the list is already empty when this feature is invoked.
   
  1. When this feature is invoked the program will remove the last CD from the list.
   
  1. When this feature is invoked the user will be prompted to end the name of the CD to remove. If the match was found then the CD is removed otherwise some sort of error message should be displayed (e.g., "CD: Let go' could not be found in the list").
 
  1. (O)rder: Sorts the CD's into alphabetical order according to the CD name.

 

Submission requirements

In addition to having to fulfill the generic assignment requirements, the requirements specific to this assignment include:

  1. Include a README file in your submission:  For this assignment you need to include a file called 'README' which includes your contact information: your name, university identification number and UNIX login name as well as all the features of the program that you implemented so that your marker knows whose assignment that he or she is marking and what features to look for.

  2. Assignments (source code/'dot-p' file and the README file) must be electronically submitted.  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.  Electronically submitting the assignment allows your marker to compile and 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 to check for things like program style.

  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.

To help make sure that you haven't missed anything here is a [checklist] of items to be used in marking.  A sample executable 'music' can be found in UNIX under the directory: /home/231/assignments/assignment8. Sample input files that you can use include 'empty.txt', 'mini.txt' and 'cd.txt'.