free geoip

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Constructor for Composition of inherited classin c++ 2011
VU Help • House Banner VU Help Virtual University Students - Assignments, Solved Papers, GDB & Exam Help Student Help Forum • Collaborative • Free Support
#1
Code:
#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; }

0300-9520262
Get solution in 24 hour
|cpmputer & internetConfusedmileys81:[SIZE="4"][SIZE="3"]....[/SIZE][/SIZE]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  array project code c++ 2011 Vuhelper 0 1,306 12-10-2011, 06:32 PM
Last Post: Vuhelper
  factorial in C++ code 2011 Vuhelper 0 979 12-10-2011, 06:31 PM
Last Post: Vuhelper
  Is constructor necessory in c++? And if than why? Vuhelper 0 1,941 11-05-2011, 05:12 PM
Last Post: Vuhelper
  stack during function call in C++ 2011 Vuhelper 0 2,056 11-05-2011, 05:05 PM
Last Post: Vuhelper
  What is the Thing Queue? in c++ 2011 Vuhelper 0 1,809 11-05-2011, 05:02 PM
Last Post: Vuhelper
  ASCII to char conversion code in C++ 2011 Vuhelper 0 1,749 11-05-2011, 05:01 PM
Last Post: Vuhelper
  How to write a summation in a sequence? C++ 2011-12 Vuhelper 2 1,391 09-19-2011, 04:53 AM
Last Post: Xpert
  GetPixel problem in c++ 2011-12 Vuhelper 0 2,530 09-18-2011, 07:12 PM
Last Post: Vuhelper
  C++ with loop code 2011-12 Vuhelper 0 1,009 09-18-2011, 07:09 PM
Last Post: Vuhelper
  how can i read the last letter of a input file? 2011 Vuhelper 0 1,857 09-12-2011, 10:24 PM
Last Post: Vuhelper

Forum Jump:


Users browsing this thread: 1 Guest(s)
VU Help • House Banner VU Help Virtual University Students - Assignments, Solved Papers, GDB & Exam Help Student Help Forum • Collaborative • Free Support