$8.00 C++ code
- From Computer-Science: General-CS
- Closed, but you can still post tutorials
- Due on Nov. 24, 0000
- Asked on Nov 21, 2011 at 3:52:05PM
Project: The purpose of this sixth project is to write a program that uses value returning functions. This project will differ from previous projects in that we will take a program that is already written and rewrite it using value returning functions.
Problem: Take a working version of Project #4 and rewrite it using value returning functions.
Please read all of the specifications that follow prior writing your program:
- Objective - the objective of this project is to be sure that everyone is able to use value returning functions in a program.
Important Notes
Your program must contain comments at the top of the program explaining the purpose of the program and also prior to each of the functions to explain the purpose of each function
-
Create the following value returning functions (you can choose your own function names)
-
getdays - send no information to this function, return the number of days stayed
-
-
getroom - send no information to this function, return the room type (P, S, or W)
-
getphone - send no information to this function, return the phone option (Y or N)
-
gettv - send no information to this function, return the tv option (Y or N)
-
calcroomchg - send this function the room type and the number of days stayed and return the room charge
-
calcphonechg - send this function the phone option and the number of days stayed and return the phone charge
-
calctvchg - send this function the tv option and the number of days stayed and return the tv charge
-
calctotaldue - send this function the room charge, phone charge, and tv charge and return the total due
-
The cout statements that display the bill at the end of the program can remain inside main
-
For each function you need to provide a function definition, prototype, and function call from main
Starting Code
// Filename: project5.cpp
// The purpose of this program is to calculate charges for a patient's stay in the hospital
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
// Constants
const double PRIVATECOST = 200;
const double SEMIPRIVATECOST = 150;
const double WARDCOST = 100.00;
const double PHONECOST = 1.75;
const double TVCOST = 3.50;
int main ()
{
// Variables
char roomtype, phoneoption, tvoption;
int daysstayed;
double roomcharge, phonecharge, tvcharge, totaldue;
//Get information from user
cout << "Enter the number of days stayed: ";
cin >> daysstayed;
cout << "Enter the type of room (P for private, S for semi-private, W for ward): ";
cin >> roomtype;
cout << "Telephone Option (Y for yes, N for no): ";
cin >> phoneoption;
cout <<"Televison Option (Y for yes, N for no): ";
cin >> tvoption;
// Calculate charges
switch(roomtype)
{
case 'P':
case 'p': roomcharge = PRIVATECOST * daysstayed; break;
case 'S':
case 's': roomcharge = SEMIPRIVATECOST * daysstayed; break;
case 'W':
case 'w': roomcharge = WARDCOST * daysstayed; break;
}
if (phoneoption == 'Y' || phoneoption == 'y')
phonecharge = PHONECOST * daysstayed;
else
phonecharge = 0;
if (tvoption == 'Y' || tvoption == 'y')
tvcharge = TVCOST * daysstayed;
else
tvcharge = 0;
totaldue = roomcharge + phonecharge + tvcharge;
// Display results
cout << fixed << showpoint << setprecision(2) << endl;
cout << "Community Hospital" << endl;
cout << "Patient Billing Statement" << endl << endl;
cout << "Number of days in hospital: " << daysstayed << endl << endl;
cout << "Type of room: ";
switch(roomtype)
{
case 'P':
case 'p': cout << "Private"; break;
case 'S':
case 's': cout << "Semi Private"; break;
case 'W':
case 'w': cout << "Ward"; break;
}
cout<< endl << endl;
cout << setw(25) << left << "Room Charge " << '$'
<< setw(8) << right << roomcharge << endl;
cout << setw(25) << left << "Telephone Charge" << '$'
<< setw(8) << right << phonecharge << endl;
cout << setw(25) << left << "Television Charge" << '$'
<< setw(8) << right << tvcharge << endl << endl;
cout << setw(25) << left << "Total Due" << '$'
<< setw(8) << right << totaldue << endl;
system("pause");
return 0;
}
PLEASE DO ONLY AS THE PROJECT MENTIONS. DO NOT USE CODE THAT IS MORE ADVANCED THAN IN THE BOOK C++ Programming,Malik 5th edition Chapter 6. Also please send me a message If you have any questions
- This tutorial hasn't been purchased yet.
- Posted on Nov 21, 2011 at 10:11:37PM
