Answer to Question #173281 in C++ for Praveen Kumar b

Question #173281

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.


1
Expert's answer
2021-03-22T01:59:04-0400
#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;
}

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