Date: Mon, 11 Nov 1996 17:04:08 GMT
Server: NCSA/1.5
Content-type: text/html
Last-modified: Mon, 11 Nov 1996 06:12:28 GMT
Content-length: 10055
CS 302 Program 6
CS 302 Program 6
Section 10
Due Date: Monday, November 11 (see
program 6 hand-in dates special information)
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)
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 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 functions:
- Appointment (public)
- this is the constructor
- it should initialize filled to false to indicate that the
appointment has not been set yet
- set_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 in 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 set_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
- remember that midnight is 12AM, noon is 12pm.
- write_app (public)
- this function will write out the appointment information
- 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.
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.
When writing a class, it often looks messy to have all of your
preconditions and postconditions in the class definition. What you
can do instead is the following:
- In the class definition, next to the prototypes for each member
function, write a short description (a line or so) of the function.
- Above the function definitions for each member function, write a
more detailed explanation of how the function works. It might be a good
idea to write formal preconditions and postconditions, but if you have
a less formal description which still thoroughly describes what all of
the parameters are, what the function returns, and what the function
does, I'll accept that as well.
As far as organizing your program, my suggestion is to have the enumerated
types, the class definition, and any function prototypes near the top
of the program, follwed by a divider, follwed by the main section
of your code, followed by any auxiliary functions which are not class
member functions, followed by another divider, followed by your
class member function definitions. By a "divider," I mean a comment
something like this:
/**********************************************************************
* *
* Member Functions for Appointment Class *
* *
**********************************************************************/
OR
// ---------------------- APPOINTMENT CLASS -------------------------
// ---------------------- MEMBER FUNCTIONS -------------------------
OR
Any other way you can come up with to visually separate one section of
your program from another.
Extra vertical space in addition to (not in place of) a dividing
line is an excellent idea too.
What To Turn In
As usual, I only want both the electronic submission and the printed copy of
your source code (the .cpp file). Also turn in a printed copy of at least
one sample run of your program which demonstrates that your program works.
Click here to
return to the CS 302 section 10 projects page
Last Modified Wed Nov 6, 1996 by Mike Steele (msteele@cs.wisc.edu)