supaya bisa mempercepat proses pelayanan.
selamat mencoba !!!
#include <iostream>
#include <iomanip>
using namespace std;
#include <iomanip>
using namespace std;
// Function prototypes
char getChoice();
double patientCharges(int, double, double, double); // In-patient
double patientCharges(double, double); // Out-patient
int main()
{
char patientType; // I=in-patient, O=out-patient
int days; // Number of days of <strong class="highlight">hospital</strong> stay
double roomRate, // Daily room rate
medication, // Total medication charges
services, // Total for tests and other services
totalCharges; // Total of all charges
// Input and validate patient type
cout << "This <strong class="highlight">program</strong> will compute patient <strong class="highlight">hospital</strong> charges.\n";
cout << "Enter I for in-patient or O for out-patient: ";
patientType=getChoice();
//Process the menu selection
switch (patientType)
{
//Inpatient
case 'I':
case 'i': cout << "The number of days spent in the <strong class="highlight">hospital</strong>: ";
cin >> days;
cout << "The daily rate: ";
cin >> roomRate;
cout << "Charges for <strong class="highlight">hospital</strong> service: ";
cin >> services;
cout << "Hospital medicaion charges; ";
cin >> medication;
cout << patientCharges (days, roomRate, services, medication) << endl;
totalCharges=(days*roomRate) + services + medication;
break;
//Outpatient
case 'O':
case 'o': cout << "Charges for <strong class="highlight">hospital</strong> services: ";
cin >> services;
cout << "Hospital medication charges: ";
cin >> medication;
cout << patientCharges (services, medication) << endl;
totalCharges= services + medication;
}
// Display the billing statment
cout << fixed << showpoint << setprecision(2) << endl << endl;
cout << "******************************\n";
if (patientType == 'I' && patientType == 'i')
cout << "Room charges $" << setw(8) << days*roomRate << endl;
if (services > 0.0)
cout << "Lab & Services $" << setw(8) << services << endl;
if (medication > 0.0)
cout << "Medication $" << setw(8) << medication << endl;
cout << "Total charges $" << setw(8) << totalCharges << endl;
cout << "******************************\n";
return 0;
}// End of main function
//************************************...
// Definition of function getChoice *
// Accepts and returns user's validated menu choice. *
//************************************...
char getChoice()
{
char letter; // Holds user's letter choice
// Get the user's choice
cin >> letter;
// Validate the choice
while (letter != 'I' && letter != 'i'
&& letter != 'O' && letter != 'o')
{
cout << "Enter I or O: ";
cin >> letter;
}
// Return the choice
return letter;
}
/*************************************...
* patientCharge *
* This function is called by main to calculate and return *
* total patient charges for in-patients *
**************************************...
double patientCharges(int days, double rate, double med, double serv)
{
return (days*rate) + med + serv;
}// end overload function patientCharges
/*************************************...
* patientCharge *
* This function is called by main to calculate and return *
* total patient charges for out-patients *
**************************************...
double patientCharges(double med, double serv)
{
return med + serv;
}// end overload function patientCharges
char getChoice();
double patientCharges(int, double, double, double); // In-patient
double patientCharges(double, double); // Out-patient
int main()
{
char patientType; // I=in-patient, O=out-patient
int days; // Number of days of <strong class="highlight">hospital</strong> stay
double roomRate, // Daily room rate
medication, // Total medication charges
services, // Total for tests and other services
totalCharges; // Total of all charges
// Input and validate patient type
cout << "This <strong class="highlight">program</strong> will compute patient <strong class="highlight">hospital</strong> charges.\n";
cout << "Enter I for in-patient or O for out-patient: ";
patientType=getChoice();
//Process the menu selection
switch (patientType)
{
//Inpatient
case 'I':
case 'i': cout << "The number of days spent in the <strong class="highlight">hospital</strong>: ";
cin >> days;
cout << "The daily rate: ";
cin >> roomRate;
cout << "Charges for <strong class="highlight">hospital</strong> service: ";
cin >> services;
cout << "Hospital medicaion charges; ";
cin >> medication;
cout << patientCharges (days, roomRate, services, medication) << endl;
totalCharges=(days*roomRate) + services + medication;
break;
//Outpatient
case 'O':
case 'o': cout << "Charges for <strong class="highlight">hospital</strong> services: ";
cin >> services;
cout << "Hospital medication charges: ";
cin >> medication;
cout << patientCharges (services, medication) << endl;
totalCharges= services + medication;
}
// Display the billing statment
cout << fixed << showpoint << setprecision(2) << endl << endl;
cout << "******************************\n";
if (patientType == 'I' && patientType == 'i')
cout << "Room charges $" << setw(8) << days*roomRate << endl;
if (services > 0.0)
cout << "Lab & Services $" << setw(8) << services << endl;
if (medication > 0.0)
cout << "Medication $" << setw(8) << medication << endl;
cout << "Total charges $" << setw(8) << totalCharges << endl;
cout << "******************************\n";
return 0;
}// End of main function
//************************************...
// Definition of function getChoice *
// Accepts and returns user's validated menu choice. *
//************************************...
char getChoice()
{
char letter; // Holds user's letter choice
// Get the user's choice
cin >> letter;
// Validate the choice
while (letter != 'I' && letter != 'i'
&& letter != 'O' && letter != 'o')
{
cout << "Enter I or O: ";
cin >> letter;
}
// Return the choice
return letter;
}
/*************************************...
* patientCharge *
* This function is called by main to calculate and return *
* total patient charges for in-patients *
**************************************...
double patientCharges(int days, double rate, double med, double serv)
{
return (days*rate) + med + serv;
}// end overload function patientCharges
/*************************************...
* patientCharge *
* This function is called by main to calculate and return *
* total patient charges for out-patients *
**************************************...
double patientCharges(double med, double serv)
{
return med + serv;
}// end overload function patientCharges
Kok pas saya build masih ada yang salah ya? tolong di balas
BalasHapus