CMPT 212 Assignment 2

David Simpson (simpson@cs.sfu.ca)
Fri, 3 Oct 1997 15:16:55 -0700 (PDT)


CMPT 212                      Assignment 2
Fall 1997                     ------------


Due date:  Start of class, Friday, October 17, 1997.


1. Goal

   - To become familiar with classes, constructors, destructors,
       and other operators on classes.

2. Overview

   - This program extends Assignment 1 to include classes.
   - A class will be defined to store information about a person,
       and another class will implement a linked list.
   - As a result, the program will support more than one list.
   - From a user's perspective, the program will appear to be very
       much like the Assignment 1 program, except that it will have
       two lists of people.

3. Description

   3.1 General
       - The program will be a text-based, menu-driven program.
       - The program will maintain two lists of people.  For each person,
          the person's first name, the person's last name, and the person's
          age will be kept.
       - The program will have four functions:
            a.  Add a person to the end of a list.
            b.  Display a list.
            c.  Empty a list.
	    d.  Copy the first list to the second list.
       - The first three functions (Add, Display, and Empty) are the
	  same as those in Assignment 1, except that they will ask
	  the user which list to operate on.
  
   3.2 Main Menu
      - The menu will look exactly like this:

              1.  Add person
              2.  Print list
              3.  Empty list
	      4.  Copy list 1 to list 2
              5.  Quit
 
              > _

          (The "_" is the cursor, waiting for the user's input.)
      - When the user enters a choice, the program will carry out
          the operation selected by the user.
      - After the operation has been carried out, the program will
          display the Main Menu and wait for the user to enter 
          another choice.  (If the user selects "Quit", the program
          will quit instead of displaying the Main Menu.)
   
   3.3 "Add Person" Operation
      - When the user presses "1" at the Main Menu, the program
          will prompt the user to enter the person's first name,
          the person's last name, and the person's age.
      - The user will also be asked which list (1 or 2) to add to.
      - This information about the person will be added to the end
          of the chosen list.

   3.4 "Print List" Operation
      - When the user presses "2" at the Main Menu, the program
          will display the contents of a list on the screen.
      - The user will be asked which list (1 or 2) to display
      - For each person in the chosen list, the information displayed
          will look exactly like this:
               First name:  <first name> 
               Last name:   <last name>
               Age:         <age>
      - After the list has been displayed (whether the list is
          empty or not), this message will be displayed:
              "There are X people in the list."
          where X is the number of people in the list.

   3.5 "Empty List" Operation
      - When the user presses "3" at the Main Menu, the program
          will remove every person from a list.
      - The user will be asked which list (1 or 2) to empty.
  
   3.5 "Copy List" Operation
      - When the user presses "4" at the Main Menu, the program
	  will empty list 2, then copy every person from list 1
	  into list 2.

   3.6 "Quit" Operation
      - When the user presses "4" at the Main Menu, the program
          will exit.

4. Design of the Program

   4.1 Modules
      - The program will consist of three modules: a "Person" module,
          a "Person List" module, and "Main" module.
 
   4.2 The Person Module
      - This module defines a class called "person" which contains
	  the information about a person and the operations which
	  can be performed on a person.
      - The source files for this module will be called "person.h" and
          "person.cpp".
      - The "person" class must have these member functions:
	   - a default constructor
	   - a copy constructor
	   - an assignment operator
      - The input (>>) and output (<<) operators must be overloaded
	  so that instances of the "person" class can be inputted
	  and outputted.
           
   4.3 The Person-List Module
      - This module defines a class called "plist" which models a
	  list of people.
      - The source files for this module will be called "plist.h" and
          "plist.cpp".
      - The "plist" class must have these member functions:
	   - a default constructor
	   - a copy constructor
	   - a destructor
	   - an assignment operator
	   - an "addToEnd" function (same parameters and return value
	       as in Assignment 1)
	   - a "getFirst" function (same parameters and return value
	       as in Assignment 1)
	   - a "getNext" function (same parameters and return value
	       as in Assignment 1)
	   - an "atEnd" function (same parameters and return value
	       as in Assignment 1)
	   - a "clearList" function (same parameters and return value
	       as in Assignment 1)
      - The output (<<) operator must be overloaded so that instances 
	  of the "plist" class can be outputted.  You do not need
	  an input operator for "plist".

   4.4 The Main Module
      - The source file for this module will be called "asgn2.cpp".
      - This modules contains the main function of the program.

5. Design Features

   5.1 Error Checking
      - Very little error checking needs to be done.
      - The program does not have to check for out-of-memory errors
          or input errors.
  
   5.2 Given Code
      - No code is given to you.  
      - This program is based on Assignment 1.  If you prefer, you
	  may base your program on my solution to Assignment 1, rather
	  than on your solution to Assignment 1.

   5.3 List Implementation
      - The elements in the list must be allocated using the memory
          allocation operator "new", and must be released using the
          memory release operator "delete".

   5.4 Constants
      - The maximum length of a person's first name and the maximum
          length of a person's last name must be defined as constants
          in the program.  Each of these constants must be defined in 
          one location so that it can be changed easily.
          You may use a constant of 20 for the lengths of the names.

   5.5 Bool Type
      - If you are using a compiler which does not support the "bool"
          type, you must define the "bool" type yourself in a header
          file called "bool.h".  Your program must be able to compile
          without errors under the Borland C++ in the Assignment Lab. 

   5.6 I/O
      - All input and output must be done using the ">>" and "<<"
          operators.
      - When inputting a person, you must use the ">>" operator
	  for the "person" class.  
      - When outputting a person, you must use the "<<" operator
	  for the "person" class.  
      - When outputting a list of people, you must use the "<<" 
	  operator for the "plist" class.  

   5.7 Miscellaneous
      - Use "const" wherever possible.
      - Use referenes ("&") when appropriate.  Pass all structures
	  and class instances by reference.
      - Use the smallest scope and lifetime for every variable, 
          constant, and function.  

6. Source Code Comments
   - Your source code must be fully commented.
   - An example of good commenting style is shown in plist.h.

7. Test Runs
   - Run this test of the program:
	   Print list 1
	   Print list 2
	   Add one person to list 1
           Print list 1
	   Print list 2
	   Add one person to list 1
	   Print list 1
	   Print list 2
	   Add one person to list 2
	   Print list 1
	   Print list 2
	   Copy list 1 to list 2
	   Print list 1
	   Print list 2
	   Empty list 1
	   Print list 1
	   Print list 2
	   Copy list 1 to list 2
	   Print list 1
	   Print list 2
	   Add one person to list 2
	   Print list 1
	   Print list 2

8. What to Hand In
   - Title page containing: 
        a. Course number
        b. Assignment number
        c. Student name
        d. Student number
        e. Student email address
   - Listing of the source code in this order:
        a. asgn2.cpp
        b. person.h
        c. person.cpp
        d. plist.h
        e. plist.cpp
        f. bool.h  (if written -- see Section 5.5 above)
   - Script of the test run (see Section 7 above).

9. Marking
   - Besides the usual reasons for deducting marks (such as not
       handing in all of your code, or your program doesn't work
       completely), marks may be deducted for these reasons:
         - bad coding style
         - inconsistent coding style
         - bad commenting style
         - code which is difficult to understand
         - poor variable/constant/function names
	 - failing to meet the requirements described here

10. Ammendments to this Assignment
   - Ammendments to this assignment may be emailed or posted on the
       web page.  Ammendments may be made to correct errors here
       or to clarify points.  Check your email regularly.


(end of assignment)