CS 250 Computer Programming and Problem Solving - FALL 1998 

[ Home | Syllabus | Notes | Glossary | CS250 WEB Version Home Page ]


 

Object Oriented Design:

Case Study: Doctor Scheduling

Version 3:


rainbow.gif (2251 bytes)

void Scheduler::ScheduleAllAppointments()
// schedules appointments until the day is over
{
   while( ScheduleOneAppointment() ) //high level loop
      continue;
}



bool Scheduler::ScheduleOneAppointment()
// Choose a doctor, input patient name, and
// ask for a particular time slot. Make the
// appointment, and display the results.
{
   Name aPatient; // probably should be a real object
   cin >> aPatient;
   int doctorNum = ChooseDoctor(); // private function to simplify
   Doctor & theDoc = doctors[doctorNum];
	
   ChooseTimeSlot( theDoc, aPatient ); // private function to simplify
   return getYN("Continue?"); // ask if end of day
}

//### private member functions of the Scheduler (see updated specification file)
// Show patient list of doctor's names and let patient choose one.
// Display list of doctor names and numbers. Let user
// enter a number, and return this as the function result.

int Scheduler::ChooseDoctor() const
{
   int n = 0;
   cout << "Please choose one of the following doctor's by number:\n";
   for(int i = 0; i < NumDoctors; i++) {
      cout << i+1 << ": " << doctors[i].GetName() << endl; // what is type? what needed?
   }
   do {
      cin >> n;
      n = n - 1; // adjust to array indices
      cin.ignore(255,'\n');
   } while((n < 0) || (n > NumDoctors)); hptrd_left.gif (955 bytes)

   return n;
}


void Scheduler::ChooseTimeSlot( Doctor & D,const Name & patient )
{
   int time;
   cout << '\n'
  	<< "Daily Schedule of Dr. " << D.GetName() << '\n'
	<< "........................................" << '\n'
	<< D.GetSchedule() << '\n';
   do {
      cout << "Enter a time (format hh:mm): ";
      time = GetTime(cin);
   } while(!D.AddToSchedule(patient,time));
}

rainbow.gif (2251 bytes)

rainbow.gif (2251 bytes)

class Scheduler {
public:
  Scheduler( Doctor * docs, int NumDoctors);
  void PrintAllAppointments( const char * fileName );
  bool ScheduleOneAppointment();
  void ScheduleAllAppointments();

private:
  Doctor * doctors;  // points to first element in array of doctors
  int NumDoctors; // keeps size of array of Doctors
  int ChooseDoctor() const;
  void ChooseTimeSlot(Doctor & theDoc, const Name & patient)const;
};

rainbow.gif (2251 bytes)


Copyright chris wild 1998.
For problems or questions regarding this website contact [Chris Wild (e-mail:wild@cs.odu.edu].
Last updated: October 05, 1998.