Here is the question:
You must write a complete C++ program based on the instruction below:
a. Write a class named Name that consists of information such as first name and last name. The Name class consists of a constructor with two arguments which are first name and last name. It also contains the methods that access the full name.
b. Write a class named Patient. The class consists of specific information such as patient ID, gender, age, the aggregation of the class of Address as well as the composition of HealthInfo and Name classes. The Patient class also provides functions such as a constructor with default arguments to initialize a patient with their patient ID, names, gender, address, height, and weight. It also contains the accessor methods to get the information of patient ID, gender, age, address, doctor, full name from the class of Name, and weight and height from the class of HealthInfo.
** Every time a patient is added, a message will be displayed such as the following:
“Patient: <full name here> has been added”
c. Write a class named Doctor. The class consists of a constructor that accepts three arguments which are
staff ID, first name, and last name.
d. The Doctor class is associated with the Patient class where each patient is attended by one of the
doctors. Information of the doctors can be associated in Patient class via attendBy(Doctor)
function that saves the information of the doctor into the attribute of Doctor in Patient.
e. Write a class named Address which is aggregated into Patient class. The class consists of information
such as street name, city, postal code, and state. This class has a constructor that takes up four arguments
for the address info as well as an accessor method to get the complete address.
f. Write a class named HealthInfo which contains the specific measurements for a patient (height, and
weight). The class has a two-argument constructor. The class also consists of the accessor methods for
those attributes.
g. You are given the incomplete main() function (refer to Figure 2). You are required to do the following
tasks:
i. Initialize THREE patients and addresses based on Table 1 below.
ii. Then, create a dynamic list to hold the objects of Patient.
iii. Save the patient in (i) into the dynamic list in (ii).
iv. After initializing the three patients and saved into the list, the program will invoke the
displayRecord function (refer to Figure 2) to display the list of patients as shown in Figure
3.
Here is what I got for my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
#include <iostream>
#include <iomanip>
using namespace std;
//(a)
class Name{
private:
string firstName;
string lastName;
public:
Name(string, string);
string getFullName();
};
//(e)
class Address{
private:
string street;
string city;
int postcode;
string state;
public:
Address(string, string, int, string);
string getAddress();
};
//(f)
class HealthInfo{
private:
int height;
int weight;
public:
HealthInfo(int, int);
int getHeight();
int getWeight();
};
//(c)
class Doctor{
private:
string staffID;
Name(name);
public:
Doctor(string, string, string) ;
string getFullName;
};
//(b)
class Patient{
private:
string patientID;
Name name;
int age;
string gender;
Address* address;
HealthInfo pHealth;
Doctor* doctor;
public:
static int numPatient;
Patient(string, string, string, string, Address*, int, int , int);
string getPatientID();
int getWeight();
int getHeight();
string getFullName();
string getGender();
int getAge();
void getAddress(Address *);
void getDoctor(Doctor *);
void attendBy(Doctor);
};
//(d)
//dunno what question want
//(g)
//This function display the record of the patient
void displayRecord(Patient pL[]) {
cout << "\nPatient Record Management System" << endl
<< "================================" << endl << endl
<< setw(4) << "No" << setw(10) << "PatientID" << setw(15) << "Name"
<< setw(5) << "Age" << setw(8) << "Gender" << setw(37) << "Address"
<< setw(8) << "Height" << setw(8) << "Weight" << setw(20) << "Attend By"
<< endl << setw(4) << "--" << setw(10) << "---------" << setw(15)
<< "----" << setw(5) << "---" << setw(8) << "------" << setw(37)
<< "-------" << setw(8) << "------" << setw(8) << "------" << setw(20)
<< "---------" << endl;
for(int i=0; i < Patient::numPatient; i++)
cout << setw(4) << (i+1) << setw(10) << pL[i].getPatientID() << setw(15)
<< pL[i].getFullName() << setw(5) << pL[i].getAge() << setw(8)
<< pL[i].getGender() << setw(37) << pL[i].getAddress()->getAddress()
<< setw(8) << pL[i].getHeight() << setw(8) << pL[i].getWeight()
<< "Dr. " << pL[i].getDoctor()->getFullName() << endl;
cout << "\n-------------------" << endl;
cout << "Total Patients: " << Patient::numPatient << endl;
}
int main() {
//(i)Initialize the Address objects based on the information given in Table 1
//(ii)Initialize the Patient objects based on the information given in Table 1
//(iii)Initialize the Doctor objects based on the information given in Table 2
//(iv)Assign Doctor to Patient based on information given in Table 1
//(v)Create a dynamic list to hold the objects of Patient //v(a)Define a Patient pointer //v(b)Use a pointer in v(a) to dynamically allocate an array of Patient objects
//(vi)Save the patient in (ii) into the dynamic list in v(b)
cout << left;
displayRecord(patientList);
return 0;
}
|
I don't know for the question (d).