Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a new class called Flower. Flower is subclassed from the Plant class; so

ID: 3766662 • Letter: C

Question

Create a new class called Flower. Flower is subclassed from the Plant class; so besides name, and leaves, it adds 2 new attributes; color, petals. Color is a string that contains the color of the flower, and petals is an in that has the number of petals on the flower. You should create an-init-method to setup the instance. With the init you should make an UNBOUND method call to plant to setup the name and height. In addition, create a method called pick_petal that decrements the number of petals on the flower.

Explanation / Answer

class Plant
{
public:
   char name[20];
   float height;
   void plant(char n[], float h)
   {
       strcpy(name, n);
       height=h;
   }
};
class Flower : Plant
{
public:
   char color[20];
   int petals;
   Flower(char c[], int p)
   {
       strcpy(color,c);
       petals=p;
       plant("Rose",12.5);
   }
   void pick_petal()
   {
       petals--;
   }
};

  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote