// DOCTORS.H - Class definitions for Doctor Schedule application // This version uses the C++ standard template library. #ifndef DOCTORS_H #define DOCTORS_H #include "root.h" class Doctor; // forward declaration required class Patient; class TimeSlot { public: TimeSlot( const unsigned n = 0 ); unsigned AsInteger() const; // Compare the intValues of two time slots. bool operator <( const TimeSlot & rtOp ) const; bool operator ==( const TimeSlot & rtOp ) const; friend istream & operator >>(istream & inp, TimeSlot & T); friend ostream & operator <<(ostream & os, const TimeSlot & T); private: static unsigned StartHour; static unsigned ApptLen; unsigned intValue; }; class Appointment { public: Appointment(); Appointment ( const TimeSlot & aTime, unsigned docNum, const Patient & P); const string & GetPatientName() const; const TimeSlot & GetTime() const; bool IsScheduled() const; void SetTime( const unsigned n ); // Compar appointments using only their time Slots. bool operator <( const Appointment & rtOp ) const; bool operator ==( const Appointment & rtOp ) const; friend ostream & operator <<( ostream & os, const Appointment & A ); private: enum { NoDoctor = 9999 }; unsigned doctorNum; TimeSlot timeSlot; string patientName; }; class Patient { public: Patient(); void InputName(); unsigned ChooseDoctor() const; TimeSlot ChooseTimeSlot(const Doctor & D) const; const Appointment & GetAppointment() const; const string & GetFirstName() const; const string & GetLastName() const; int IsScheduled() const; void SetAppointment( const Appointment & A ); friend ostream & operator <<( ostream & os, const Patient & P ); private: string lastName; string firstName; Appointment nextVisit; }; class DailySchedule { public: DailySchedule(); int IsTimeSlotFree( const TimeSlot & T ) const; void SetAppointment( const Appointment & A ); void ShowAppointments( ostream & os ) const; friend ostream & operator <<( ostream & os, const DailySchedule & DS ); private: enum { MaxTimeSlots = 40 }; vector appointments; // Appointment appointments[MaxTimeSlots]; }; class Doctor { public: Doctor(); int AddToSchedule( const Appointment & A ); // Try to schedule an appointment. Return 1 (true) if // successful, 0 (false) if not. const DailySchedule & GetSchedule() const; void SetId( const unsigned ); void SetLastName( const string & L ); const string & GetLastName() const; void ShowAppointments( ostream & ) const; // Operations required by the vector class, for comparing // Doctor objects; not implemented yet. bool operator <(const Doctor & rtOp) const { return false; } bool operator ==(const Doctor & rtOp) const { return false; } static const string & GetDoctorName( unsigned id ); static const vector & GetDoctorNames(); static void AddDoctorName( const string & aName ); private: unsigned id; string lastName; DailySchedule schedule; static vector doctorNames; }; class Scheduler { public: Scheduler( vector & docs ); void PrintAllAppointments( const char * fileName ); int ScheduleOneAppointment(); void ScheduleAllAppointments(); private: vector & doctors; // reference to array of doctors }; //............. Inline functions .................. inline TimeSlot::TimeSlot( const unsigned n ) { intValue = n; } inline unsigned TimeSlot::AsInteger() const { return intValue; } inline const DailySchedule & Doctor::GetSchedule() const { return schedule; } inline void Doctor::SetId( const unsigned n ) { id = n; } inline void Doctor::SetLastName( const string & aName ) { lastName = aName; } inline const string & Doctor::GetLastName() const { return lastName; } inline const string & Doctor::GetDoctorName( unsigned id ) { return (const string &) doctorNames[id]; } inline const vector & Doctor::GetDoctorNames() { return doctorNames; } inline void Doctor::AddDoctorName( const string & aName ) { doctorNames.push_back( aName ); } inline const string & Appointment::GetPatientName() const { return patientName; } inline bool Appointment::IsScheduled() const { return doctorNum != NoDoctor; } inline void Appointment::SetTime( const unsigned n ) { timeSlot = n; } inline const TimeSlot & Appointment::GetTime() const { return timeSlot; } inline const string & Patient::GetFirstName() const { return firstName; } inline const string & Patient::GetLastName() const { return lastName; } inline Appointment::Appointment() { doctorNum = NoDoctor; } inline const Appointment & Patient::GetAppointment() const { return nextVisit; } inline Patient::Patient() { } inline void Patient::SetAppointment( const Appointment & app ) { nextVisit = app; } inline int Patient::IsScheduled() const { return nextVisit.IsScheduled(); } #endif