Answer to Question #283967 in C++ for rjc

Question #283967

Consider a class Fruit that contains o A data member named as Fruit Name of string type o A data member named as Quantity of type int o A data member named price-per-kg of type double o A member function displayprice(Fruit) that shows the price of the instrument while evaluating the name of the instrument object that it accepts as a reference parameter Derive two classes named Mango and Watermelon from the class Fruit that contain o A parameterized constructor to initialize data members that they inherit from the class Fruit


1
Expert's answer
2021-12-31T15:43:37-0500
#include <iostream>
#include <string>
using namespace std;


class Fruit{
    string Name;
    int Quantity;
    double price_per_kg;


    public:
    Fruit(){}
    Fruit(string name, int quantity, double price): 
        Name(name), 
        Quantity(quantity), 
        price_per_kg(price)
        {}
    void displayprice(Fruit& f){
        cout<<price_per_kg<<endl;
        cout<<"Name of passed Fruit: "<<f.Name<<endl;
    }
};
class Mango: public Fruit{
    public:
    Mango(int quantity, double price): Fruit("Mango", quantity, price){}
};
class Watermelon: public Fruit{
    public:
    Watermelon(int quantity, double price): Fruit("Watermelon", quantity, price){}
};

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