Answer to Question #252860 in C++ for Jagan

Question #252860
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.
1
Expert's answer
2021-10-18T03:51:15-0400
/*
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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS