Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- class Fan
- {
- private:
- int speed;
- bool isOn;
- double radius;
- string color;
- public:
- const int SLOW = 1, MEDIUM = 2, FAST = 3;
- Fan()
- {
- speed = SLOW;
- isOn = false;
- radius = 5;
- color = "blue";
- }
- void setSpeed(int spd)
- {
- speed = spd;
- }
- void setOn()
- {
- isOn = true;
- }
- void setRadius(double rds)
- {
- radius = rds;
- }
- void setColor(string clr)
- {
- color = clr;
- }
- string getSpeed()
- {
- if(speed == SLOW)
- return "SLOW";
- if(speed == MEDIUM)
- return "MEDIUM";
- if(speed == FAST)
- return "FAST";
- }
- bool getIsOn()
- {
- return isOn;
- }
- double getRadius()
- {
- return radius;
- }
- string getColor()
- {
- return color;
- }
- string toString()
- {
- string str;
- if(isOn)
- {
- str = str + "Speed : " + getSpeed() + "\n";
- str = str + "Color : " + getColor() + "\n";
- str = str + "Radius : " + to_string(getRadius()) + "\n\n";
- }
- else
- {
- str = str + "Color : " + getColor() + "\n";
- str = str + "Radius : " + to_string(getRadius()) + "\n";
- str = str + "fan is off\n\n";
- }
- return str;
- }
- };
- int main()
- {
- Fan fan1, fan2;
- fan1.setSpeed(fan1.FAST);
- fan1.setRadius(10);
- fan1.setColor("yellow");
- fan1.setOn();
- fan2.setSpeed(fan2.MEDIUM);
- fan2.setRadius(5);
- fan2.setColor("blue");
- cout<<fan1.toString();
- cout<<fan2.toString();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement