CMPT 212 Assignment 1
Fall 1997 ------------
Due date: Start of class, Wednesday, October 1, 1997.
1. Goal
- To become familiar with C++ header files and separate compilation.
- To become familiar with pointers and dynamic memory allocation
and release.
- To become familiar with the Borland C++ IDE.
2. Overview
- The program will be a simple program to store and retrieve
information about people. In future assignments, you will be
adding more features to the program and using more sophisticated
programming techniques.
3. Description
3.1 General
- The program will be a text-based, menu-driven program.
- The program will maintain a list 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 three functions:
a. Add a person to the end of the list.
b. Display the list.
c. Empty the list.
3.2 Main Menu
- The menu will look exactly like this:
1. Add person
2. Print list
3. Empty list
4. 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.
- This information about the person will be added to the end
of the list.
3.4 "Print List" Operation
- When the user presses "2" at the Main Menu, the program
will display the contents of the list on the screen.
- For each person in the list, the information displayed
will look exactly like this:
First name:
Last name:
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 the list.
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 the data types and functions to manipulate
the information about a person.
- The source files for this module will be called "person.h" and
"person.cpp".
- This module contains these publicly-available data types and
functions:
a. the structure which holds the information about a
person,
b. a function called "readPerson" which prompts the user
to enter information about a person, then reads the
input into a "person" structure,
c. a function called "printPerson" which displays the
information about a person on the screen.
4.3 The Person-List Module
- This module defines the data types and functions to manipulate
a list of information about people.
- The source files for this module will be called "plist.h" and
"plist.cpp".
- This module contains these publicly-available data types and
functions:
a. a function called "addToEnd" which adds a given person
to the end of the list,
b. a function called "getFirst" which returns the first
person in the list,
c. a function called "getNext" which returns the next
person in the list,
d. a function called "atEnd" which determines if the end
of the list has been reached,
e. a function called "clearList" which removes every person
from the list.
4.4 The Main Module
- The source file for this module will be called "asgn1.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
- The header file (plist.h) for the Person-List module is given
to you. You must use it. You must not change it.
- plist.h will be sent out by email, and it will be available
in the Assignment Lab and on the class web pages.
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".
- There will be only one list in the program, and it must not
be publicly available. The only functions which are allowed
to operate on the list are the functions in the Person-List
module.
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.
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.
5.7 Miscellaneous
- Use "const" wherever possible.
- Use referenes ("&") when appropriate. Pass all structures
by reference.
- Do not define any classes for this assignment.
- 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 these two tests of the program:
a. Start, Print list, Quit.
b. Start, Enter 3 people, Print list, Empty List, Print list,
Enter 1 person, Print List, Quit.
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. main.cpp
b. person.h
c. person.cpp
d. plist.h
e. plist.cpp
f. bool.h (if written -- see Section 5.5 above)
- Scripts of the two test runs (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)