fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. //.............................encapsulation...............................//
  5. class car {
  6. private:
  7. int speed;
  8.  
  9. public:
  10. car() {
  11. speed = 0;
  12. }
  13. void setSpeed(int s) {
  14. speed = s;
  15. }
  16. int getSpeed() {
  17. return speed;
  18. }
  19. };
  20.  
  21. //.............................inheritance...............................//
  22.  
  23. //class Animal {
  24. //public:
  25. // void eat() {
  26. // cout << "Eating..." << endl;
  27. // }
  28. //};
  29. //
  30. //class Dog : public Animal
  31. //{
  32. //public:
  33. // void bark() {
  34. // cout << "woof! woof!" << endl;
  35. // }
  36. //};
  37. //.............................polymorphism...............................//
  38.  
  39. //class math {
  40. //public:
  41. // int add(int a, int b) {
  42. // return a + b;
  43. // }
  44. // int add(int a, int b, int c) {
  45. // return a + b + c;
  46. // }
  47. // double add(double a, double b) {
  48. // return a + b;
  49. // }
  50. //};
  51.  
  52. // can i add 2 numbers without tell the data type of the numbers?
  53.  
  54. //.............................abstraction...............................//
  55. //
  56. //class coffeeMachine {
  57. //public:
  58. // void makeCoffee() {
  59. // grindCoffee();
  60. // heatWater();
  61. // brewCoffee();
  62. // cout << "Coffee is ready!" << endl;
  63. // }
  64. //
  65. //private:
  66. // void grindCoffee() {
  67. // cout << "Grinding coffee beans..." << endl;
  68. // }
  69. // void heatWater() {
  70. // cout << "Heating water..." << endl;
  71. // }
  72. // void brewCoffee() {
  73. // cout << "Brewing coffee..." << endl;
  74. // }
  75. //};
  76.  
  77. int main()
  78. {
  79. car mycar;
  80. mycar.setSpeed(100);
  81. cout << mycar.getSpeed() << endl;
  82.  
  83. //Dog mydog;
  84. //mydog.bark();
  85. //mydog.eat();
  86.  
  87. //math m;
  88. //cout << m.add(5, 10) << endl;
  89. //cout << m.add(5, 10, 15) << endl;
  90. //cout << m.add(5.5, 10.55) << endl;
  91.  
  92. //coffeeMachine myCoffeeMachine;
  93. //myCoffeeMachine.makeCoffee();
  94.  
  95. return 0;
  96. }
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
100