Advertisement
Waliul

Fan (Shajed)

Jun 8th, 2021
951
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.74 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. class Fan
  5. {
  6. private:
  7.     int speed;
  8.     bool isOn;
  9.     double radius;
  10.     string color;
  11. public:
  12.     const int SLOW = 1, MEDIUM = 2, FAST = 3;
  13.     Fan()
  14.     {
  15.         speed = SLOW;
  16.         isOn = false;
  17.         radius = 5;
  18.         color = "blue";
  19.     }
  20.     void setSpeed(int spd)
  21.     {
  22.         speed = spd;
  23.     }
  24.     void setOn()
  25.     {
  26.         isOn = true;
  27.     }
  28.     void setRadius(double rds)
  29.     {
  30.         radius = rds;
  31.     }
  32.     void setColor(string clr)
  33.     {
  34.         color = clr;
  35.     }
  36.  
  37.     string getSpeed()
  38.     {
  39.         if(speed == SLOW)
  40.             return "SLOW";
  41.         if(speed == MEDIUM)
  42.             return "MEDIUM";
  43.         if(speed == FAST)
  44.             return "FAST";
  45.     }
  46.     bool getIsOn()
  47.     {
  48.         return isOn;
  49.     }
  50.     double getRadius()
  51.     {
  52.         return radius;
  53.     }
  54.     string getColor()
  55.     {
  56.         return color;
  57.     }
  58.  
  59.     string toString()
  60.     {
  61.         string str;
  62.         if(isOn)
  63.         {
  64.             str = str + "Speed : " + getSpeed() + "\n";
  65.             str = str + "Color : " + getColor() + "\n";
  66.             str = str + "Radius : " + to_string(getRadius()) + "\n\n";
  67.         }
  68.         else
  69.         {
  70.             str = str + "Color : " + getColor() + "\n";
  71.             str = str + "Radius : " + to_string(getRadius()) + "\n";
  72.             str = str + "fan is off\n\n";
  73.         }
  74.         return str;
  75.     }
  76. };
  77.  
  78. int main()
  79. {
  80.     Fan fan1, fan2;
  81.  
  82.     fan1.setSpeed(fan1.FAST);
  83.     fan1.setRadius(10);
  84.     fan1.setColor("yellow");
  85.     fan1.setOn();
  86.  
  87.     fan2.setSpeed(fan2.MEDIUM);
  88.     fan2.setRadius(5);
  89.     fan2.setColor("blue");
  90.  
  91.     cout<<fan1.toString();
  92.     cout<<fan2.toString();
  93.     return 0;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement