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 for the assignment

  1. Records and arrays of records
  2. File input and output
  3. Sorting
  4. Basic list management operations

Introduction

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

Assignment description

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

  1. Title  The title of the book will consist of a string of up to 80 upper case characters.
  2. Author: The maximum length for each author's name is 80 characters.
  3. Genre: This field will consist of a two character code: FA = Fantasy, SF = Science Fiction, HO = Horror, FI = Fiction, NF = Non-fiction, IN = Instructional
  4. Rating: A numerical integer rating from one (lowest) to ten (highest).1
1.  JT: The rating value given to the books in the input file was based solely upon my opinion and does not necessarily reflect the opinions of the university so please don't write angry letters outrage  because you thought I didn't properly rate your favourite book

The four main fields for each book will be followed by an empty line (to be specific it's the end-of-line marker):

THE UNIVERSE IN A NUTSHELL
Stephen Hawking
IN
8

A CHRISTMAS CAROL
Charles Dickens
FI
10

DRACULA
Bram Stoker
HO
10

THE QUEEN'S FOOL: A Novel
Philippa Gregory
FI
6

THUNDER RUN: THE ARMOURED STRIKE TO TAKE BAGHDAD
David Zucchino
NF
10

 

Grades for working assignments:

Basic assignment: C

Your program reads the information from the input file 'books.dat'  into the array.   The contents of that array can be displayed onscreen with write's and writeln statements with each book separated by a line of stars.  To prevent the output from scrolling off the screen your program should 'pause' the display of books ever so often (say after displaying every 5th or 6th book) 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 book (try running the sample executable for an example of how your output could look).    Finally your program must be able to write the information for the book collection back to a 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 book when 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 books.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:

Book Manager: Menu options

(d)isplay collection
(l)oad a collection from a file
(s)ave the collection to a file
(q)uit the program

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

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 updated information for the list to file.
  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 must be the same each time that the program is run).

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+'.  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 (Alphabetize the list according to titles):

Sort the list into alphabetical order according to the name of the book.

Feature two (Find additional details about a book):

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

Feature three (Present all books of a certain genre):

This feature allows the user of the program to display the titles of all of the books of a particular genre (alternatively you can get your program to show all titles that were written by a particular author or with a specific rating but since these operations are very similar you will only get a maximum credit of one grade step for this feature regardless of how many criteria that your program can use as presentation criteria).

If you have already completed feature one, then the books will be presented in alphabetical order, otherwise they will presented in the order in which they currently appear in the array.  

Feature four (Insert a book at the end of the list):

When this feature is selected by the user, he or she will prompted to enter in information for all the fields of the new book which will then be added to the end of the list.

Feature five (Remove a book from the list):

Since the user must type in the name of the book in order to indicate which book that he or she wishes to remove from the list you will likely have already completed the 'find' feature first (feature two).  When the collection is displayed after the removal, no information about the book that was removed should be displayed - not even blank spaces.  You can implement this feature by either shifting 'up' the array elements that follow the element to be deleted or you may be able to add an additional field for each array element that indicates whether it has been deleted or not (JT: I'd recommend the first approach because you'll probably find it easier to implement).

Feature six (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 'books.dat' file.  When the user of the program selects the 'save' option then the program can write the modifications to the 'books.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 - other than debugging variables (JT: although it's not explicitly required for this assignment I still recommend that you use them to quickly find the errors) - or for non-modular design).  See the coding style guide for additional details.
  2. Include a README file in your submission:  For this assignment your README file must indicate what grade level has been completed (e.g., B+) as well as the specific features that are working e.g., "I completed all the requirements of the base level assignment plus the ability to: alphabetize the list so this assignment may receive a maximum grade of 'C+' for functionality."  This will allow your marker to quickly determine what he or she must look for and speed up the marking process.  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 this file will result in the loss of a letter 'step'.
  3. Assignments (source code 'files that end in dot-p' 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.  Missing the electronic submission will mean that your maximum grade attainable is 'D' or 'D-' (it is very time consuming to mark assignments when you only hand in paper submissions).  Missing the paper printout will result in the loss of a letter 'step'.

Relevant files (Can be found in the Unix directory: /home/231/assignments/assignment7)

  1. Sample executable: 'books'
  2. Data file: books.dat