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

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:

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:


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)