Design a class Market to calculate the total expenses. Use appropriate member functions
i) The quantity and price per item are the data member of the class which is input by the user
2) discount of 10% is offered if the expense is more than 5000.
3) Calculate the total expenses
4) Display total amount, discount and Amount to pay
#include <iostream>
using namespace std;
class Market {
private:
//The quantity and price per item are the data member of the class which is input by the user
int quantity;
float pricePerItem;
public:
Market (){}
void input(){
cout<<"Enter the quantity: ";
cin>>quantity;
cout<<"Enter the price per item: ";
cin>>pricePerItem;
}
void calculateTotalExpenses(){
//3) Calculate the total expenses
float totalExpenses=quantity*pricePerItem;
//2) discount of 10% is offered if the expense is more than 5000.
float discount=0;
if(totalExpenses>=5000){
discount=totalExpenses*0.1;
}
float amountPay=totalExpenses+discount;
//4) Display total amount, discount and Amount to pay
cout << "The total amount: " << totalExpenses << "\n";
cout << "The discount of 10%: " << discount << "\n";
cout << "The amount to pay: " << amountPay << "\n";
}
};
int main (){
Market market;
market.input();
market.calculateTotalExpenses();
system("pause");
return 0;
}
Comments
Leave a comment