subject

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 or the Flower class. Create a function called PrintVector(), 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 using the PrintInfo() function. Ex. If the input is:
plant Spirea 10
flower Hydrangea 30 false lilac
flower Rose 6 false white
plant Mint 4
-1
the output is:
Plant Information:
Plant name: Spirea
Cost: 10
Plant Information:
Plant name: Hydrengea
Cost: 30
Annual: false
Color of flowers: lilac
Plant Information:
Plant name: Rose
Cost: 6
Annual: false
Color of flowers: white
Plant Information:
Plant name: Mint
Cost: 4
main. cpp
#include "Plant. h"
#include "Flower. h"
#include "Plant. cpp"
#include "Flower. cpp"
#include
#include
#include
using namespace std;
// TODO: Define a PrintVector function that prints an vector of plant (or flower) object pointers
void PrintVector(vector myGarden)
{
for(int i=0; i {
if(typeid(Flower)==typeid(myGarden[ i]))
(dynamic_cast(myGarden[i]))->Pri ntInfo();
else
myGarden[i]->PrintInfo();
cout< }
}
int main(int argc, char* argv[]) {
// TODO: Declare a vector called myGarden that can hold object of type plant pointer
vector myGarden;
// TODO: Declare variables - plantName, plantCost, flowerName, flowerCost,
// colorOfFlowers, isAnnual
string plantName, flowerName, colorOfFlowers, isann;
bool isAnnual;
int plantCost, flowerCost;
string input;
Flower *flower;
Plant *plant;
cin >> input;
while(input != "-1") {
// TODO: Check if input is a plant or flower
if (input=="plant")
{
cin>>plantName;
cin>>plantCost;
plant = new Plant();
plant->SetPlantName(plantName);< br /> plant->SetPlantCost(plantCost);< br /> myGarden. push_back(plant);
}
else if(input=="flower")
{
cin>>flowerName;
cin>>flowerCost;
cin>>isann;
isAnnual = (isann=="true");
cin>>colorOfFlowers;
flower = new Flower();
flower->SetPlantName(flowerName) ;
flower->SetPlantCost(flowerCost) ;
flower->SetPlantType(isAnnual);< br /> flower->SetColorOfFlowers(colorO fFlowers);
myGarden. push_back(flower);
}
// Store as a plant object or flower object
// Add to the vector myGarden
cin >> input;
}
// TODO: Call the method PrintVector to print myGarden
PrintVector(myGarden);
for (size_t i = 0; i < myGarden. size(); ++i) {
delete myGarden. at(i);
}
return 0;
}

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 23:00
Computer programming is one type of what career
Answers: 1
question
Computers and Technology, 24.06.2019 01:30
Write a program that asks the user to enter the name of an input file. if the file does not exist, the program should prompt the user to enter the file name again. if the user types quit in any uppercase/lowercase combinations, then the program should exit without any further output.
Answers: 3
question
Computers and Technology, 24.06.2019 13:00
Which one of the following functions is not available on the autosum tool? sum average if max
Answers: 3
question
Computers and Technology, 24.06.2019 14:30
Which computer network component connects two different networks together and allows them to communicate? a is a node (or a device) that connects two different networks together and allows them to communicate.
Answers: 1
You know the right answer?
Given a base Plant class and a derived Flower class, complete main() to create a vector called myGar...
Questions
question
English, 23.11.2020 23:00
question
Chemistry, 23.11.2020 23:00
question
Mathematics, 23.11.2020 23:00
Questions on the website: 13722363