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
|
#include <iostream>
#include <iomanip>
#include <string>
double validateData(double, const std::string&);
double patientCharges(int, double, double, double);
double patientCharges(double, double);
int main() {
char patientType {};
int days {};
double roomRate {},
medication {},
services {},
totalCharges {};
std::cout << "This program will compute patient hospital charges.\n";
std::cout << "Enter I for in-patient or O for out-patient: ";
std::cin >> patientType;
if (patientType == 'i')
patientType = 'I';
else if (patientType == 'o')
patientType = 'O';
while (patientType != 'I' && patientType != 'O') {
std::cout << "Please enter I or O: ";
std::cin >> patientType;
if (patientType == 'i')
patientType = 'I';
else if (patientType == 'o')
patientType = 'O';
}
std::cout << '\n';
if (patientType == 'I') {
std::cout << "Number of days in the hospital: ";
std::cin >> days;
days = static_cast<int>(validateData(days, "days in hospital"));
std::cout << "Daily room rate: $";
std::cin >> roomRate;
roomRate = validateData(roomRate, "daily room rate");
}
std::cout << "Lab fees and other service charges: $";
std::cin >> services;
services = validateData(services, "lab fees and other service charges");
std::cout << "Medication charges: $";
std::cin >> medication;
medication = validateData(medication, "medication charges");
if (patientType == 'I')
totalCharges = patientCharges(days, roomRate, medication, services);
else
totalCharges = patientCharges(medication, services);
std::cout << std::fixed << std::showpoint << std::setprecision(2) << '\n';
std::cout << "************************** \n";
std::cout << "Hospital Billing Statement \n";
std::cout << "************************** \n";
if (patientType == 'I')
std::cout << std::setw(15) << std::left << "Room charges " << "$" << std::right << std::setw(8) << days * roomRate << '\n';
if (services > 0.0)
std::cout << std::setw(15) << std::left << "Lab & Services " << "$" << std::right << std::setw(8) << services << '\n';
if (medication > 0.0)
std::cout << std::setw(15) << std::left << "Medication " << "$" << std::right << std::setw(8) << medication << '\n';
std::cout << std::setw(15) << std::left << "Total charges " << "$" << std::right << std::setw(8) << totalCharges << '\n';
std::cout << "**************************\n\n";
}
// This needs to be completed
double validateData(double data, const std::string& str) {
return data;
}
double patientCharges(int d, double r, double m, double s) {
return r * d + m + s;
}
double patientCharges(double med, double serv) {
return med + serv;
}
|