Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in c++ please. Only the main.cpp file requires a code. 4.15 LAB: Plant information (vector) Given a base Plant class and a derived Flower class,

in c++ please. Only the main.cpp file requires a code.
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
4.15 LAB: Plant information (vector) Given a base Plant class and a derived Flower class, complete main to create a vector called myGarden The vector should be able to store objects that belong to the plant class of the Flower class. Create a function called Print Vector), that uses the Printinfo() functions defined in the respective classes and prints each element in myGarden. The program should read plants or flowers from input (ending with 1), adding each Plant or Flower to the myGarden vector and output each element in myGarden uting the Printinfo) function Ex If the input is plant spirea 10 flower Hydrangea 30 talne lilac flower Home 6 talne white plant Mint 4 -1 the output is Plant Information: Plant name: Spirea Cost: 10 Plant Information: Plant namet Hydrengea Contt 30 Annual: false Color of flowen Hilac the outputs Plant Information Plant name: Spirea Conts 10 Plant Information Plant names Hydrangea Costa Annual: false Color o losers Inc Plant Information Plant namet Rose Cost: Annual: false Color or lowers: white plant Information Plant Dame Mint Costi Load Current file: main.cpp 1 #include "Plant.h" 2 #include "Flower.h" 3 #include 5 #include 6 7 using namespace std; 8 9 void Print Vector(vector myGarden) { 10 for (size_t i = 0; i 14) 15 16 int main(int arec, char *arev) 17 vector myGardens 18 19 string plantName; 20 int plantCost; Develop mode Submit mode Run your program as often as you'd like, before submitting for grading Below input values in the first box, then click Run program and observe the program's second box Current file: main.cpp 21 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 string flowerName; int flowerCost; string isAnnual; string colorOfFlowers; string input; cin >> input; while (input 1"-1") if (input = "plant") { cin >> plantName>> plantCost; p.SetPlantName(plantName); p.SetPlantcost(plant Cost); myGarden.push_back(new Plant()); 2 else if (input "Flower) cin >> flower Name >> flowerCost >> is Annual >> colorOfFlowers Flower f; f.SetPlantName(flowerliame); Catant Cartet Plant Di Current file: main.cpp 42 44 45 46 47 T. ET LUWU); f.SetPlant Cost (flowerCost); if (isAnnual "false") { f.SetPlantType(false); else { f.SetPlantType(true); 2 f.setColorOfFlowers (colorOfFlowers); myGarden.push_back(new Flower (f)); 1 cin >> input; 49 50 51 52 53 1 56 57 Print Vector (myGarden); for (size_t i = 0; i 5 using namespace std; 5 7 class Plant B public: 9 virtual -Plant(); 10 11 void SetPlantName(string userplante); 12 13 string Get PlantName() const: 14 15 void SetPlantcost(int user Plant Cost): 16 17 int Get Plant Cost) const; 1 19 virtual vold PrintInfo() const; 20 21 protected: strine plantione: 21 int plant Costi 25 26 endir File is marked as read only Current file: Plant.cpp 1 include "Plant." 2 #include 3 4 Plant: :-Plant) 0); S 6 void Plant::SetPlantName(string userPlantae) 7 plantae - userPlantrame; 8) 9 10 string Plant::GetPlantae) const 11 return plantime 12) 13 10 void Planttiset Plant Cost(int user Plant Cost) 15 plant Cost userPlantcost; 16) 17 18 int Plant Plant Cost const 19 return plantCost: 20) 21 12 vold Plant PrintInfo const 23 cout using namespace std; 7 class Flower poblic Plant 9 public te void SetPlant Type(bool user is Annual); 11 bool Get PlantType() const, 13 14 void Set Coloroflowers(string userColorofflowers), 15 10 string GetColororFlowers const; 17 void PrintInfo() const: 19 20 private 21 bool is Annual string colorOfFlowers: 23 ) 24 25 Fendi File is marked as read only Current file: Flower.cpp 1 #include "Flower." 2 include 3 4 void Flower :: SetPlant Type(bool userIsAnnual) 5 isAnnual = userIsAnnual 6) 7 8 bool Flower:GetPlant Type() const { 9 return is Annual 10) 11 12 vold Flower SetColoroflowers(string userColorOfFlowers) ( colorFlower's userColorofflowers; 14 ) 16 string Flowers GetColorOfFlowers) const 17 return colorOfFlowers; 18) 19 20 vold Flower::PrintInfo() const 21 cout

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems On GPUs In Databases

Authors: Johns Paul ,Shengliang Lu ,Bingsheng He

1st Edition

1680838482, 978-1680838480

More Books

Students also viewed these Databases questions

Question

Understand the historical shifts of civic engagement.

Answered: 1 week ago