Answer to Question #174175 in C++ for Harini.M

Question #174175

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

loss=100



1
Expert's answer
2021-03-25T03:03:49-0400
#include <iostream>
using namespace std;
class Seller{
    int cost_price, selling_price;
    bool profit = false, loss = false, no_PorL = false;
    public:
    Seller(){}
    void getItemDetails(int a, int b){
        cost_price = a;
        selling_price = b;
    }
    void determineProfitLoss(){
        if(selling_price - cost_price > 0)
            profit = true;
        else if(selling_price - cost_price < 0)
            loss = true;
        else no_PorL = true;
    }
    void showItemDetails(){
        cout<<"\nCost Price = "<<cost_price<<endl;
        cout<<"Selling Price = "<<selling_price<<endl;
        if(profit)
            cout<<"Profit = "<<selling_price - cost_price<<endl;
        if(loss)
            cout<<"Loss = "<<cost_price - selling_price<<endl;
        if(no_PorL)
            cout<<"No profit no loss";
    }
};
int main(){
    int x, y;
    Seller seller;
    cout<<"Enter cost price: ";
    cin>>x;
    cout<<"Enter selling price: ";
    cin>>y;
    seller.getItemDetails(x, y);
    seller.determineProfitLoss();
    seller.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