Build a patient base class consisting of
Attributes: full name (string), hometown (string), year of birth (int)
Functions: Create, import, and export information
Build a medical record class that inherits public from the patient class, adding:
Attributes: medical record name (string), hospital charge amount (double)
Functions: Create, import, export information, calculate current age.
Write a main program that does:
Enter a list of N medical records
Sort the list by descending age of the patients
Display the list of patients with age <=10
Show information of the patients with the highest hospital fees
#include<iostream>
#include<string>
#include<list>
using namespace std;
class Patient
{
string fullname;
string hometown;
int year_of_birth;
public:
Patient(){}
void Create()
{
cout << "Please, enter a full name of a patient: ";
getline(cin, fullname, '\n');
cout << "Please, enter a hometown of a patient: ";
cin >> hometown;
cout << "Please, enter a year of birth of a patient: ";
cin >> year_of_birth;
}
void Import(string _fullname, string _hometown, int _year_of_birth)
{
fullname = _fullname;
hometown = _hometown;
year_of_birth = _year_of_birth;
}
void Export()
{
cout<<"\nFullname is "<<fullname;
cout<<"\nHometown is "<<hometown;
cout<<"\nYear of birth is "<<year_of_birth;
}
int GetYear(){return year_of_birth;}
};
class Medical_record :public Patient
{
string med_rec_name;
double hosp_charge;
public:
Medical_record() {}
void Create()
{
cout << "Please, enter a medical record name: ";
cin.ignore(256, '\n');
getline(cin, med_rec_name, '\n');
cout << "Please, enter a hospital charge amount: ";
cin >> hosp_charge;
cin.ignore(256, '\n');
}
void Import(string _med_rec_name, double _hosp_charge)
{
med_rec_name = _med_rec_name;
hosp_charge= _hosp_charge;
}
void Export()
{
cout << "\nMedical record name is " << med_rec_name;
cout << "\nHospital charge name is " << hosp_charge;
}
int CalcAge(int birth_year)
{
return (2021 - birth_year);
}
double GetHospCharge() { return hosp_charge; }
};
bool CompareAge( Medical_record& x,Medical_record& y)
{
return x.CalcAge(x.GetYear()) < y.CalcAge(y.GetYear());
}
int main()
{
const int N = 5;
list<Medical_record>lmr;
for (int i = 0; i <N; i++)
{
Medical_record temp;
temp.Patient::Create();
temp.Create();
lmr.push_back(temp);
}
list<Medical_record>::iterator it;
for (it = lmr.begin(); it != lmr.end(); it++)
{
it->Patient::Export();
it->Export();
}
lmr.sort(CompareAge);
cout << "\n\nSorted list of patients:\n";
for (it = lmr.begin(); it != lmr.end(); it++)
{
it->Patient::Export();
it->Export();
}
cout << "\n\nPatients with age <=10:\n";
for (it = lmr.begin(); it != lmr.end(); it++)
{
if (it->CalcAge(it->Patient::GetYear()) <= 10)
{
it->Patient::Export();
it->Export();
}
}
double highestFee = 0;
for (it = lmr.begin(); it != lmr.end(); it++)
{
if (it->GetHospCharge()>highestFee)
{
highestFee = it->GetHospCharge();
}
}
cout << "\n\nPatients with the highest hospital fee:\n";
for (it = lmr.begin(); it != lmr.end(); it++)
{
if (it->GetHospCharge()== highestFee)
{
it->Patient::Export();
it->Export();
}
}
}
Comments
Leave a comment