Create a class product, take appropriate data members and functions which calculate net profit for a product after selling the product.
#include <iostream>
using namespace std;
class Product{
float price, cost, profit;
public:
Product(){}
void setPrice(float f){
price = f;
}
void setCost(float f){
cost = f;
}
void calcProfit(){
profit = price - cost;
}
float displayPrice(){
return price;
}
float displayCost(){
return cost;
}
float displayProfit(){
return profit;
}
};
int main(){
Product SonyXM4;
SonyXM4.setCost(455.99);
SonyXM4.setPrice(500.99);
SonyXM4.calcProfit();
cout<<"The net profit for an item that costs "<<SonyXM4.displayCost()<<" and sold at "
<<SonyXM4.displayPrice()<<" is "<<SonyXM4.displayProfit();
return 0;
}
Comments
Leave a comment