Answer to Question #173447 in C++ for praveenkumar.b

Question #173447

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-24T01:24:27-0400
#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;
}

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