Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sstream>
- using namespace std;
- class CPlant {
- private:
- string name;
- int age;
- float height;
- bool condition;
- float growthrate;
- float numgen;
- float timeflowering;
- public:
- CPlant(string n, int a, float h, bool c, float gr, float ng, float tf) {
- name = n;
- age = a;
- height = h;
- condition = c;
- growthrate = gr;
- numgen = ng;
- timeflowering = tf;
- }
- void getinfo() {
- cout << "Plant " << name << ", " << age << "years old, number of generating oxygen: " << numgen << "Growth rate: " << growthrate << ". Heith: " << height << ". Time of flowering: " << timeflowering << endl;
- }
- void grow(int years) {
- age += years;
- height += growthrate*years;
- }
- void generate(int time) {
- if (condition == true)
- cout << "Plant generate " << time*numgen << "g of oxygen per " << time << "minutes." << endl;
- else
- cout << "Plant sleeps." << endl;
- }
- };
- void main() {
- string n;
- int a;
- float h, gr, ng, tf;
- bool c;
- cout << "Enter specifications of plant (name, age, height condition, growth rate, number of generate oxygen, time of flowering) separated by spaces: ";
- cin >> n >> a >> h >> c >> gr >> ng >> tf;
- CPlant p1(n, a, h, c, gr, ng, tf);
- p1.getinfo();
- cout << "Grow ";
- int years;
- cin >> years;
- p1.grow(years);
- p1.getinfo();
- cout << "Generate time ";
- float time;
- cin >> time;
- p1.generate(time);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement