Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3.  
  4. using namespace std;
  5.  
  6. class CPlant {
  7. private:
  8.     string name;
  9.     int age;
  10.     float height;
  11.     bool condition;
  12.     float growthrate;
  13.     float numgen;
  14.     float timeflowering;
  15. public:
  16.     CPlant(string n, int a, float h, bool c, float gr, float ng, float tf) {
  17.         name = n;
  18.         age = a;
  19.         height = h;
  20.         condition = c;
  21.         growthrate = gr;
  22.         numgen = ng;
  23.         timeflowering = tf;
  24.     }
  25.     void getinfo() {
  26.         cout << "Plant " << name << ", " << age << "years old, number of generating oxygen: " << numgen << "Growth rate: " << growthrate << ". Heith: " << height << ". Time of flowering: " << timeflowering << endl;
  27.     }
  28.     void grow(int years) {
  29.         age += years;
  30.         height += growthrate*years;
  31.     }
  32.     void generate(int time) {
  33.         if (condition == true)
  34.             cout << "Plant generate " << time*numgen << "g of oxygen per " << time << "minutes." << endl;
  35.         else
  36.             cout << "Plant sleeps." << endl;
  37.     }
  38. };
  39.  
  40. void main() {
  41.     string n;
  42.     int a;
  43.     float h, gr, ng, tf;
  44.     bool c;
  45.     cout << "Enter specifications of plant (name, age, height condition, growth rate, number of generate oxygen, time of flowering) separated by spaces: ";
  46.     cin >> n >> a >> h >> c >> gr >> ng >> tf;
  47.     CPlant p1(n, a, h, c, gr, ng, tf);
  48.     p1.getinfo();
  49.     cout << "Grow ";
  50.     int years;
  51.     cin >> years;
  52.     p1.grow(years);
  53.     p1.getinfo();
  54.     cout << "Generate time ";
  55.     float time;
  56.     cin >> time;
  57.     p1.generate(time);
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement