Date: Mon, 11 Nov 1996 17:12:54 GMT
Server: NCSA/1.5
Content-type: text/html
Last-modified: Mon, 04 Nov 1996 18:34:52 GMT
Content-length: 8486
Program 6 - CS 302 Fall 1996 - Section 4
Algebraic Language Programming in C++
Instructor:
Milo M. Martin
(milo@cs.wisc.edu)
Program 6
Due Friday, November 8, 1996
Objective: Give the student practice with classes and emumerations.
Update - November 4, 1996
You are required to use a project and separate compilation for this
project. See the page Using
Projects for the details.
Program Description
The phone service 1-800-DOCTORS has decided to expand their business.
In addition to their usual service of finding doctors, they will now find
people dentists and hair dressers as well, and even make the appointments
for them. They need to be able to save all of this information, though,
and everyone is sick and tired of writing stuff down on paper and killing
trees. Obviously, the information needs to be stored in a computer.
Believe it or not, this is where you come in.
You need to write a program that will fill up to three appointments at the
users request (doctor, dentist, hair). For each appointment it should
first ask the user if they want to make that particular appointment. If
they do, you should then ask for the relevent time information (month,
day, hour, minute). After all appointments have been made, you should
print out the user's appointments, with the time either in military or
standard format (you should ask which they want for each).
A typical run of the program would look something like this:
Do you want to make a doctor's appointment?
Y
Enter the month (1-12): 1
Enter the day of the month (1-30): 15
Enter the hour (0-23): 18
Enter the minute (0-59): 0
Do you want to make a dental appointment?
N
Do you want to make a hair appointment?
Y
Enter the month (1-12): 3
Enter the day of the month (1-30): 13
Enter the hour (0-23): 13
Enter the minute (0-59): 13
Doctor's Appointment:
Military (M) or Standard (S) time?
S
The appointment is on Monday, January 15 at 6:00 PM.
Hair Appointment:
Military (M) or Standard (S) time?
M
The appointment is on Wednesday, March 13 at 13:13.
There are lots of variables needed to store the information for an
appointment. They are as follows:
- the month: the month of the year (JAN, FEB, MAR, ..., DEC --
must be an enumerated type)
- the day of month: the day of the month (to make your life
easier, all months of the year will have 30 days, so this should
be an integer with legal values of 1-30)
- the day of week: the day of the week (MON, TUE, ..., SUN --
must be an enumerated type)
- the hour of day: the hour of the day (appointments are stored
in military time, so this will be an integer between 0 and 23
where the 0th hour is between midnight and 1 AM)
- the minute of hour: the minute of the hour (this is an integer
between 0 and 59 -- THIS CAN NOT BE 60!!!)
- filled: whether or not the data for this appointment has been
set (must be an enumerated boolean type, that is, an
enumerated types with tags true and false)
There are six variables in all. Since we are storing three different
appointments, this would mean 18 variable declarations. Also, it
would be nice if we could have our own set of member functions just
for appointments and be able to protect the appointment data from
other parts of the program. The sane solution to these potential
problems is to define and implement an Appointment class. We will
then not only get away with only three declarations of appointment
objects, but will have a nicely modularized program.
As stated above, you should define an Appointment class. It must contain
the six variables for storing the appointment information. It should also
contain the following method functions:
- Appointment - public
- this is the constructor
- it should initialize filled to false to indicate that the
appointment has not been set yet
- get_day - private
- this function will set the day of week variable based upon the
current month and day of month
- you can assume that January 1 is a Monday and that all months have
exactly 30 days
- since we are dealing with classes, this should not need to have any
formal parameters and should not need to return anything
- read_app - public
- this function will fill all of the necessary appointment information
- it should first prompt for and read from cin the month, day of
month, hour, and minute and make sure that they
all have legitimate values
- the hour should be read in military format
- the month should be read in as an int and then type cast to the month
enumerated type
- it should then set the day of week (by calling get day
-- thus, read_app should not prompt the user for the day
of the week)
- it should then set filled to indicate that the appointment has been set
- is_filled - public
- should return true if the current object's appointment has been set
and false otherwise
- this function is necessary because the filled variable is private
and can not be accessed by the caller
- print_mil_time - private
- this function will print the time in military (24 hour) format
- this should not require any parameters and does not need to return
anything
- print_stan_time - private
- this function will print the time in standard (12 hour) format
- this should not require any parameters and does not need to return
anything
- write_app - public
- this function will write out to cout the appointment information
if the information has been filled in, if not a message should be
displayed which says that no information has been entered yet.
- otherwise it should ask if the user wants the time printed in
military or
standard format and do appropriate error checking (you will
probably want a function to do this)
- it should then print out the day of week, the month, the
day of month
- the entire name of the month should be written, not just the
number
- it should then print the time in the format the user requests (by
calling one of the two private time print functions)
Main should not be able to harm any of the class's data, so all variables
int the class must be made private. The constructor function,
Appointment must be made public (this is a hard and fast rule of
constructors). Also, the functions read_app, write_app, and
is_filled are all called by main and should be made public. No
other functions are needed outside the class and the remaining
functions must therefore remain private.
The main part should be relatively simple. The first thing you need to do
is declare three objects of type appointment. For each appointment, you
should prompt if the user wants to fill that particular appointment (e.g.
doctor's). If so, call read_app to fill the necessary information.
After this is done for all three appointments, you should print out each
appointment that is set (this should be checked by calling
is_filled) in a manner similar to the example.
What To Turn In
As usual, I only want an electronic
submission, printed copy of your source code, and 2 or more test runs
which thoroughly tests your program's features and error checking.
Suggestions/Final Notes
Notice that in both main and within one of the class functions, we have
the need to read in a character for a yes/no type question and do error
checking. This is something that should be done within a function.
Written by Dave Zimmermann (dzimm@cs.wisc.edu)