C++ program that computes a patient’s bill for a hospital stay
You are to write a C++ program that computes a patient’s bill for a hospital stay. The
different components of the program are
The PatientAccount class
The Surgery class
The Pharmacy class
The main program
The PatientAccount class will keep a total of the patient’s charges. It will
also keep track of the number of days spent in the hospital. The group must
decide on the hospital’s daily rate.
The Surgery class will have stored within it the charges for at least five types
of surgery. It can update the charges variable of the PatientAccount class.
The Pharmacy class will have stored within it the price of at least five types of
medication. It can update the charges variable of the PatientAccount class.
The student who designs the main program will design a menu that allows
the user ro enter a type of surgery and a type of medication, and check the
patient out of the hospital. When the patient checks Ollt, the tOtal charges
should be displayed.
Answer:
// Patient Fees #include <iostream> #include <iomanip> #include "PatientAccount.h" #include "Surgery.h" #include "Pharmacy.h" using namespace std; // Function prototypes int getSurgeryType(); int getMedicationType(); int main() { int surgeryType, // To hold the type of surgery medicationType; // To hold the type of medication PatientAccount patient1; // Create a PatientAccount object. Surgery surgery; // Create a Surgery object. Pharmacy pharmacy; // Create a Pharmacy object. cout << "\n\nPatient Release Menu\n\n"; patient1.setDays(); // Sets length of patient stay and // adds daily room rate onto charges // Get the surgery and medication types. surgeryType = getSurgeryType(); medicationType = getMedicationType(); surgery.updateAccount(patient1, surgeryType); pharmacy.updateAccount(patient1, medicationType); cout << fixed << showpoint << setprecision(2); cout << "\nPatient Charges: " << patient1.getCharges() << endl << endl; return 0; } //*********************************************** // Function getSurgeryType * // Displays a menu of surgery types and gets * // a selection from the user. The selection * // is returned. * //*********************************************** int getSurgeryType() { int choice; // Display the surgery menu cout << "\nTypes of Surgery We Perform\n"; cout << "---------------------------\n"; cout << "1 - Tonsillectomy\n"; cout << "2 - Foot\n"; cout << "3 - Knee\n"; cout << "4 - Shoulder\n"; cout << "5 - Appendectomy\n\n"; cout << "Choose a type of Surgery (1-5): "; cin >> choice; while (choice < 1 || choice > 5) { cout << "Legal values are 1-5. Please re-enter surgery type: "; cin >> choice; } return choice; } //*********************************************** // Function getMedicationType * // Displays a menu of medication types and gets * // a selection from the user. The selection * // is returned. * //*********************************************** int getMedicationType() { int choice; // Display the medication menu cout << "\nTypes of Medication\n"; cout << "---------------------------\n"; cout << "1 - Antibiotic\n"; cout << "2 - Ant-inausea\n"; cout << "3 - Anti-inflamatory\n"; cout << "4 - Light Pain\n"; cout << "5 - Strong Pain\n\n"; cout << "Choose a type of medication (1-5): "; cin >> choice; while (choice < 1 || choice > 5) { cout << "Legal values are 1-5. Please re-enter medication type: "; cin >> choice; } return choice; }
Implementation file for the PatientAccount class
#include "patientAccount.h" #include <iostream> using namespace std; // Daily room rate const double DAILY_RATE = 500.00; //********************************************************** // Default constructor * //********************************************************** PatientAccount::PatientAccount() { days = 0; charges = 0.00; } //********************************************************** // setDays member function * //********************************************************** void PatientAccount::setDays() { // Get the number of days in the hospital. cout << "How many days was the patient in the hospital? "; cin >> days; // Validate it. while (days < 0) { cout << "Days must be 0 or more. Please re-enter: "; cin >> days; } // Update charges. charges += days * DAILY_RATE; } //********************************************************** // updateCharges member function * //********************************************************** void PatientAccount::updateCharges(double newCharge) { charges += newCharge; } //********************************************************** // getCharges member function * //********************************************************** double PatientAccount::getCharges() { return charges; }
Specification file for the PatientAccount class
#ifndef PATIENT_ACCOUNT_H #define PATIENT_ACCOUNT_H class PatientAccount { private: double charges; int days; public: PatientAccount(); void setDays(); void updateCharges(double); double getCharges(); }; #endif
Implementation file for the Pharmacy class
#include "Pharmacy.h" //*********************************************************** // Default constructor * //*********************************************************** Pharmacy::Pharmacy() { price1 = 10.00; // set prices for medicine types 1-5 price2 = 20.00; price3 = 30.00; price4 = 40.00; price5 = 50.00; } //*********************************************************** // updateAccount member function * //*********************************************************** void Pharmacy::updateAccount(PatientAccount& pt, int type) { switch (type) { case 1: pt.updateCharges(price1); break; case 2: pt.updateCharges(price2); break; case 3: pt.updateCharges(price3); break; case 4: pt.updateCharges(price4); break; case 5: pt.updateCharges(price5); break; default: ; // Do not add any charge to the account. } }
Specification file for the Pharmacy class
#include "PatientAccount.h" #ifndef PHARMACY_H #define PHARMACY_H class Pharmacy { private: double price1, // holds prices of 5 types of medicine price2, price3, price4, price5; public: Pharmacy(); void updateAccount(PatientAccount&, int); }; #endif
Implementation file for the Surgery class
#include "surgery.h" //********************************************************** // Default constructor * //********************************************************** Surgery::Surgery() { rate1 = 100.00; // set rates for suregery types 1-5 rate2 = 200.00; rate3 = 300.00; rate4 = 400.00; rate5 = 500.00; } //********************************************************** // updateAccount member function * //********************************************************** void Surgery::updateAccount(PatientAccount& pt, int type) { switch (type) { case 1: pt.updateCharges(rate1); break; case 2: pt.updateCharges(rate2); break; case 3: pt.updateCharges(rate3); break; case 4: pt.updateCharges(rate4); break; case 5: pt.updateCharges(rate5); break; default: ; // Do not add any charge to the account. } }
Specification file for the Surgery class
#include "PatientAccount.h" #ifndef SURGERY_H #define SURGERY_H class Surgery { private: double rate1, // rates for each of these surgery types rate2, rate3, rate4, rate5; public: Surgery(); void updateAccount(PatientAccount&, int); }; #endif
Leave a reply