So its fun when you have questions for hw but neither the teacher nor the textbook show you how to do the HW question. Anyway, I have my base class, a derived class, and class with composition of the derived class. I am not sure how to create the constructor for that. This is what I got but its not right and is regard to the Billing constructor.
#include <iostream>
#include <string>
using namespace std;
class Person
{
protected:
string name;
public:
Person():name(""){cout << "Default Person Constructor" << endl;}
Person(string theName):name(theName){cout << "Parameterized Person Constructor" << endl;}
Person(const Person& theObject);
~Person(){cout << "Person Destructor" << endl;}
string getName() const{return name;}
Person& operator=(const Person& rtSide)
{
string Name;
Name = rtSide.name;
return *this;
}
friend istream& operator >>(istream& inStream, Person& personObject)
{
inStream >> personObject.name;
return inStream;
}
friend ostream& operator <<(ostream& outStream, const Person& personObject)
{
outStream << "Person's name: " << personObject.name << endl;
return outStream;
}
};
class Doctor
{
protected:
string specialty;
double fee;
public:
Doctor():specialty(""), fee(0){cout << "Default Doctor Constructor" << endl;}
Doctor(string Specialty):specialty(Specialty), fee(0){ cout << "Specialty Doctor Constructor" << endl;}
Doctor(double Fee):specialty(0), fee(Fee){cout << "Fee Doctor Constructor" << endl;}
Doctor(string Specialty, double Fee):specialty(Specialty), fee(Fee){cout << "Parameterized Doctor Constructor" << endl;}
~Doctor(){cout << "Doctor Destructor" << endl;}
string getSpecialty() const{return specialty;}
double getFee() const{return fee;}
const Doctor& operator=(const Doctor& rtSide)
{
string Specialty;
double Fee;
Specialty = rtSide.specialty;
Fee = rtSide.fee;
return *this;
}
Doctor(const Doctor& theObject);
friend ostream& operator <<(ostream& outStream, const Doctor& docObject)
{
outStream << "Doctor's Speciality: " << docObject.specialty << endl;
return outStream;
}
};
class Patient: public Person
{
protected:
Doctor phys;
public:
Patient(): Person(), phys(){cout << "Default Patient Constructor" << endl;}
Patient(string Name, string Specialty, double Fee): Person(Name), phys(Specialty, Fee){cout << "Parameterized Patient Constructor" << endl;}
~Patient(){cout << "Patient Destructor" << endl;}
//friend ostream& operator <<(ostream& outStream, const Patient& patObject)
//{
// Doctor::operator<<(outStream, patObject);
// /*outStream << "Doctor's Speciality: " << phys.getSpecialty;*/
// return outStream;
//}
};
class Billing
{
protected:
double amtdue;
Patient pat;
Doctor doc;
public:
Billing(): amtdue(-1.0), pat(), doc(){cout << "Default Billing Constructor" << endl;}
Billing(double Amtdue, string Name, string Specialty, double Fee): amtdue(Amtdue), Patient(Person(Name)), doc(Specialty, Fee){cout << "Parameterized Patient Constructor" << endl;}
~Billing(){cout << "Billing Destructor" << endl;}
};
int main()
{
Doctor z1("Oncologist", 50);
Doctor z2("Pathologist", 100);
Patient x1("Erica", "Oncologist", 50);
Patient x2("Tom", "Pathologist", 100);
Billing y1;
Billing y2;
cout << z1;
cout << z2;
return 0;
}