/*
Design a class Market to calculate the total expenses.
The quantity and price per item are input by the user in base class and
the derived class calculate the discount of 10% is offered if
the expense is more than 5000 in derived class.
Display the total expenses using single inheritance.
*/
#include <iostream>
using namespace std;
class Market{ //defining a class
private:
int quantity;
float price;
public:
float exp, disc;
int amount_in_total;
bool discounted;
Market(){
}
/*
the derived class calculate the discount of 10% is offered if
the expense is more than 5000 in derived class
*/
Market(int q, float p){
quantity = q;
price = p;
amount_in_total = quantity * price;
discounted = amount_in_total > 5000;
if(discounted){
exp = amount_in_total * 0.9;
disc = 0.1 * amount_in_total;
}
else exp = amount_in_total;
}
void display(){ //the calling of base class input The quantity and price per item
cout<<"\nTotal Amount: "<<amount_in_total;
if(discounted){
cout<<"\nDiscount: "<<disc;
cout<<"\nTotal Expenses: "<<exp;
}
else{
cout<<"\nDiscount: 0";
cout<<"\nTotal Expenses: "<<exp;
}
}
};
int main(){
Market M;
int q;
float p;
cout<<"Input the quantity: ";
cin>>q;
cout<<"Input price per item: ";
cin>>p;
M = Market(q, p);
M.display();
return 0;
}
Comments
Leave a comment