Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <multipleplants.h>
- using namespace std;
- int main()
- {
- int choice;
- void clrScr(); // clears the screen
- void menu(); // shows the menu
- // std::vector<Plant*> vec; // vector of plants
- Plant *temp;
- return 0;
- }
- //plant.h
- #ifndef PLANT_H
- #define PLANT_H
- #include <iostream>
- #include <vector>
- enum { HERB = 1, BUSH, TREE, PRINT, EXIT };
- class Plant {
- private:
- std::string name; // name of plant
- std::string origin; // country of origin
- double height; // height in meters
- protected:
- static int plantCounter; // the num of existing plants
- public:
- Plant(); // constructor without arguments
- virtual void input() = 0; // input info
- virtual void output() = 0; // output info
- virtual ~Plant(); // virtual destructor
- static std::vector<Plant*> vec;
- static int getPlantsNum(); // get the value of plantCounter
- };
- #endif // PLANT_H
- //plant.cpp
- #include "plant.h"
- int Plant::plantCounter = 0;
- Plant::Plant() :
- name(""), origin(""), height(0) {
- plantCounter++;
- }
- void Plant::input() {
- std::cout << "Enter the plant info, plx:\n";
- std::cout << "Name: "; std::cin >> name;
- std::cout << "Origin: "; std::cin >> origin;
- std::cout << "Height: "; std::cin >> height;
- }
- void Plant::output() {
- std::cout << "\t" <<name
- << "\t" << origin
- << "\t" << height;
- }
- int Plant::getPlantsNum() { return plantCounter; }
- Plant::~Plant() {
- plantCounter--;
- }
- //multiplePlants.h
- #ifndef MULTIPLEPLANTS_H
- #define MULTIPLEPLANTS_H
- #include <iostream>
- #include <plant.h>
- typedef unsigned int UI;
- class Herb : public Plant {
- private:
- std::string petalsColor; // color of petals
- UI age; // 1..n year aged herbs
- public:
- Herb(); // constructor without arguments
- void input(); // input herb info
- void output(); // output herb info
- ~Herb(); // destructor
- };
- class Tree: public Plant {
- private:
- std::string fruit; // type of fruit
- std::string type; // <evergreen/coniferous/deciduous>
- public:
- Tree(); // constructor without arguments
- void input(); // input tree info
- void output(); // output tree info
- ~Tree(); // destructor
- };
- class Bush: public Plant {
- private:
- std::string soil; // needed soil
- double tempResistance; // temperature resistance
- public:
- Bush(); // constructor without parameters
- void input(); // input bush info
- void output(); // output bush info
- ~Bush(); // destructor
- };
- #endif // MULTIPLEPLANTS_H
- //multiplePlants.cpp
- #include "multipleplants.h"
- std::vector<Plant*> vec;
- //herb description
- Herb::Herb() :
- Plant(), petalsColor(""), age(0) {
- vec.push_back(this);
- std::cout << "Created new herb.\n";
- }
- Herb::~Herb()
- { std::cout << "Deleted herb.\n"; }
- void Herb::input() {
- Plant::input();
- std::cout << "Petals color: "; std::cin >> petalsColor;
- std::cout << "Ages: "; std::cin >> age;
- }
- void Herb::output() {
- Plant::output();
- std::cout << "\t" << petalsColor << "\t" << age
- << "\t-\t-\t-\t-" << std::endl;
- }
- // bush description
- Bush::Bush() :
- Plant(), soil(""), tempResistance(0)
- { std::cout << "Created new bush.\n"; }
- Bush::~Bush()
- { std::cout << "Deleted bush.\n"; }
- void Bush::input() {
- Plant::input();
- std::cout << "Needed soil: "; std::cin >> soil;
- std::cout << "Temperature: "; std::cin >> tempResistance;
- }
- void Bush::output() {
- Plant::output();
- std::cout << "\t-\t-\t" << soil << "\t" << tempResistance
- << "\t-\t-" << std::endl;
- }
- //tree description
- Tree::Tree() :
- Plant(), fruit(""), type("")
- { std::cout << "Created new tree.\n";}
- Tree::~Tree()
- { std::cout << "Deleted tree.\n";}
- void Tree::input() {
- Plant::input();
- std::cout << "Type of fruit: "; std::cin >> fruit;
- std::cout << "Type of tree: "; std::cin >> type;
- }
- void Tree::output() {
- Plant::output();
- std::cout << "\t-\t-\t-\t-\t" << fruit
- << "\t" << type << std::endl;
- }
- void menu() {
- std::cout << "-------------------------------" << std::endl
- << "Number of all elements: "
- << Tree::getPlantsNum() << std::endl;
- std::cout << "1. New herb" << std::endl
- << "2. New bush" << std::endl
- << "3. New tree" << std::endl
- << "4. Print all info" << std::endl
- << "5. Exit" << std::endl;
- }
- void clrScr() {
- std::cout << "\033[2J\033[1;1H";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement