In: Computer Science
Write a discount system for a spa, which provides services and sells products. It offers 3 types of memberships: Premium, Gold and Silver. Premium, gold and silver members receive a discount of 18%, 12%, and 10%, respectively (this might change in future), for all services provided. Customers without membership receive no discount. All members receive a flat 10% discount on products purchased (this might change in future). Your system shall consist of four classes: Customer, Discount, Visit,Product and Services. It shall compute the total bill if a customer purchases $x of products and $y of services, for a visit. Also write a test program to exercise all the services.
Acceptance Criteria
As a user, I should be able to interact with the application interactively.
Note :
This Problem is implemented in c++
Source Code:
#include <iostream>
using namespace std;
class Customer{
protected: string name;
int m;
Customer(){
m=0;
}
public:
int membership() // Function that takes value for Membership
{
cout<<"1.Premium\n2.Gold\n3.Silver\n4.Without Member ship\n";
cout<<"Enter your Membership Number : ";
cin>>m;
return m;
}
};
class ProductAndService
{
protected : int ch,ch2;
public:
int product() // Member Function that calculate the total price of product customer want to buy
{
double price = 0;
while(ch!=4){
cout<<"\n\n--------------------- PRODUCT LIST -------------------\n";
cout<<"1.Hair Wax($10)\n2.Shampoo($15)\n3.Face Wash($20)\n----------4.Not Want to Buy----------\n";
cout<<"Enter Product Number:";
cin>>ch;
if(ch==1)price+=10;
else if(ch==2)price+=15;
else if(ch==3)price+=20;
}
return price; // Return Product Price
}
int service(){ // Member Function that calculate Total service price
double price = 0;
while(ch2!=6){
cout<<"\n\n ------------------- SERVICE LIST----------------------";
cout<<"\n1.Hair Cutting($5)\n2.Shave($5)\n3.De-tannng($10)\n4.massage($10)\n5.Facial($20)\n-----------6.Not want to buy-----------";
cout<<"\nEnter your choice:";
cin>>ch2;
if(ch2==1)price+=5;
if(ch2==2)price+=5;
if(ch2==3)price+=10;
if(ch2==4)price+=10;
if(ch2==5)price+=20;
}
return price; // Return Service Price
}
};
/* Discount Class Inherits the two class publically
one is Customer and
second is ProductAndService
*/
class Discount : public Customer , public ProductAndService
{
protected :
double mDiscount; // membership Discount
double FlatDiscount; // Flat Discount;
public:
Discount()
{
FlatDiscount = 10;
}
void checkCustomer() // Check Customer Membership and add membership discount
{
int d;
d = membership(); //Calls Membership function of class Customer
switch(d){
case 1 : mDiscount = 18; break;
case 2 : mDiscount =12; break;
case 3: mDiscount = 10; break;
case 4: mDiscount =0; break;
default : mDiscount = 0;
}
}
void CalculateDiscount()
{
checkCustomer(); // Call checkCustomer method
double ProductBill,ServiceBill;
ProductBill = product(); // calls product() Function of ProductAndService class which return the bill of products
ServiceBill = service(); // calls service() Function of ProductAndService class which returns the bill of services
double TotalBill;
//TotalBill = (ProductBill+ServiceBill)*(FlatDiscount/100)*(mDiscount/100);
TotalBill = ServiceBill +ProductBill;
double f,m;
f=(TotalBill*(FlatDiscount/100));
m = (TotalBill*(mDiscount/100));
cout<<"\nTotal Bill is $"<<TotalBill;
cout<<"\nDiscount : $ "<<f;
cout<<"\nDiscount(Membership) : $"<<m;
cout<<"\nBill After Discount : $"<<TotalBill - f-m;
}
};
class visit : public Discount // Vist class Inherits the Discount class
{
public:
void VisitCustomer()
{
cout<<"------------------- Welcome -------------------";
cout<<"\nMake Sure you enter Correct Choice otherwise program will be stopped and you need to Re-Execute\n";
CalculateDiscount(); // Calls CalculateDiscount() Function of Discount class for further activities
}
};
int main()
{
visit v1; // Declare object of class visit
char a;
while(a!='n')
{
v1.VisitCustomer();
cout<<"\nDo you Want to Continue(y/n)";
cin>>a;
}
cout<<"--------------- Thankyou For Coming ---------------\n\n";
cout<<"--------------- Visit Again ---------------";
return 0;
}
Output:
.
.
.
.
.
.
.
.
Class Diagram:
.
.
.
If you have any type of error Explain in Comment Section
Thumbs up if you are satisfied.
Thankyou