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
#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;
}
Comments
Leave a comment