Using program Visual Studios. C++ : Questions is : Write a program in C to calcu
ID: 3601765 • Letter: U
Question
Using program Visual Studios. C++ :
Questions is :
Write a program in C to calculate the following. Suppose you manage a chain of four hotels. Each hotel charges a different room rate, but all the rooms in given hotel go for the same rate. Rate the Fairfeild arms $180, hotel olympics $225, chertworthy plaza $225, and the stockton $355. For people who book multiple nights, the second night goes for 95% of the first night, the third night goes for 95% of the second night, and so on. Don't worry about the economics of such a ploicy. You want a program that enables you to specify the hotel and number of nights and gives you the cost that many nights. Check for invalid hotel options. You'd like the program to have a menu that enables you to continue entering datd until you choose to quite. Your program must use the following user defined functions.
/*function declarations*/
int getNights(void);
void calculateCost(double rate, int nights);
Explanation / Answer
#include <iostream>
using namespace std;
/*function declarations*/
int getNights(void);
void calculateCost(double rate, int nights);
int main() {
int hotel,nights,rate;
string option = "o";
do
{
cout<<" 1. Fairfeild arms $180";
cout<<" 2. Hotel olympics $225";
cout<<" 3. Chertworthy plaza $225";
cout<<" 4. Stockton $355";
cout<<" Enter the hotel<1-4> :";
cin>>hotel;
nights = getNights();
switch(hotel) //assign rate of different hotels
{
case 1: rate = 180;
break;
case 2: rate = 225;
break;
case 3: rate = 225;
break;
case 4: rate = 355;
break;
default: cout<<" Invalid hotel : ";
break;
}
calculateCost(rate,nights); //function call to calculate cost
cout<<" Do you want to continue[y/n]? : ";
cin>>option;
if(option != "y")
break;
}while(option == "y");
return 0;
}
int getNights(void)
{
int nights;
cout<<" Enter the number of nights to stay : ";
cin>>nights;
return nights;
}
void calculateCost(double rate, int nights)
{
double nextdaycost, totalcost=rate;
int i;
for(i=1;i<nights-1;i++)
{
nextdaycost = totalcost*0.95;
totalcost = totalcost + nextdaycost;
}
cout<<" Cost of hotel stay : $"<<totalcost;
}
output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.