Implement in C Create a class named Doctor that has three me
Implement in C++
Create a class named Doctor that has three member variables:
name – A string that stores the name of the doctor
numPatients – An integer that tracks how many patients the doctor must treat
patientList – A dynamic array of strings used to store the patient names
Write appropriate constructor(s), mutator, and accessor methods for the Doctor class along with the following:
A method that inputs all values from the user, including the list of patient names. Note that this method has to support input for an arbitrary number of patient.
A method that outputs the names in the list of all patients.
A method that resets the number of patient to 0 and the patientList to an empty list.
An overloaded assignment operator that correctly makes a new copy of a Doctor object with the list of patients.
A destructor that releases all memory that has been allocated.
Create a class named HeartSurgeon that is derived from the Doctor class with public inheritance. In addition to the variables it inherits from the Doctor class, it also has the following variables:
numSurgeriesScheduled – An integer that tracks how many heart surgeries the doctor is scheduled
surgerySchedule – A dynamic array of objects used to store the patient names and the dates of the heart surgery. Define the appropriate new class for surgerySchedule objects.
Write appropriate constructor(s), mutator, and accessor methods for the HeartSurgeon class along with the following:
A method that inputs all values from the user, including the list of patient names and surgery schedules. Note that this method has to support input for an arbitrary number of patients and surgeries.
A method that outputs the names in the list of all patients and surgeries scheduled.
A method that resets the number of patient to 0 and the patientList to an empty list.
A method that resets the number of surgery scheduled to 0 and the surgerySchedule to an empty list.
An overloaded assignment operator that correctly makes a new copy of a HeartSurgeon object with the list of patients and the list of surgeries scheduled.
A destructor that releases all memory that has been allocated. Write a main method that tests (i.e., unit testing) all of your functions in both the Doctor and HeartSurgeon classes.
Solution
main.cpp
#include \"Doctor.h\"
#include \"HeartSurgeon.h\"
#include <iostream>
#include <string>
#include <stdlib.h>
//#define UNIT_TESTING
using namespace std;
int main()
{
#ifdef UNIT_TESTING
cout << \"Unit testing!\" << endl;
Doctor doc;
doc.setName(\"Doctor Bob\");
cout << \"Doctor\'s name (Doctor Bob): \" << doc.getName() << endl;
string *patients = new string[2];
patients[0] = \"Jim\";
patients[1] = \"Jane\";
doc.setPatientList(patients);
doc.setNumPatients(2);
cout << \"Patient Number (2): \" << doc.getNumPatients() << endl;
cout << \"Patients (Jim, Jane):\ \ \";
doc.displayInfo();
doc.reset();
cout << \"RESET\ \ Patient Number (0): \" << doc.getNumPatients() << endl;
cout << \"Patients (): \";
doc.displayInfo();
HeartSurgeon hDoc;
hDoc.setName(\"HeartSurgeon Bob\");
cout << \"HeartSurgeon\'s name (HeartSurgeon Bob): \" << hDoc.getName() << endl;
string *Hpatients = new string[2];
Hpatients[0] = \"Jim\";
Hpatients[1] = \"Jane\";
hDoc.setPatientList(Hpatients);
hDoc.setNumPatients(2);
Surgery *surgeries = new Surgery[1], surgery;
surgery.setName(\"Jim\");
surgery.setType(\"Heart Translpant\");
surgeries[0] = surgery;
hDoc.setSurgerySchedule(surgeries);
hDoc.setNumSurgeriesScheduled(1);
cout << \"Patient Number (2): \" << hDoc.getNumPatients() << endl;
cout << \"Patients/Surgeries (Jim, Jane)(Jim - Heart Transplant):\ \ \";
hDoc.displayInfo();
hDoc.reset();
cout << \"RESET\ \ Patient Number (0): \" << hDoc.getNumPatients() << endl;
cout << \"Patients/Surgeries ()(): \";
hDoc.displayInfo();
#else
Doctor doc;
doc.getInfo();
doc.displayInfo();
HeartSurgeon hDoc;
hDoc.getInfo();
hDoc.displayInfo();
#endif
exit(EXIT_SUCCESS);
return 0;
}
Doctor.h
#ifndef DOCTOR_H
#define DOCTOR_H
#include <string>
#include <vector>
#include <iostream>
using namespace std;
class Doctor
{
public:
Doctor();
virtual ~Doctor();
Doctor(const Doctor&);
string getName();
void setName(string);
int getNumPatients();
void setNumPatients(int);
string* getPatientList();
void setPatientList(string*);
void getInfo();
void displayInfo();
void reset();
Doctor& operator= (const Doctor&);
protected:
string name;
int numPatients;
string *patientList;
};
#endif // DOCTOR_H
HeartSurgeon.cpp
#include \"HeartSurgeon.h\"
HeartSurgeon::HeartSurgeon()
{
Doctor::Doctor();
surgerySchedule = new Surgery[1];
surgerySchedule[0] = Surgery();
numSurgeriesScheduled = 0;
}
HeartSurgeon::HeartSurgeon(const HeartSurgeon &docIn)
{
setName(docIn.name);
setNumPatients(docIn.numPatients);
setPatientList(docIn.patientList);
setNumSurgeriesScheduled(docIn.numSurgeriesScheduled);
setSurgerySchedule(docIn.surgerySchedule);
}
HeartSurgeon& HeartSurgeon::operator= (const HeartSurgeon& docIn)
{
setName(docIn.name);
setNumPatients(docIn.numPatients);
setPatientList(docIn.patientList);
setNumSurgeriesScheduled(docIn.numSurgeriesScheduled);
setSurgerySchedule(docIn.surgerySchedule);
return *this;
}
HeartSurgeon::~HeartSurgeon()
{
delete &name;
delete &numPatients;
delete [] patientList;
patientList = NULL;
delete [] surgerySchedule;
surgerySchedule = NULL;
}
void HeartSurgeon::getInfo()
{
vector<Surgery> surgeries;
vector<Surgery>::iterator surItr;
string in = \"\";
int i;
Surgery surgery;
cout << \"\ \ Enter Scheduled Surgeries, by patient name (enter \'$\' when finished): \";
getline(cin, in);
while (in.compare(\"$\") != 0)
{
surgery.setName(in);
cout << \"\\tEnter Surgery Type: \";
getline(cin, in);
surgery.setType(in);
surgeries.push_back(surgery);
cout << \"\ \ Enter Next Patient: \";
getline(cin, in);
}
numSurgeriesScheduled = surgeries.size();
delete [] surgerySchedule;
surgerySchedule = new Surgery[numSurgeriesScheduled];
i = 0;
for (surItr = surgeries.begin(); surItr < surgeries.end(); surItr++)
{
surgerySchedule[i] = *surItr;
i++;
}
}
void HeartSurgeon::displayInfo()
{
int i;
cout << \"Patients:\";
for (i = 0; i < numPatients; i++)
{
cout << endl << patientList[i];
}
cout << \"Surgeries:\";
for (i = 0; i < numSurgeriesScheduled; i++)
{
surgerySchedule[i].print();
}
cout << endl;
}
void HeartSurgeon::reset()
{
numPatients = 0;
delete [] patientList;
patientList = NULL;
numSurgeriesScheduled = 0;
delete [] surgerySchedule;
surgerySchedule = NULL;
}
int HeartSurgeon::getNumSurgeriesScheduled()
{
return numSurgeriesScheduled;
}
void HeartSurgeon::setNumSurgeriesScheduled(int numIn)
{
numSurgeriesScheduled = numIn;
}
Surgery* HeartSurgeon::getSurgerySchedule()
{
return surgerySchedule;
}
void HeartSurgeon::setSurgerySchedule(Surgery* scheduleIn)
{
surgerySchedule = scheduleIn;
}
HeartSurgeon.h
#ifndef HEARTSURGEON_H
#define HEARTSURGEON_H
#include \"Doctor.h\"
#include \"Surgery.h\"
class HeartSurgeon : public Doctor
{
public:
HeartSurgeon();
HeartSurgeon(const HeartSurgeon&);
virtual ~HeartSurgeon();
int getNumSurgeriesScheduled();
void setNumSurgeriesScheduled(int);
Surgery* getSurgerySchedule();
void setSurgerySchedule(Surgery*);
void getInfo();
void displayInfo();
void reset();
HeartSurgeon& operator=(const HeartSurgeon&);
private:
int numSurgeriesScheduled;
Surgery *surgerySchedule;
};
#endif // HEARTSURGEON_H
Surgery.cpp
#include \"Surgery.h\"
Surgery::Surgery()
{
//ctor
}
Surgery::Surgery(string nameIn)
{
setName(nameIn);
}
Surgery::~Surgery()
{
delete &patientName;
delete &type;
}
string Surgery::getName()
{
return patientName;
}
void Surgery::setName(string nameIn)
{
patientName = nameIn;
}
string Surgery::getType()
{
return type;
}
void Surgery::setType(string typeIn)
{
type = typeIn;
}
void Surgery::print()
{
cout <<\"\ \ Patient: \" << patientName;
cout << \"\ \ Surgery Type: \" << type;
}
Surgery.h
#ifndef SURGERY_H
#define SURGERY_H
#include <string>
#include <iostream>
using namespace std;
class Surgery
{
public:
Surgery();
Surgery(string);
virtual ~Surgery();
string getName();
void setName(string);
string getType();
void setType(string);
void print();
private:
string patientName;
string type;
};
#endif // SURGERY_H
HeartSurgeon.cpp
#include \"HeartSurgeon.h\"
#include \"Doctor.h\"
HeartSurgeon::HeartSurgeon()
{
// Doctor::Doctor();
surgerySchedule = new Surgery[1];
surgerySchedule[0] = Surgery();
numSurgeriesScheduled = 0;
}
HeartSurgeon::HeartSurgeon(const HeartSurgeon &docIn)
{
setName(docIn.name);
setNumPatients(docIn.numPatients);
setPatientList(docIn.patientList);
setNumSurgeriesScheduled(docIn.numSurgeriesScheduled);
setSurgerySchedule(docIn.surgerySchedule);
}
HeartSurgeon& HeartSurgeon::operator= (const HeartSurgeon& docIn)
{
setName(docIn.name);
setNumPatients(docIn.numPatients);
setPatientList(docIn.patientList);
setNumSurgeriesScheduled(docIn.numSurgeriesScheduled);
setSurgerySchedule(docIn.surgerySchedule);
return *this;
}
HeartSurgeon::~HeartSurgeon()
{
delete &name;
delete &numPatients;
delete [] patientList;
patientList = NULL;
delete [] surgerySchedule;
surgerySchedule = NULL;
}
void HeartSurgeon::getInfo()
{
vector<Surgery> surgeries;
vector<Surgery>::iterator surItr;
string in = \"\";
int i;
Surgery surgery;
cout << \"\ \ Enter Scheduled Surgeries, by patient name (enter \'$\' when finished): \";
getline(cin, in);
while (in.compare(\"$\") != 0)
{
surgery.setName(in);
cout << \"\\tEnter Surgery Type: \";
getline(cin, in);
surgery.setType(in);
surgeries.push_back(surgery);
cout << \"\ \ Enter Next Patient: \";
getline(cin, in);
}
numSurgeriesScheduled = surgeries.size();
delete [] surgerySchedule;
surgerySchedule = new Surgery[numSurgeriesScheduled];
i = 0;
for (surItr = surgeries.begin(); surItr < surgeries.end(); surItr++)
{
surgerySchedule[i] = *surItr;
i++;
}
}
void HeartSurgeon::displayInfo()
{
int i;
cout << \"Patients:\";
for (i = 0; i < numPatients; i++)
{
cout << endl << patientList[i];
}
cout << \"Surgeries:\";
for (i = 0; i < numSurgeriesScheduled; i++)
{
surgerySchedule[i].print();
}
cout << endl;
}
void HeartSurgeon::reset()
{
numPatients = 0;
delete [] patientList;
patientList = NULL;
numSurgeriesScheduled = 0;
delete [] surgerySchedule;
surgerySchedule = NULL;
}
int HeartSurgeon::getNumSurgeriesScheduled()
{
return numSurgeriesScheduled;
}
void HeartSurgeon::setNumSurgeriesScheduled(int numIn)
{
numSurgeriesScheduled = numIn;
}
Surgery* HeartSurgeon::getSurgerySchedule()
{
return surgerySchedule;
}
void HeartSurgeon::setSurgerySchedule(Surgery* scheduleIn)
{
surgerySchedule = scheduleIn;
}
Doctor.cpp
#include \"Doctor.h\"
#include \"HeartSurgeon.h\"
Doctor::Doctor()
{
patientList = new string[1];
numPatients = 0;
}
Doctor::Doctor(const Doctor &docIn)
{
setName(docIn.name);
setNumPatients(docIn.numPatients);
setPatientList(docIn.patientList);
}
Doctor& Doctor::operator= (const Doctor& docIn)
{
setName(docIn.name);
setNumPatients(docIn.numPatients);
setPatientList(docIn.patientList);
return *this;
}
Doctor::~Doctor()
{
delete &name;
delete &numPatients;
delete [] patientList;
patientList = NULL;
}
void Doctor::getInfo()
{
vector<string> patients;
vector<string>::iterator itr;
string in = \"\";
int i;
cout << \"\ \ Enter Doctor name: \";
getline(cin, name);
cout << \"\ \ Enter Patient Names, one at a time (enter \'$\' when finished): \";
getline(cin, in);
while (in.compare(\"$\") != 0)
{
patients.push_back(in);
getline(cin, in);
}
numPatients = patients.size();
delete [] patientList;
patientList = new string[numPatients];
i = 0;
for (itr = patients.begin(); itr < patients.end(); itr++)
{
patientList[i] = *itr;
i++;
}
}
void Doctor::displayInfo()
{
cout << \"Patients:\";
for (int i = 0; i < numPatients; i++)
{
cout << endl << patientList[i];
}
cout << endl;
}
void Doctor::reset()
{
if (numPatients > 0)
{
numPatients = 0;
delete [] patientList;
patientList = NULL;
}
}
string Doctor::getName()
{
return name;
}
void Doctor::setName(string nameIn)
{
name = nameIn;
}
int Doctor::getNumPatients()
{
return numPatients;
}
void Doctor::setNumPatients(int numIn)
{
numPatients = numIn;
}
string* Doctor::getPatientList()
{
return patientList;
}
void Doctor::setPatientList(string* listIn)
{
patientList = listIn;
}









