Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
Code :
1. #include <iostream>
2. using namespace std;
3. string lights,lever;
4. void setLightsRed(){
5. lights = "Red";
6. }
7. void setLightsGreen(){
8. lights= "Green";
9. }
10. void setLightsOff(){
11. lights = "Off";
12. }
13. string getLights(){
14. return lights;
15. }
16. void setLeverUp(){
17. lever = "Up";
18. }
19. void setLeverDown(){
20. lever = "Down";
21. }
22. string getLever(){
23. return lever;
24. }
25. string takeOff()
26. {
27. if(getLights() != "Red" )
28. return "Can't take off because lights are not red\n";
29. setLeverUp();
30. setLightsOff();
31. return "Take Off Success\n";
32. }
33. string landing()
34. {
35. if(getLights() != "Green" )
36. return "Can't land because lights are not Green\n";
37. setLeverDown();
38. return "Landing Success\n";
39. }
40. int main()
41. {
42. setLightsRed();
43. cout<<takeOff();
44. setLightsGreen();
45. cout<<landing();
46. return 0;
47. }