Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C Plus Plus Programming 7th Edition. 11. In this exercise, you will design vario

ID: 664635 • Letter: C

Question

C Plus Plus Programming 7th Edition.

11. In this exercise, you will design various classes and write a program to computerize the billing system of a hospital.

a. Design the class doctorType, inherited from the class personType, defined in Chapter 10, with an additional data member to store a doctor’s speciality. Add appropriate constructors and member functions to initialize, access, and manipulate the data members.

b. Design the class billType with data members to store a patient’s ID and a patient’s hospital charges, such as pharmacy charges for medicine, doctor’s fee, and room charges. Add appropriate constructors and member functions to initialize, access, and manipulate the data members.

c. Design the class patientType, inherited from the class personType, defined in Chapter 10, with additional data members to store a patient’s ID, age, date of birth, attending physician’s name, the date when the patient was admitted in the hospital, and the date when the patient was discharged from the hospital. (Use the class dateType to store the date of birth, admit date, discharge date, and the class doctorType to store the attending physician’s name.) Add appropriate constructors and member functions to initialize, access, and manipulate the data members. Write a program to test your classes.

This is Chapter 10's personType.

#include <string>
using namespace std;
class personType
{
public:
void print() const;
//Function to output the first name and last name
//in the form firstName lastName.
void setName(string first, string last);
//Function to set firstName and lastName according
//to the parameters.
//Postcondition: firstName = first; lastName = last;
string getFirstName() const;
//Function to return the first name.
//Postcondition: The value of firstName is returned.
string getLastName() const;
//Function to return the last name.
//Postcondition: The value of lastName is returned.
personType(string first = "", string last = "");
//Constructor
//Sets firstName and lastName according to the parameters.
//The default values of the parameters are null strings.
//Postcondition: firstName = first; lastName = last;
private:
string firstName; //variable to store the first name
string lastName; //variable to store the last name
};

Explanation / Answer

#include<iostream>
#include<string>
#include "PersonType.h"
#include "PatientType.h"
#include "DoctorType.h"

using namespace std;
class PersonType
{
public:
    void print() const; //Function to output the first name and last name

    void setName(string first, string last);
    //Function to set firstName and lastName according
    tName = first; lastName = last
  
    void setDateOfBirth(string dateOfBirth);
  
    string getFirstName() const;
    string getLastName() const;
    string getDateOfBirth() const;
  
    PersonType(string first = "", string last = "", string dateOfBirth = "");
    //constructor
    //Sets firstName and lastName according to the parameters.
  
  
private:
    string firstName; //variable to store the first name
    string lastName; //variable to store the last name
    string dateOfBirth;
};

#endif

void PersonType::print() const{
    std::cout << "Name is " << firstName << " " << lastName << " ";
}

void PersonType::setName(string first, string last){
    firstName = first;
    lastName = last;
}

void PersonType::setDateOfBirth(string dateOfBirth){
    this->dateOfBirth = dateOfBirth;
}

string PersonType::getFirstName() const{
    return firstName;
}

string PersonType::getLastName() const{
    return lastName;
}

string PersonType::getDateOfBirth() const{
    return dateOfBirth;
}

PersonType::PersonType(string first, string last, string dateOfBirth){
    firstName = first;
    lastName = last;
    dateOfBirth = dateOfBirth;
}

class DoctorType : public PersonType
{
public:
   void SetName(string first, string last);
   void SetSpeciality(string Special);
   void SetDoctor(string Doc);
   string getDoctor() const;
   string getSpeciality() const;
   string getFirstName() const;
   string getLastName() const;
   DoctorType(string Special = "");

private:
   string FirstName, LastName, Speciality, Doctor;
};
void DoctorType::SetDoctor(string Doc)
{
   Doctor = Doc;
}
string DoctorType::getDoctor() const
{
   return Doctor;
}

class BillType{
public:
    BillType();
    BillType(int patientId, float hospitalCharges, float doctorFee, float roomCharges);
    void setPatientId(int patientId);
    int getPatientId();
    void setHospitalCharges(float hospitalCharges);
    float getHospitalCharges();
    void setDoctorFee(float doctorFee);
    float getDoctorFee();
    void setRoomCharges(float roomCharges);
    float getRoomCharges();
  
private:
    int patientId;
    float hospitalCharges;
    float doctorFee;
    float roomCharges;
};

#endif

BillType::BillType(){
  
}

BillType::BillType(int patientId, float hospitalCharges, float doctorFee, float roomCharges){
    this->patientId = patientId;
    this->hospitalCharges = hospitalCharges;
    this->doctorFee = doctorFee;
    this->roomCharges = roomCharges;
}

void BillType::setPatientId(int patientId){
    this->patientId = patientId;
}

int BillType::getPatientId(){
    return patientId;
}

class PatientType : public PersonType{
  
public:
    PatientType();
    PatientType(int id, string firstName, string lastName, string dateOfBirth, string admitDate, string dischargeDate, PersonType doctorIncharge);
    int getId() const;
    void setId(int id);
    string getAdmitDate() const;
    void setAdmitDate(string admitDate);
    string getDischargeDate() const;
    void setDischargeDate(string dischargeDate);
    PersonType getDoctorIncharge() const;
    void setDoctorIncharge(PersonType doctorIncharge);
  
private:
    int id;
    string admitDate;
    string dischargeDate;
    PersonType doctorIncharge;
};

#endif

PatientType::PatientType():PersonType(){
  
}

PatientType::PatientType(int id, string firstName, string lastName, string dateOfBirth, string admitDate, string dischargeDate, PersonType doctorIncharge) : PersonType (firstName, lastName, dateOfBirth){
    this->id = id;
    this->admitDate = admitDate;
    this->dischargeDate = dischargeDate;
    this->doctorIncharge = doctorIncharge;
}

void PatientType::setId(int id){
    this->id = id;
}

int PatientType::getId() const{
    return id;
}

void PatientType::setAdmitDate(string admitDate){
    this->admitDate = admitDate;
}

string PatientType::getAdmitDate() const{
    return admitDate;
}

void PatientType::setDischargeDate(string dischargeDate){
    this->dischargeDate = dischargeDate;
}

string PatientType::getDischargeDate() const{
    return dischargeDate;
}

void PatientType::setDoctorIncharge(PersonType doctorIncharge){
    this->doctorIncharge = doctorIncharge;
}

PersonType PatientType::getDoctorIncharge() const{
    return doctorIncharge;
}

class dateType
{
public:
   void setDate(int month, int day, int year);
   //set member variables dMonth, dDay, and dYear
  
   void setMonth(int month);
   //set member variable dMonth
  
   void setDay(int day);
   //set member variable dDay
  
   void setYear(int year);
   //set member variable dYear
  
   void calculateNewDate(int dayAmount);
   //calculate new date by adding a fixed amount of days to the date
  
   int getDaysInMonth() const;
   //return number of days in dMonth
  
   int getDaysPassed() const;
   //return number of days passed in the year
  
   int getDaysRemaining() const;
   //return number of days remaining in the year
  
   int getDay() const;
   //return dDay
  
   int getMonth() const;
   //return dMonth
  
   int getYear() const;
   //return dYear
  
   bool isLeapYear() const;
   //check if dYear is a leap year
  
   void printDate() const;
   //print the date in the format: dMonth-dDay-dYear
  
   dateType(int = 1, int = 1, int = 1900);
   //default constructor
private:
   int dMonth;
   int dDay;
   int dYear;
};

int main()
{
   //Tested and verified all the functions, except calculateNewDate
   dateType myDate(12, 31, 2008);
  
   myDate.printDate();
  
   cout << "Total days passed in year is " << myDate.getDaysPassed() << endl;
   cout << "Total days remaining in year is " << myDate.getDaysRemaining() << endl;
  
   myDate.printDate();
  
   return 0;
}

void dateType::setDate(int month, int day, int year)
{
   if(1 <= month && month <= 12) //make sure value of dMonth is valid
       dMonth = month;
   else
       dMonth = 1;
  
   if(year > 0)//make sure value of dYear is valid
       dYear = year;
   else
       dYear = 1;
  
   if(dMonth <= 7) //Months in range Jan-July: Odd numbered months have 31 days, even months have 30
   {
       if(dMonth % 2 == 1 && (1 <= day && day <= 31)) //make sure dDay is valid
           dDay = day;
       else if((dMonth % 2 == 0 && dMonth != 2) && (1 <= day && day <= 30))
           dDay = day;
       else if((dMonth == 2 && isLeapYear()) && (1 <= day && day <= 29)) //During leap year, Feb. has 29 days
           dDay = day;
       else if((dMonth == 2 && !isLeapYear()) && (1 <= day && day <=28)) //During normal year, Feb. has 28 days
           dDay = day;
       else
           dDay = 1;
   }
   else //Months in range Aug.-December: Odd numbered months have 30 days, even months have 31 days
   {
       if(dMonth % 2 == 1 && (1 <= day && day <= 30))
           dDay = day;
       else if(dMonth % 2 == 0 && (1 <= day && day <= 31))
           dDay = day;
       else
           dDay = 1;
   }
  
}

void dateType::setMonth(int month)
{
   if(1 <= month && month <= 12) //make sure dMonth is valid
       dMonth = month;
   else
       dMonth = 1;
}

void dateType::setDay(int day)
{
   if(dMonth <= 7) //months in range Jan-July: Odd numbered months have 31 days, even months have 30
   {
       if(dMonth % 2 == 1 && (1 <= day && day <= 31))
           dDay = day;
       else if((dMonth % 2 == 0 && dMonth != 2) && (1 <= day && day <= 30))
           dDay = day;
       else if((dMonth == 2 && isLeapYear()) && (1 <= day && day <= 29)) //During leap year, Feb. has 29 days
           dDay = day;
       else if((dMonth == 2 && !isLeapYear()) && (1 <= day && day <=28)) //During normal year, Feb. has 28 days
           dDay = day;
       else
           dDay = 1;
   }
   else //months in range Aug-December: Odd numbered months have 30 days, even months have 31
   {
       if(dMonth % 2 == 1 && (1 <= day && day <= 30))
           dDay = day;
       else if(dMonth % 2 == 0 && (1 <= day && day <= 31))
           dDay = day;
       else
           dDay = 1;
   }
}

void dateType::setYear(int year)
{
   if(year > 0) //make sure year is valid
       dYear = year;
   else
       dYear = 1;
  
}

void dateType::calculateNewDate(int dayAmount)
{
   //stumped with this function
}

int dateType::getDaysInMonth() const
{
   if(dMonth <= 7) //find days of months in range Jan.-July
   {
       switch(dMonth % 2)
       {
            case 0:
                if(dMonth == 2 && isLeapYear())
                    return 29;
                else if(dMonth == 2 && !isLeapYear())
                    return 28;
                else
                    return 30;
            case 1:
               return 31;
       }//end switch
   } //end if
   else //find months in range August-December
   {
       switch(dMonth % 2)
       {
            case 0:
                return 31;
            case 1:
                return 30;
       } //end switch
   } //end else
    return 0;
}

int dateType::getDaysPassed() const
{
   switch(dMonth)
   {
        case 1:
            return dDay;
        case 2:
            return (31 + dDay);
        case 3:
            if(isLeapYear())
                return (60 + dDay);
            else
                return (59 + dDay);
        case 4:
            if(isLeapYear())
                return (91 + dDay);
            else
                return (90 + dDay);
        case 5:
            if(isLeapYear())
                return (121 + dDay);
            else
                return (120 + dDay);
        case 6:
            if(isLeapYear())
                return (152 + dDay);
            else
                return (151 + dDay);
        case 7:
            if(isLeapYear())
                return (182 + dDay);
            else
                return (181 + dDay);
        case 8:
            if(isLeapYear())
                return (213 + dDay);
            else
                return (212 + dDay);
        case 9:
            if(isLeapYear())
                return (244 + dDay);
            else
                return (243 + dDay);
        case 10:
            if(isLeapYear())
                return (274 + dDay);
            else
                return (273 + dDay);
        case 11:
            if(isLeapYear())
                return (305 + dDay);
            else
                return (304 + dDay);
        case 12:
            if(isLeapYear())
                return (335 + dDay);
            else
                return (334 + dDay);
   }
    return 0;
}

int dateType::getDaysRemaining() const
{
   if(isLeapYear())
       return (366 - getDaysPassed());
   else
       return (365 - getDaysPassed());
}

int dateType::getDay() const
{
   return dDay;
}

int dateType::getMonth() const
{
   return dMonth;
}

int dateType::getYear() const
{
   return dYear;
}

bool dateType::isLeapYear() const
{
   return(dYear % 4 == 0 && (dYear % 100 != 0 || dYear % 400 == 0));
}

void dateType::printDate() const
{
   cout << dMonth << "-" << dDay << "-" << dYear << endl;
}

dateType::dateType(int month, int day, int year) //default constructor. Same body as setDate function
{
   if(1 <= month && month <= 12)
       dMonth = month;
   else
       dMonth = 1;
  
   if(year > 0)
       dYear = year;
   else
       dYear = 1;
  
   if(dMonth <= 7)
   {
       if(dMonth % 2 == 1 && (1 <= day && day <= 31))
           dDay = day;
       else if((dMonth % 2 == 0 && dMonth != 2) && (1 <= day && day <= 30))
           dDay = day;
       else if((dMonth == 2 && isLeapYear()) && (1 <= day && day <= 29))
           dDay = day;
       else if((dMonth == 2 && !isLeapYear()) && (1 <= day && day <=28))
           dDay = day;
       else
           dDay = 1;
   }
   else
   {
       if(dMonth % 2 == 1 && (1 <= day && day <= 30))
           dDay = day;
       else if(dMonth % 2 == 0 && (1 <= day && day <= 31))
           dDay = day;
       else
           dDay = 1;
   }
}

int main()
{
   int choice;

   PersonType *Person = NULL;

   cout << "Who would you like to input information for? ";
   cout << "      1 - Doctor ";
   cout << "      2 - Patient ";
   cin >> choice;

   if (choice == 1)
   {
       Person = new DoctorType();
       Person->SetName();
       Person->SetSpeciality();
   }
   else if (choice == 2)
   {
       Person = new PatientType();
       Person->;
       Person->;
   }
   return 0;
}