SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,julia Lobur
Chapter:
Inheritance
Exercise:
Programming Projects
Question:6 | ISBN:9780321531346 | Edition: 7

Question

Give the definition of two classes, Patient and Billing, whose objects are records for a clinic. Patient will be derived from the class

Person given in Programming Project 4. A Patient record has the patient’s name (inherited from the class Person) and primary

physician, of type Doctor defined in Programming Project 3. A Billing object will contain a Patient object, a Doctor object, and an

amount due of type double. Be sure your classes have a reasonable complement of constructors, accessor, and mutator member

functions, an overloaded assignment operator, and a copy constructor. First write a driver program to test all your member

functions, and then write a test program that creates at least two patients, at least two doctors, and at least two Billing records, then

prints out the total income from the Billing records.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

//Billing.h
#ifndef BILLING_H
#define BILLING_H
#include "patient.h"
class billing
{
public:
	billing();
	billing(patient obj1, double amt);
	string getPatient();
	string getDoctor();
	string getDesignation();
	double getBill();
	billing(const billing& objBill);
	billing& operator=(const billing& rtside);
private:
	patient pat;
	double bill;
};
#endif

----------------------------------------------------------
//Patient.h
#ifndef PATIENT_H
#define PATIENT_H
#include "person.h"
#include "doctor.h"
class patient :public person
{
public:
	patient();
	patient(string pname, doctor obj);
	patient(const patient& patobj);
	string getPatient();
	string getDoctor();
	string getDesignation();
	patient& operator=(const patient& rtside);
private:
	doctor doc;
};
#endif
--------------------------------------------------------
//Doctor.h
#ifndef DOCTOR_H
#define DOCTOR_H
class doctor
{
public:
	doctor();
	doctor(string dname, string dspeciality);
	doctor(const doctor& docobj);
	string getDoctor();
	string getDesignation();
	doctor& operator=(const doctor& rtside);
private:
	string docName;
	string desg;
};
#endif
--------------------------------------------------------
//Person.h
#ifndef PERSON_H
#define PERSON_H
class person
{
public:

	person();
	person(string namePerson);

	person(const person& objPerson);

	string getName() const;

	person& operator=(const person& rtside);

	friend istream& operator >> (istream& ins, person& per);
	friend ostream& operator<<(ostream& out, const person& per);
private:
	string name;
};
#endif
-------------------------------------------------------
//Billing.cpp
#include "stdafx.h"
#include<iostream>
#include<string>
#include<cstdlib>
using namespace std;
#include "billing.h"
billing::billing()
{
	bill = 0.0;
}

billing::billing(patient p, double b)
{
	pat = p;
	bill = b;
}
billing::billing(const billing& objBill)
{

	pat = objBill.pat;

	bill = objBill.bill;
}

string billing::getPatient()
{
	return pat.getPatient();
}

string billing::getDesignation()
{
	return pat.getDesignation();
}

string billing::getDoctor()
{
	return pat.getDoctor();
}

double billing::getBill()
{
	return bill;
}

billing& billing::operator=(const billing& rtside)
{
	pat = rtside.pat;
	bill = rtside.bill;
	return *this;
}
------------------------------------------------------
//Patient.cpp
#include "stdafx.h"
#include<iostream>
#include<string>
#include<cstdlib>
using namespace std;
#include "patient.h"
patient::patient() :person()
{
}
patient::patient(string pname, doctor obj) : person(pname)
{
	doc = obj;
}
string patient::getPatient()
{
	return getName();
}
string patient::getDoctor()
{
	return doc.getDoctor();
}
string patient::getDesignation()
{
	return doc.getDesignation();
}

patient::patient(const patient& patobj) :person(patobj)
{
	doc = patobj.doc;
}

patient& patient::operator=(const patient& rtside)
{
	person::operator=(rtside);
	doc = rtside.doc;
	return *this;
}
--------------------------------------------------------------------------------------
//Doctor.cpp
#include "stdafx.h"
#include<iostream>
#include<cstdlib>
#include<string>
using namespace std;
#include "doctor.h"
doctor::doctor() :docName("not yet defined "),desg("not yet defined")
{
}
doctor::doctor(string n, string d)
{
	docName = n;
	desg = d;
}
string doctor::getDoctor()
{
	return docName;
}
string doctor::getDesignation()
{
	return desg;
}
doctor::doctor(const doctor& docobj)
{
	docName = docobj.docName;
	desg = docobj.desg;
}
doctor& doctor::operator=(const doctor& rtside)
{
	docName = rtside.docName;
	desg = rtside.desg;
	return *this;
}

------------------------------------------------------------
//Person.cpp
#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;
#include "person.h"
person::person() :name("not yet named")
{
}
person::person(string namePerson) : name(namePerson)
{
}
person::person(const person& objPerson)
{
	name = objPerson.name;
}
string person::getName() const
{
	return name;
}
person& person::operator =(const person& rtside)
{
	name = rtside.name;
	return *this;
}
istream& operator >> (istream& ins, person& per)
{
	string name;
	getline(ins, name);
	return ins;
}
ostream& operator<<(ostream& out, const person& per)
{
	out << per.name;
	return out;
}
--------------------------------------------------------
#include "stdafx.h"
//main cpp
#include<iostream>
#include<string>
#include<iomanip>
#include<cstdlib>

using namespace std;
#include "billing.h"
#include "patient.h"
#include "doctor.h"
int main()
{
	doctor drecordA("Tim Cook", "Cardiologist");
	doctor drecordB("Jon koum", "Orthopedic");
	cout << "Doctor Record:" << endl;
	cout << "_____________" <<endl << endl;
	cout << setw(12) << "Doctor_Name" << setw(20) << "Designation" <<endl;
	cout << setw(12) << "-----------" << setw(20) << "-----------" << endl;
	cout << setw(12) << drecordA.getDoctor() << setw(20) << drecordA.getDesignation() << endl;
	cout << setw(12) << drecordB.getDoctor() << setw(20) << drecordB.getDesignation() << endl;
	cout << endl << endl;
	patient precordA("Mark", drecordA);
	patient precordB("Sundar", drecordA);
	patient precordC("Nadella", drecordB);
	cout << "Patient Record:" << endl;
	cout << "_____________" << endl << endl;
	cout << setw(12) << "Patient_Name" << setw(20)
		<< "Doctor_Name" << setw(20) << "Designation" << endl << endl;
	cout << setw(12) << "------------" << setw(20)
		<< "----------" << setw(20) << "----------" << endl << endl;
	cout << setw(12) << precordA.getName() << setw(20) << precordA.getDoctor() << setw(20) << precordA.getDesignation()
		<< endl;
	cout << setw(12) << precordB.getName() << setw(20) << precordB.getDoctor() << setw(20) << precordB.getDesignation()
		<< endl;
	cout << setw(12) << precordC.getName() << setw(20) << precordC.getDoctor() << setw(20) << precordC.getDesignation()
		<< endl;
	cout << endl << endl;
	billing brecordA(precordA, 65000.00);
	billing brecordB(precordB, 93509.00);
	billing brecordC(precordC, 555320.00);
	cout << "Clinic Record:" << endl;
	cout << "______________" << endl << endl;
	cout << setw(12) << "Patient_Name" << setw(20)
		<< "Doctor_Name" << setw(20) << "Total_Bill_Amount"
		<< endl;
	cout << setw(12) << "-----------" << setw(20)
		<< "-----------" << setw(20) << "-----------------"
		<< endl << endl;
	cout << setw(12) << brecordA.getPatient() << setw(20)
		<< brecordA.getDoctor() << setw(20)
		<< brecordA.getBill() << endl;
	cout << setw(12) << brecordB.getPatient() << setw(20)
		<< brecordB.getDoctor() << setw(20)
		<< brecordB.getBill() << endl;
	cout << setw(12) << brecordC.getPatient() << setw(20)
		<< brecordC.getDoctor() << setw(20)
		<< brecordC.getBill() << endl;
	system("pause");
	return 0;
}

 

OUTPUT:

:

 

0 0

Discussions

Mix Studio

There is error in this code. Please solve it ASAP.

Post the discussion to improve the above solution.