File tree 2 files changed +53
-1
lines changed
2 files changed +53
-1
lines changed Original file line number Diff line number Diff line change @@ -26,4 +26,5 @@ add_subdirectory(plant-care-better)
26
26
#add_executable(isp_door_better2 ISP/isp_door_example_better2.cpp)
27
27
#add_executable(isp_device ISP/isp_device_example.cpp)
28
28
#add_executable(isp_device_better ISP/isp_device_example_better.cpp)
29
- add_executable (isp_multiple_inheritance ISP/isp_multiple_inheritance.cpp)
29
+ #add_executable(isp_multiple_inheritance ISP/isp_multiple_inheritance.cpp)
30
+ add_executable (dip_lamp DIP/dip_lamp_example.cpp)
Original file line number Diff line number Diff line change
1
+ //
2
+ // Created by sajith on 4/23/21.
3
+ //
4
+
5
+ #include < iostream>
6
+
7
+ class Lamp
8
+ {
9
+ public:
10
+ void switchOn ()
11
+ {
12
+ std::cout << " Lamp is on\n " ;
13
+ }
14
+
15
+ void switchOff ()
16
+ {
17
+ std::cout << " Lamp is off\n " ;
18
+ }
19
+ };
20
+
21
+ class Button
22
+ {
23
+ Lamp &lamp;
24
+ bool on = false ;
25
+
26
+ public:
27
+ Button (Lamp &lamp) : lamp{lamp} {}
28
+
29
+ void toggle ()
30
+ {
31
+ if (on)
32
+ {
33
+ lamp.switchOff ();
34
+ } else
35
+ {
36
+ lamp.switchOn ();
37
+ }
38
+
39
+ on = !on;
40
+ }
41
+ };
42
+
43
+ int main ()
44
+ {
45
+ Lamp lamp;
46
+ Button button (lamp);
47
+ button.toggle ();
48
+ button.toggle ();
49
+
50
+ return 0 ;
51
+ }
You can’t perform that action at this time.
0 commit comments