Assignment Plan and code a C++ program utilizing one or more selection structure
ID: 3728236 • Letter: A
Question
Assignment Plan and code a C++ program utilizing one or more selection structures to solve the following problem: Write a program to compute charges for a patient in Community Hospital. Charges per day per patient are computed from the following Room charges per day Private room Semi private room: Ward: $125.00 $95.00 $ 75.00 $ 1.75 $ 3.50 Telephone charge Television charge Name of the individual, patient identification number, type of room. Have the user enter the number of days, the type of room (P, S, W), whether or not patient had a telephone (Y/N), and whether or not the patient had a television (Y/N). Compute the patient's bill and print out an itemized statement similar to the following COMMUNITY HOSPITAL PATIENT BILLING STATEMENT Name: Patient ID Number of days in hospital 5 Type of Room Room Charge: Telephone Charge Television Charge TOTAL DUE: Mary Jones 9523 Private $625.00 $0.00 $17.50 $642.50 BE SURE TO INCLUDE ADEQUATE ERROR CHECKING IN YOUR PROGRAM AND ERROR DATA WHEN YOU RUN THE PROGRAM TO DEMONSTRATE ERROR CHECKING Input Patient name and ld, number of days, room type, telephone option, television option Output ltemized bill of each charge and total owed by the patient. Label all output for readability Be sure your output contains user prompts and what was entered by the user in addition to the results of your program processing Adequately check entered data for validity. Use adequate test data to process all valid data and representative examples of invalid data to show how your program handles invalid dataExplanation / Answer
Answer:
hospital.cpp:
#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;
// Constant values for Charges
const float privateRm = 125.00;
const float semiPrivateRm = 95.00;
const float wardRm = 75.00;
const float phn = 1.75;
const float tv = 3.50;
// function for caleculating room charge based on room type and No. of days.
float caleculateRoomCharge(int days, char type);
int main() {
char name[30];
char roomType;
char phoneOptn;
char tvOptn;
int id;
int numOfDays;
float roomCharge;
float phnCharge;
float tvCharge;
float totalCharge;
cout<<"Enter Name of the patient : ";
cin.get(name,30);
cout<<"Enter ID : ";
cin>>id;
cout<<"No. of days : ";
cin>>numOfDays;
cout<<"Choose Room type (P-Private, S- Semi private, W-Ward *Case sensitive) : ";
cin>>roomType;
// validation for Room type
while( roomType != 'P' && roomType != 'S' && roomType != 'W' ) {
cout<<"----- Invalid room type ----"<<endl;
cout<<"Enter the Room type : ";
cin>>roomType;
}
cout<<" is telephone available? (Y/N) *Case sensitive : ";
cin>>phoneOptn;
// validation for Phone option
while( phoneOptn != 'Y' && phoneOptn != 'N' ) {
cout<<"----- Invalid option ----"<<endl;
cout<<"is telephone available? (Y/N) *Case sensitive: ";
cin>>phoneOptn;
}
cout<<" is telivision available? (Y/N): ";
cin>>tvOptn;
// validation for Telivision option
while( tvOptn != 'Y' && tvOptn != 'N' ) {
cout<<"----- Invalid option ----"<<endl;
cout<<"is telivision available? (Y/N): ";
cin>>tvOptn;
}
//caleculate Room charge
roomCharge = caleculateRoomCharge(numOfDays,roomType);
if (phoneOptn == 'Y'){// Check Phone availablity
phnCharge = numOfDays * phn;
}
else {
phnCharge = 0;
}
if (phoneOptn == 'Y'){// Check Telivision availablity
tvCharge = numOfDays * tv;
}
else {
tvCharge = 0;
}
totalCharge = roomCharge + phnCharge + tvCharge;
cout<<"COMMUNITY HOSPITAL PATIENT BILLING STATEMENT"<<endl;
cout<<setw(5)<<"Name : "<<setw(35)<<name<<endl;
cout<<setw(5)<<"Patient ID :"<<setw(30)<<id<<endl;
cout<<setw(5)<<"No. of days in Hospital :"<<setw(17)<<numOfDays<<endl;
if(roomType == 'P'){
cout<<setw(5)<<"Type of room :"<<setw(28)<<"Private"<<endl;
}else if(roomType == 'S'){
cout<<setw(5)<<"Type of room :"<<setw(28)<<"Semi Private"<<endl;
}else if(roomType == 'W'){
cout<<setw(5)<<"Type of room :"<<setw(28)<<"Ward"<<endl;
}
cout<<setw(5)<<"Room Charge : "<<setw(25)<<"$"<<roomCharge<<endl;
cout<<setw(5)<<"Telephone Charge :"<<setw(20)<<"$"<<phnCharge<<endl;
cout<<setw(5)<<"Telivision Charge :"<<setw(19)<<"$"<<tvCharge<<endl<<endl;
cout<<setw(5)<<"TOTAL DUE :"<<setw(26)<<"$"<<totalCharge<<endl;
return 0;
}
//Function to caleculate Room charge
float caleculateRoomCharge(int days, char type) {
float value;
switch(type){
case 'P' :
value = days * privateRm;
break;
case 'S' :
value = days * semiPrivateRm;
break;
case 'W' :
value = days * wardRm;
break;
}
return value;
};
Output 1:
Enter Name of the patient : Mary Jones
Enter ID : 1234
No. of days : 5
Choose Room type (P-Private, S- Semi private, W-Ward *Case sensitive) : P
is telephone available? (Y/N) *Case sensitive : Y
is telivision available? (Y/N): Y
COMMUNITY HOSPITAL PATIENT BILLING STATEMENT
Name : Mary Jones
Patient ID : 1234
No. of days in Hospital : 5
Type of room : Private
Room Charge : $625
Telephone Charge : $8.75
Telivision Charge : $17.5
TOTAL DUE : $651.25
Output 2:
Enter Name of the patient : Mary jones
Enter ID : 123
No. of days : 5
Choose Room type (P-Private, S- Semi private, W-Ward *Case sensitive) : s
----- Invalid room type ----
Enter the Room type : p
----- Invalid room type ----
Enter the Room type : w
----- Invalid room type ----
Enter the Room type : S
is telephone available? (Y/N) *Case sensitive : n
----- Invalid option ----
is telephone available? (Y/N) *Case sensitive: y
----- Invalid option ----
is telephone available? (Y/N) *Case sensitive: Y
is telivision available? (Y/N): n
----- Invalid option ----
is telivision available? (Y/N): y
----- Invalid option ----
is telivision available? (Y/N): Y
COMMUNITY HOSPITAL PATIENT BILLING STATEMENT
Name : Mary jones
Patient ID : 123
No. of days in Hospital : 5
Type of room : Semi Private
Room Charge : $475
Telephone Charge : $8.75
Telivision Charge : $17.5
TOTAL DUE : $501.25
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.