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. //
  38. //class Cat : public Animal
  39. //{
  40. //public:
  41. // void meow() {
  42. // cout << "meow! meow!" << endl;
  43. // }
  44. //};
  45.  
  46. //.............................polymorphism...............................//
  47.  
  48. //class math {
  49. //public:
  50. // int add(int a, int b) {
  51. // return a + b;
  52. // }
  53. // int add(int a, int b, int c) {
  54. // return a + b + c;
  55. // }
  56. // double add(double a, double b) {
  57. // return a + b;
  58. // }
  59. //};
  60.  
  61. // can i add 2 numbers without tell the data type of the numbers?
  62.  
  63. //.............................abstraction...............................//
  64. //
  65. class coffeeMachine {
  66. public:
  67. void makeCoffee() {
  68. grindCoffee();
  69. heatWater();
  70. brewCoffee();
  71. cout << "Coffee is ready!" << endl;
  72. }
  73.  
  74. private:
  75. void grindCoffee() {
  76. cout << "Grinding coffee beans..." << endl;
  77. }
  78. void heatWater() {
  79. cout << "Heating water..." << endl;
  80. }
  81. void brewCoffee() {
  82. cout << "Brewing coffee..." << endl;
  83. }
  84. };
  85.  
  86. int main()
  87. {
  88. //car mycar;
  89. //mycar.setSpeed(100);
  90. //cout << mycar.getSpeed() << endl;
  91.  
  92. //Dog mydog;
  93. //mydog.bark();
  94. //mydog.eat();
  95. //
  96. //Cat mycat;
  97. //mycat.meow();
  98. //mycat.eat();
  99.  
  100. //math m;
  101. //cout << m.add(5, 10) << endl;
  102. //cout << m.add(5, 10, 15) << endl;
  103. //cout << m.add(5.5, 10.55) << endl;
  104.  
  105. coffeeMachine myCoffeeMachine;
  106. myCoffeeMachine.makeCoffee();
  107.  
  108. return 0;
  109. }
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
Grinding coffee beans...
Heating water...
Brewing coffee...
Coffee is ready!