Computers and Technology
Computers and Technology, 10.05.2021 19:30, 9tpompey

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;
}

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 22:00, AshlynPlayz45
Which one of the following would administrators use to connect to a remote server securely for administration? a. telnetb. secure file transfer protocol (sftp)c. secure copy (scp)d. secure shell (ssh)
Answers: 1
image
Computers and Technology, 22.06.2019 15:30, coollid876
To increase sales, robert sends out a newsletter to his customers each month, letting them know about new products and ways in which to use them. in order to protect his customers' privacy, he uses this field when addressing his e-mail. attach bcc forward to
Answers: 2
image
Computers and Technology, 23.06.2019 01:20, shiann2002
Me with this program in c++ ! computers represent color by combining sub-colors red, green, and blue (rgb). each sub-color's value can range from 0 to 255. thus (255, 0, 0) is bright red. (130, 0, 130) is a medium purple. (0, 0, 0) is black, (255, 255, 255) is white, and (40, 40, 40) is a dark gray. (130, 50, 130) is a faded purple, due to the (50, 50, 50) gray part. (in other word, equal amounts of red, green, blue yield gray).given values for red, green, and blue, remove the gray part. ex: if the input is 130 50 130, the output is: 80 0 80. thus, find the smallest value, and then subtract it from all three values, thus removing the gray.
Answers: 3
image
Computers and Technology, 24.06.2019 02:00, arubright177
Write an expression that will cause the following code to print "equal" if the value of sensorreading is "close enough" to targetvalue. otherwise, print "not equal". ex: if targetvalue is 0.3333 and sensorreading is (1.0/3.0), output is:
Answers: 1
Do you know the correct answer?
Given a base Plant class and a derived Flower class, complete main() to create a vector called myGar...

Questions in other subjects: