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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
|
//
// Grant Wynn
// CMPSC 121
// 3/28/2018
// Description
//
// If you choose to use a preprocessor directive - ie to turn debugging
// notes on an off - you would put them here
// #define debug 1
// Pound includes
#include<iostream>
#include<iomanip>
#include<string>
#include<cmath>
using namespace std;
// Class Definitions
class PatientBill {
public:
// Hospital Costs
double hospitalCost;
// Bool set to true for inpatient and false for outpatient
bool Patient;
// Integer for days
int TheDays;
// Doubles for cost per day, Med Charges Service Charges
double CostPerDay;
double MedCharges;
double ServiceCharges;
// Double for total hospital costs
double HospitalTotalCosts;
// Any other variables would be considered temporary and can be
// declared when you use them
};
// Function Prototypes
void printHeader(string, string, string, string);
bool getBoolean(string); // Enter a boolean
double getDouble(string, double, double); // Enter a double variable
int getInteger(string, int, int); // Enter an integer variable
double calcCosts(int, double, double, double); // In Patient
double calcCosts(double, double); // Out Patient
void printResults(bool Inmate, int Days, double dailyCost, double meds, double services, double total);
// Definition of the program function
int main(void) {
// Call the splash screen function
printHeader("Grant Wynn", "CMPSC 121", "3/28/2018", "The goal of this program is to return the total charges of the bill.");
// Create an object to hold the integer and the boolean result
PatientBill hospitalBill;
// Determine if the patient is in-patient or out-patient
// Do this by calling the getBoolean function with an appropriate string
hospitalBill.Patient = getBoolean("Enter true if you are a in-patient, otherwise enter false: ");
// Call the getDouble function to have user enter the costs
hospitalBill.ServiceCharges = getDouble("Enter the cost of the hospital services ", 1, 1000000);
// If inpatient then call the getInteger function for the number of days
if(hospitalBill.Patient = 1) {
hospitalBill.TheDays = getInteger("Enter the number of days spent in the hospital: ", 1, 60000);
}
// Call appropriate function to calculate the costs
if(hospitalBill.Patient = 1) {
cout << "Enter the daily cost: ";
cin >> hospitalBill.CostPerDay;
cout << "Enter the cost of the medical charges: ";
cin >> hospitalBill.MedCharges;
hospitalBill.HospitalTotalCosts = calcCosts(hospitalBill.TheDays, hospitalBill.CostPerDay, hospitalBill.MedCharges, hospitalBill.ServiceCharges);
}
else if(hospitalBill.Patient = 0) {
cout << "Enter the cost of the medical charges: ";
cin >> hospitalBill.MedCharges;
hospitalBill.HospitalTotalCosts = calcCosts(hospitalBill.MedCharges, hospitalBill.ServiceCharges);
}
// Call the appropriate function to print the results by passing the
// object
printResults(hospitalBill.Patient, hospitalBill.TheDays, hospitalBill.CostPerDay, hospitalBill.MedCharges, hospitalBill.ServiceCharges, hospitalBill.HospitalTotalCosts);
return 0;
}
bool getBoolean(string s) {
// GETBOOLEAN getBoolean(string) is the function that prompts the user to
// enter a value that will be used as a true or false. It must check that
// the value is either 0 or 1. It returns the bool
//
// Name: Grant Wynn
// Course: CMPSC 121
// Date: 8/28/2018
//
bool boolValue;
cout << s;
cin >> boolValue;
if(boolValue = 1) {
return boolValue =1;
}
else if(boolValue = 0) {
return boolValue = 0;
}
else {
cout << "You have not entered true of false, try again.";
}
}
int getInteger(string s, int low, int high) {
// GETINTEGER getInteger(string, int, int) is the function that prompts the
// user to enter an integer value. It error checks it so see that it is
// within the range of values passed to the function. It returns the
// integer value.
//
// Name: Grant Wynn
// Course: CMPSC 121
// Date: 3/28/2018
//
int intValue;
cout << s;
cin >> intValue;
if(intValue < low) {
cout << "You have entered an invalid number of days please try again." << endl;
}
else if(intValue > high) {
cout << "You have entered an invalid number of days please try again." << endl;
}
else {
return intValue;
}
}
double getDouble(string s, double low, double high) {
// GETDOUBLE getDouble(string, double, double) is the function that prompts the
// user to enter a double value. It error checks it so see that it is
// within the range of values passed to the function. It returns the
// double value.
//
// Name: Grant Wynn
// Course: CMPSC 121
// Date: 3/28/18
//
double doubleValue;
cout << s;
cin >> doubleValue;
if(doubleValue < low) {
cout << "You have entered an invalid number of days please try again." << endl;
}
else if(doubleValue > high) {
cout << "You have entered an invalid number of days please try again." << endl;
}
else {
return doubleValue;
}
}
void printHeader(string name, string course, string dueDate, string description) {
// PRINTHEADER printHeader(string, string, string, string) is the
// function used to hide away the splash screen
//
// Name: Grant Wynn
// Course: CMPSC 121
// Date: 12 March 2017
//
// Print the splash screen
cout << endl;
cout << name << endl;
cout << course << endl;
cout << dueDate << endl;
cout << description << endl;
cout << endl;
return;
}
double calcCosts(int days, double dailyCost, double meds, double services) {
// CALCCOSTS calcCosts(int, double, double, double) is the
// function used calculate the in patient costs
//
// Name: Grant Wynn
// Course: CMPSC 121
// Date: 3/28/2018
//
// Declare the variable for the total costs
double totalCost;
// Calculate the costs
totalCost = (days * dailyCost) + meds + services;
// return the totalCost
return totalCost;
}
double calcCosts(double meds, double services) {
// CALCCOSTS calcCosts(double, double) is the
// function used calculate the out patient costs
//
// Name: Grant Wynn
// Course: CMPSC 121
// Date: 3/28/18
//
// Declare the variable for the total costs
double totalCost;
// Calculate the costs
totalCost = meds + services;
// return the totalCost
return totalCost;
}
void printResults(bool Inmate, int Days, double dailyCost, double meds, double services, double total) {
// PRINTRESULTS printResults(PatientBill patientData) is the
// function used to print the results of the program. It is
// passed a copy of the object currently holding the patient
// data
//
// Name: Grant Wynn
// Course: CMPSC 121
// Date: 3/28/2018
//
// Function should print the input data
if(Inmate = 1) {
cout << endl;
cout << "Number of days spent in the hospital:" << setw(6) << Days << endl;
cout << "The daily rate:" << setw(28) << dailyCost << "$" << endl;
cout << "The hospital medical charges:" << setw(14) << meds << "$" << endl;
cout << "The charges for the hospital service:" << setw(6) << services<< "$" << endl;
cout << "The Total Cost of the hospital visit:" << setw(6)<< total << "$" << endl;
cout << endl;
}
else if(Inmate = 0) {
cout << "The hospital medical charges:" << setw(14) << meds << endl;
cout << "The charges for the hospital service:" << setw(6) << services << endl;
cout << "The Total Cost of the hospital visit:" << setw(6) << total << endl;
}
return;
}
|