Prepare a C++ program that implements modular programming and value returning function to solve the following problem.
Melur Spa and Beauty is an agency that provides service for facial and body treatments with reasonable package and price. The service provided as in Table 1. The table contains Treatment , Package , Price in Ringgit Malaysia (RM).
Table 1:
Treatment 1 - Body
Package and Price for treatment 1 - Massage (RM120) , Scrub (RM150).
Treatment 2 - Facial
Package and Price for treatment 2 - Refreshing (RM80) , Hydra Facial (RM100).
Customer can choose any package and treatment provided in the menu and your program can calculates the price need to be paid by the customer. 10% discount will be given if the total price is RM200 and above whereas 5% discount will be given if the total price is more than RM150. Total price and discount should be calculated in value returning function. Then, your program will display the total price, the discount rate and the nett price paid by the customer.
#include <iostream>
using namespace std;
float calculateDiscount(float price){
float discount = 0;
if(price >= 200) discount = 0.1;
else if(price > 150) discount = 0.05;
return discount;
}
float calculatePrice(float price){
return price * (1 - calculateDiscount(price));
}
int main(){
int choice, choice2;
float price = 0, discount, netprice;
do{
cout<<"\nTreatment 1 - Body\n";
cout<<"Treatment 2 - Facial\n";
cin>>choice;
switch(choice){
case 1: cout<<"\nPackage and Price for treatment 1\n1. Massage (RM120)\n2. Scrub(RM150)\n";
cin>>choice2;
switch(choice2){
case 1: price += 120; break;
case 2: price += 150; break;
default: break;
}
break;
case 2: cout<<"\nPackage and Price for treatment 2\n1. Refreshing (RM80)\n2. Hydra Facial (RM150)\n";
cin>>choice2;
switch(choice2){
case 1: price += 80; break;
case 2: price += 150; break;
default: break;
}
break;
default: break;
}
cout<<"\nAdd another package?\n1. yes\n2. no\n";
cin>>choice2;
if(choice2 == 2) break;
}while(true);
discount = 100 * calculateDiscount(price);
netprice = calculatePrice(price);
cout<<"\nTotal Price: "<<price<<endl;
cout<<"Discount: "<<discount<<"%"<<endl;
cout<<"Net Price: "<<netprice<<endl;
return 0;
}
Comments
Leave a comment