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

CPSC 231: Assignment 7

New concepts to be applied for the assignment

  1. File input and output
  2. Arrays of records
  3. Common list management functions.

Writing a list management program

For this assignment you are to write a Pascal program that allows a person to manage their movie collection.  In the full version of the assignment your program will read the initial information a file into an array of records.  (For marking purposes your program must be able to use 'movies.dat' as an input file).  The user can perform common list management functions, such as adding or removing movies.   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 movie will be described by four fields with each field residing on a separate line (or lines in the case where there are sub-fields) in the following order:

  1. Movie name

  2. The names of the first three cast members.

  3. The genre of the movie

  4. The number of stars (the rating of the movie)

 

Description of the fields

1. Movie name

The name of the movie will be up to 80 characters in length.

2. Cast

The cast list will consist of the full names of three of the actors from this film.   Each actor's name will appear on a separate line, both in the data file and when the collection is displayed onscreen. Each actor's name acts as a sub-field for this field but you can treat each person's name as one continuous string, e.g., you don't need separate fields for the first, middle and last name.  The maximum length of the name field for each actor will be 80 characters.   Thus a 1D array of strings can be used to store the cast information: the number in the brackets determine which actor is being accessed while index for a particular string determines which part of an actor's name is being accessed.

  [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] ... [80]
[1] H e a t h e r   M o r r i s    
[2] R i c h a r d   G r o s s e    
[3] D o n n a   B u r k e          

In the example above the first element of the array is the string 'Heather Morris'.  The first element of this string is the character 'H', the second is 'e' etc.

3. Genre

The genre field describes the category that the movie falls into.  There will be six different categories of movies: action, drama, science fiction, comedy, horror, martial arts or 'other'.   In the input file, the genre field will consist of a series of character up to fifteen characters in length.

4. Rating

This field uses a number of stars to rate each movie according to how good or bad that I thought it was1.  The greater the number of stars, the better the movie.  In the input file the number of stars that a movie received will be specified by an integer ranging from one to five.

    1 star (It sucks): It's not the type of movie that's so bad that it's good, it's just all bad.  Don't  
    waste your time with this one.

    2 stars (Poor): Overall there were more things that I disliked than liked with this movie.   
    Unless there's a ticket sale it's probably one that you should avoid.

    3 stars (Average):  There were some things that I liked and some things that I disliked.  It's one
    that you may want to rent rather than buy.

    4 stars (Good): This movie has some flaws but overall you'll have a great time watching it.

    5 stars (A true masterpiece!): I laughed, I cried, it became a part of me.  It should definitely 
    be nominated for an Oscar (maybe several).

The four main fields for each movie will be followed by a line of stars:

TERMINATOR 2 JUDGMENT DAY
Arnold Schwarzenegger
Linda Hamilton
Edward Furlong
Action
5
************
IT'S A WONDERFUL LIFE
James Stewart
Donna Reed
Lionel Barrymore
Drama
5
************
ROMEO AND JULIET
Leonard Whiting
Olivia Hussey
John McEnery
Drama
5
************

The lines of stars are not to be read into the array of records.  It is only used to visually separate the movies in the input file.

1.  JT: The number of stars given to the movies 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 favorite flick

 

Features to be implemented (you will also be graded on other criteria such as coding style and providing program documentation as listed in the marking guide): 

 
  1. Displays an introduction to the program that describes how it works each time that it's run.
 
  1. Displays a sign off exit message to indicate to the user that he or she has exited the program.
 
  1. Declares a new type (e.g., 'Movie') that stores the 4 attributes of each movie.
 
  1. Declares a new type (e.g., 'MovieList') that consists of an array of 100 elements with each array element consisting of a movie.
 
  1. Declares an instance of the array which is of type 'MovieList'
 
  1. Initializes each field of each element of the array to the following values (Name := 'NNNNNN'; Cast (all three members are set to this value) := 'CCCCCC'; Genre :='GGGGGG'; Rating := -1').
 
  1. Implements some form of debug mode (i.e., it has a debugging variable that will display some sort of debugging message when the program is in debug mode).
 
  1. The program error checks the genre field to ensure that a proper category is entered.  If another genre is entered then the program will enter 'other' as the genre.
 
  1. The program error checks the rating field to ensure that a movie receives a rating from one to five stars.  If another value is entered then the program will set the rating to 3.
 
  1. Displays a menu listing the list operations available.
 
  1. The program repeats until the user quits. Each time that the program repeats the main menu (above) is displayed. The (Q)uit menu option has been implemented.
 
  1. (L)oad: The program reads the information from the input file (specified by the user) into the array. Any movies that previously resided in the array are overwritten by the ones read in from file.
 
  1. (D)isplay: The contents of the array can be displayed onscreen with write and writeln statements.  Each movie will be separated onscreen by a line of tildes '~'.  When the list of movies is long, to prevent the output from scrolling off the screen your program should 'pause' the display of movies ever so often (say after displaying every 4th or 5th movie) 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 (try running the sample executable for an example).    Also only the occupied elements of the array should be displayed onscreen e.g., if only 20 out of 100 elements are occupied then the other 80 elements should not be shown. In order to receive credit for this feature you must have already implemented some way of adding elements to the list (so your marker can quickly see that the display operation is actually working).
 
  1. (S)ave: The program must be able to write the movie list back to an output file (specified by the user).   The line of stars that separated each movie in the input file must be written back to the output file.
   
  1. The program can write to a user-specified file. In this simple version the program does have to read from this file again.
   
  1. The program can write to a user-specified file. In the more advanced version the program has to be able to read and write to the 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 additional details about a movie: The user of the program can type in the name of the movie (case sensitive) to find additional information about that movie.   If the list is empty then the program should inform the user of this fact and no search should be performed.  If the movie is not in the list, then your program should indicate that the movie could not be found under that name.  If the movie is in the list, then your program will display additional details about that movie (all the fields of that movie will be displayed onscreen).
 
  1. (P)resent genre: The user can type in a genre  (case sensitive) and the program will list all the movies that fall in the genre specified by the user.  If the list is empty then the program should inform the user of this fact and no search should be performed.  If no instances of the genre could be found in the list, then your program should also indicate this to the user.
 
  1. (A)dd a movie to the collection: When this feature is selected by the user, he or she will prompted to enter in information for all the fields of the new movie which will be added to the end of the list. Tthe program should check if the list is already full, if it is then a suitable error message should be displayed to the user and no addition will be performed.
 
  1. (R)emove a movie from the list: When the collection is displayed, no information about that movie should be displayed - not even blank spaces. 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 movie from the list.
   
  1. When this feature is invoked the user will be prompted to end the name of the movie to remove. If the match was found then the movie is removed otherwise some sort of error message should be displayed e.g., "Movie "BORAT" was not found in the collection, removal cannot be performed".  If the list is already empty when this feature has been invoked then a suitable error should be displayed to the user. 

 

Submission requirements

In addition to having 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 so that your marker knows whose assignment that he or she is marking.  Also it should list the features of the assignment that have been implemented in your program.

 
  1. The programming assignments require a two part submission: a) A paper submission of your README file and Pascal program into the assignment drop boxes (second floor Math Sciences) b) An electronic submission (again of your README file and your Pascal program) as an email attachment (don't cut and paste it into the email body!) to the following people (failing to include everyone listed below may result in your assignment not being marked for credit so before submitting your assignment double check!) Make sure that the subject line of the email contains the exact text (don't add or delete anything to it or you will lose marks - mail filters work by looking for specific words in the subject line): CPSC 231 Assignment X. Both parts are necessary. 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.  A typescript of your execution is not needed for the programming assignments (this assignment onwards).

X = The appropriate assignment number (e.g., for Assignment 2 the subject would be titled "CPSC 231 Assignment 2")

 
  1. The course instructor at the following email address: tamj@cpsc.ucalgary.ca
 
  1. Your tutorial instructor, the email addresses for the TA's can be found on the main course web page.
 
  1. Yourself. Sending the assignment to yourself provides one last "double check" that you submitted your assignment properly (e.g., you sent it to all the right people, you attached all the important files to the submission etc...you should actually open the file attachments and check the files rather than just looking at the email). When you receive the submitted assignment you can check one last time to make sure that you fulfilled all the requirements. If you forgot something then you can resend your assignment with a note to mark only the latest submission (but try not to resubmit your assignment too many times please).
 
  1. Include a structure chart: It outlines the functions or procedures that will be implemented in your program as well as the hierarchy of calls (which module calls which). You can work on the structure chart on your own time and during tutorials when you will get some feedback about the direction of the design of your program. If students hand in their structure charts after the specified tutorial (e.g., you hand it in with your paper print outs when you submit your assignment) then you can still get a grade for this component although you obviously won't receive timely feedback to help you with your work. If you are unsure of what a structure chart looks like you can refer to the slides and your in-class notes on problem decomposition / modular design or the image included with the previous assignment. However you must hand in a structure chart along with your paper printouts in order to get credit for this component of the assignment - you can't just quickly show your TA your chart in tutorial because he won't remember it when it comes time to mark your assignment.  (You don't need to submit an electronic version of the structure chart however).

 
  To help make sure that you haven't missed anything here is a checklist of items to be used in marking.

 

Academic Misconduct and collaboration

Assignments must reflect individual work.  Each student must demonstrate that he or she can complete the assignment on their own so you cannot copy the work of other students nor can students work in groups.  Any suspected cases of cheating must be forwarded by me onto the Department Head, which may be passed on further to the Office of the Dean of Science and the Department of Student Services and result in penalties such as failing the course or even expulsion from the university.

A few questions and answers to help clarify things:

Q: What exactly constitutes cheating in this course? 
A: It is probably similar to what you have seen in other courses.  Cheating has occurred if you hand in someone else's work as if it were your own (without crediting the other person).   Furthermore if a student knowingly provides a copy of his or her assignment to another student  then both students are guilty of academic misconduct (the first student helped the second student to cheat).


Q: What happens if you include someone else's code in your assignment submission and you do credit the other person clearly and properly e.g., You use the code from the text book and you include the following citation:  The function listed below displays the list of email contacts for the user and it was taken from the book Pascal Programming & Problem Solving, 4th Edition, Leestma/Nyhoff . 
A: This will not constitute cheating but since someone else did the work for that section of your assignment you won't get credit for it e.g., if you were supposed to get a marks for writing the code to display a list but instead you copied someone else's code (and credited this person) rather than writing it yourself then you wouldn't get credit for the work.
 

Q: What is the difference between getting help from someone vs. cheating?
A: If you describe the process to someone using plain English then you should be okay because then the person still must figure out how to implement your generic ideas in a programming language (both of you are handing in separate submissions). This is because the person must understand the problem sufficiently to solve it on their own. If you simply give your code to a friend then this is not okay, even if your friend says that he or she will only use your solution as a 'guide' in order figure out the answer and 'promises' that he or she won't just copy it into their own program. This is because the person probably will not understand or the solution so he or she has learned nothing.

Okay Not okay
To write a loop that counts from one to ten the following steps must be completed. First a loop control (a variable that stores the values from one to ten) must be initialized to the starting value (in this case it's the number one). Next a check must be performed to ensure that the control includes but does not exceed the last value in the sequence (in this case it's the number ten). Within the body of the loop the current value of the loop control should be displayed onscreen so that the program actually 'counts' out the values onscreen. Finally the loop control must be updated with each pass through the body of the loop.
  i := 1;
  while (i <= 10) do
  begin 
       writeln ('i=', i);
       i := i + 1;
 end;

 

Q: The code that you gave us in lecture or tutorial would be really handy for our assignments, are we allowed to use it and get credit for the work? (You should pay especially close attention to this last point with the assignments in the later part of the term).
A: Yes, unless you are told otherwise you can make use of my sample code (I usually give the TA's the examples to cover in tutorial). Just make sure that you clearly indicate where you got it from in your program documentation as well as indicating which parts of the program come from class. Don't just include it in your code without citing the source (in this case it's me) because you will be claiming that this work is yours when it isn't so you will be guilty of academic misconduct.
 

Q: How do we credit some else's code?
A: Typically each logical block (function, procedure, loop, branch) that you did not write yourself must clearly indicate the source e.g., "The following procedure called "displayMaze" for displaying the contents of the array came from lecture notes by James Tam.

This list of questions only includes things that I thought up as I writing the assignment specifications, if you ever unsure if a particular situation constitutes cheating or not then it is up to you to ask me.