Answer to Question #184760 in C++ for jainab

Question #184760

 Create a class product, take appropriate data members and functions which calculate net profit for a product after selling the product.


1
Expert's answer
2021-04-23T14:13:48-0400
#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;
}

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