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:
int quantity;
float price;
public:
float expense, discount;
int total_amount;
bool discounted;
Market(){
}
Market(int q, float p){
quantity = q;
price = p;
total_amount = quantity * price;
discounted = total_amount > 5000;
if(discounted){
expense = total_amount * 0.9;
discount = 0.1 * total_amount;
}
else expense = total_amount;
}
void display(){
cout<<"\nTotal Amount: "<<total_amount;
if(discounted){
cout<<"\nDiscount: "<<discount;
cout<<"\nAmount to Pay: "<<expense;
}
else{
cout<<"\nDiscount: 0";
cout<<"\nAmount to Pay: "<<expense;
}
}
};
int main(){
Market M;
int q;
float p;
cout<<"Enter quantity: ";
cin>>q;
cout<<"Enter price per item: ";
cin>>p;
M = Market(q, p);
M.display();
return 0;
}
Comments
Leave a comment