using c build a class named Candy and the subclasses Chocola

using c++ build a class named Candy and the subclasses Chocolate, Fruit, and Sour using inheritance. The name of the candy and the price are included in the Candy class. The child classes should all indicate how it tastes (chocolaty, fruity, and sour).

Solution

abstract class Candy

{

private:

double price;

String name;

public:

abstract void getTaste();

void setPrice(double p)

{

price=p;

}

void setName(String s)

{

name=s;

}

}

class Chocolate:public Candy

{

public:

String getTaste()

{

return \"chocolaty\";

}

}

class Fruit:public Candy

{

public:

String getTaste()

{

return \"Fruity\";

}

}

class Sour:public Candy

{

public:

String getTaste()

{

return \"sour\";

}

}

using c++ build a class named Candy and the subclasses Chocolate, Fruit, and Sour using inheritance. The name of the candy and the price are included in the Can
using c++ build a class named Candy and the subclasses Chocolate, Fruit, and Sour using inheritance. The name of the candy and the price are included in the Can

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site