Give the definition of a class named Doctor whose objects are records for a clinic’s doctors. This class will be a derived class of the class SalariedEmployee given in Display 14.4. A Doctor record has the doctor’s specialty (such as Pediatrician, Obstetrician, General Practitioner, etc., so use type string), and office visit fee (use type double). Be sure your class has a reasonable complement of constructors and accessor methods, an overloaded assignment operator, and a copy constructor. Write a driver program to test all your methods.
Complete Program:
NOTE: Please refer the textbook for salariedemployee.h, salariedemployee.cpp, employee.h, and employee.cpp files.
// File doctor.h
#ifndef DOCTOR_H
#define DOCTOR_H
#include <string>
#include "salariedemployee.h"
using std::string;
namespace SavitchEmployees
{
class Doctor : public SalariedEmployee
{
public:
// constructors
Doctor();
Doctor(const string& theName, const string& theSsn,
double theAnnualSalary, const string& theSpecility,
double theOfficeVisitFee);
// copy constructor
Doctor(const Doctor& otherObject);
// overloaded assignment operator
Doctor& operator=(const Doctor& otherObject);
// accessors
string getSpecialty();
double getOfficeVisitFee();
// mutators
void setSpecialty(const string& theSpecility);
void setOfficeVisitFee(double theOfficeVisitFee);
// print function
void print();
private:
string specialty;
double officeVisitFee;
};
}
#endif
// File doctor.cpp
#include <string>
#include <iostream>
#include "doctor.h"
using std::string;
using std::cout;
using std::endl;
namespace SavitchEmployees
{
Doctor::Doctor() : SalariedEmployee(), specialty("No specialty yet"), officeVisitFee(0)
{
// deliberately empty
}
Doctor::Doctor(const string& theName, const string& theSsn, double theAnnualSalary,
const string& theSpecility, double theOfficeVisitFee)
: SalariedEmployee(theName, theSsn, theAnnualSalary),
specialty(theSpecility), officeVisitFee(theOfficeVisitFee)
{
// deliberately empty
}
Doctor::Doctor(const Doctor& otherObject)
: SalariedEmployee(otherObject.getName(), otherObject.getSsn(),
otherObject.getSalary()), specialty(otherObject.specialty),
officeVisitFee(otherObject.officeVisitFee)
{
// deliberately empty
}
Doctor& Doctor::operator=(const Doctor& otherObject)
{
setName(otherObject.getName());
setSsn(otherObject.getSsn());
setSalary(otherObject.getSalary());
specialty = otherObject.specialty;
officeVisitFee = otherObject.officeVisitFee;
return *this;
}
string Doctor::getSpecialty()
{
return specialty;
}
double Doctor::getOfficeVisitFee()
{
return officeVisitFee;
}
void Doctor::setSpecialty(const string& theSpecility)
{
specialty = theSpecility;
}
void Doctor::setOfficeVisitFee(double theOfficeVisitFee)
{
officeVisitFee = theOfficeVisitFee;
}
void Doctor::print()
{
cout << "Doctor's name: " << getName() << endl;
cout << "Doctor's SSN: " << getSsn() << endl;
cout << "Doctor's salary: $" << getSalary() << endl;
cout << "Doctor's specialty: $" << specialty << endl;
cout << "Doctor's office visit fee: $" << officeVisitFee << endl;
}
}
// File: main.cpp
#include <iostream>
#include "doctor.h"
using SavitchEmployees::Doctor;
using std::cout;
using std::endl;
int main()
{
Doctor doc1("Mr. John Smith", "963-85-2741", 10000.00, "General Practitioner", 50);
Doctor doc2("Mr. Charles Chars", "789-45-6123", 9500.00, "Obstetrician", 45);
Doctor doc3(doc1);
Doctor doc4 = doc2;
cout << "Details of Doctor #1..." << endl;
doc1.print();
cout << "\nDetails of Doctor #2..." << endl;
doc2.print();
cout << "\nDetails of Doctor #3..." << endl;
doc3.print();
cout << "\nDetails of Doctor #4..." << endl;
doc4.print();
return 0;
}
Sample Output: