Answer to Question #157551 in C++ for dee

Question #157551

Write a C++ program that contain the following

functions:


a) Function travelCharge(char,int,int): this function will calculate and return the traveling

cost based on the given table.


Vacation Places Places ID Adult (RM) Children (RM)

Pangkor Island P 350 175

Bukit Merah B 200 100

Teluk Batik T 80 40


b) Function hotelCharge(int,int): this function will receives vacation packages as input

from the user. Then, calculate and return the hotel charge. The hotel charge (per room) is

based on the given table.

Vacation Packages Package ID Price per day and per room (RM)

Deluxe D 430

Standard S 270

Economy E 100


c) Write the main program to input the customer’s name, vacation places (P, B or T), number

of adults in the group, number of children in the group, number of days going for vacation

and number of hotel rooms booked. Then, by using functions above, calculate the cost for

travel and hotel. Finally, display the total payment a customer has to pay.


1
Expert's answer
2021-01-22T11:52:27-0500
#include<iostream>
using namespace std;
//FUNCTION DEFINTION OF TRAVEL CHARGE THAT CONSIST THREE PARAMETER AND RETURN TYPE IS INTEGER
int travel_charge(char place, int number_of_adults, int number_of_children)
{       int travelcost;
//CHECK CONDITION IF PLACE IS P
        if(place=='p' || place=='P')
        {
        travelcost=number_of_adults*350+number_of_children*175;  //CALCULATE TRAVEL COST
        }
        //CHECK CONDITION IF PLACE IS B
        else if(place=='b' || place=='B')
        {
        travelcost=number_of_adults*200+number_of_children*100; 
        }
        //CHECK CONDITION IF PLACE IS T
        else if(place=='t' || place=='T')
        {
        travelcost=number_of_adults*80+number_of_children*40;   
        }
        //CHECK CONDITION IF PLACE IS WRONG ENTERED
        else
        {
                cout<<"YOU HAVE ENTERED THE WRONG CHOICE\n";
                cout<<"\n TRAVEL CHARGE CANNOT BE CALCULATED\n";
        }
        //return te value of travel cost variable
        return travelcost;
}
//function hotel charge that comsist three parameter and return type is integer
int hotel_charge(char roomid,int number_of_days,int number_of_rooms)
{
        int hotelcost;
        //CHECK CONDITION IF ROOM ID IS D
        if(roomid=='d' || roomid=='D')
        {
        hotelcost=430*number_of_days*number_of_rooms;
        }
        //CHECK CONDITION IF ROOM ID IS S
        else if(roomid=='s' || roomid=='S')
        {
        hotelcost=270*number_of_days*number_of_rooms;
        }
        //CHECK CONDITION IF ROOM ID IS E
        else if(roomid=='e' || roomid=='E')
        {
        hotelcost=100*number_of_days*number_of_rooms;
        }
        //CHECK CONDITION IF ROOM ID WRONGLY ENTERED
        else
        {
                cout<<"\nYOU HAVE ENTERED THE WRONG CHOICE";
                cout<<"\nHOTEL CHARGE CANNOT BE CALCULATED\n";
        }
        return hotelcost;
}
int main()
{       //VARIABLE DECLARATION
        char name[30],place,category;
        int adult,child,day,room,a,b,total_amount;
        //ENTER CUSTOMER NAME, VACATION PLACE, NUMBER OF ADULT,NUMBER OF CHILDEREN,ROOM TYPE, NUMBER OF ROOMS, NUMBER OF DAYS
        cout<<"ENTER THE CUSTOMER NAME==";
        gets(name);
        cout<<"ENTER THE VACATION PLACE(P,B,T)==";
        cin>>place;
        cout<<"ENTER THE NUMBER OF ADULT IN THE GROUP==";
        cin>>adult;
        cout<<"ENTER THE NUMBER OF CHILDREN IN THE GROUP==";
        cin>>child;
        cout<<"ENTER THE NUMBER OF DAYS==";
        cin>>day;
        cout<<"ENTER THE CATEOGRY OF ROOM(D,S,E)==";
        cin>>category;
        cout<<"ENTER THE NUMBER OF ROOMS==";
        cin>>room;
        //CALL TRAVEL_CHARGE FUNCTION THAT RETURN A VALUE OF INTEGER TYPE AND STORED IN VARIABLE A
        a=travel_charge(place,adult,child);
        cout<<"COST OF TRAVEL CHARGE==="<<a;
        //CALL HOTEL_CHARGE FUNCTION THAT RETURN A VALUE OF INTEGER TYPE AND STORED IN VARIABLE B
        b=hotel_charge(category,day,room);
                cout<<"\n COST OF hotel CHARGE==="<<b;
                //CALCULATE TOTAL AMOUNT 
                total_amount=a+b;
                //PRINT THE VALUE OF TOTAL AMOUNT
                        cout<<"\n\nHELLO DEAR CUSTOME  "<<name<<"  TOTAL AMOUNT PAID TO YOU======"<<total_amount;
        
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog