Answer to Question #174012 in C++ for Stalin

Question #174012

Design class Seller to determine whether the seller has made profit or incurred loss. Also determine how much profit he made or loss he incurred. Cost price and selling price of an item is the data member of the class which is input data given by the user. Include the following member function

getItemDetails()- to get item details

dtermineProfitLoss()- to determine whether the seller has made profit or incurred loss

showItemDetails()- to get item details with Profit or loss.

Sample Input and Output

Test cases

Input

Output

Test case 1

800

800

No profit no loss

Test case 2

800

900

profit=100

Test case 3

800

700


1
Expert's answer
2021-03-22T04:33:35-0400
#include <iostream>
#include <string>
class Seller
{
public:
	double costprise;
	double sellingprice;
	std::string profit;
    Seller() {}
	Seller(double costprise, double sellingprice)
		: m_costprice(costprise), m_sellingprice(sellingprice)
	{}
	void dtermineProfitLoss()
	{
		if (m_sellingprice == m_costprice)
			m_profit = "No profit no loss";
		else if (m_sellingprice > m_costprice)
			m_profit = "profit  " + std::to_string(m_sellingprice - m_costprice);
		else if (m_sellingprice < m_costprice)
			m_profit = "loss  " + std::to_string(m_costprice - m_sellingprice);
	}
	void getItemDetails()
	{
		costprise = m_costprice;
		sellingprice = m_sellingprice;
		dtermineProfitLoss();
		profit = m_profit;
	}
	void showItemDetails()
	{
		getItemDetails();
		std::cout << costprise << std::endl;
		std::cout << sellingprice<< std::endl;
		std::cout << profit<< std::endl;
	}
private:
	double m_costprice{0};
	double m_sellingprice{0};
	std::string m_profit;
};

int main()
{
	// example test
	Seller t1(800, 800);
	Seller t2(800, 900);
	Seller t3(800, 700);
	t1.showItemDetails();
	t2.showItemDetails();
	t3.showItemDetails();
    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