Advertisement
L3peha

Untitled

Feb 18th, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class SpacePort
  6. {
  7. public:
  8. SpacePort(unsigned int size);
  9. bool requestLanding(unsigned int dockNumber);
  10. bool requestTakeoff(unsigned int dockNumber);
  11. private:
  12. bool num[100];
  13. unsigned int size;
  14. };
  15.  
  16. SpacePort::SpacePort(unsigned int size)
  17. {
  18. this->size = size;
  19. for (unsigned int i = 0; i < size; i++)
  20. {
  21. this->num[i] = 0;
  22. }
  23. }
  24.  
  25. bool SpacePort::requestLanding(unsigned int dockNumber)
  26. {
  27. if (dockNumber >= this->size|| this->num[dockNumber] ==1||dockNumber<0)
  28. {
  29. return 0;
  30. }
  31. else
  32. {
  33. this->num[dockNumber] = 1;
  34. return 1;
  35. }
  36. }
  37.  
  38. bool SpacePort::requestTakeoff(unsigned int dockNumber)
  39. {
  40. if (dockNumber >= this->size || this->num[dockNumber] == 0 || dockNumber < 0)
  41. {
  42. return 0;
  43. }
  44. else
  45. {
  46. this->num[dockNumber] = 0;
  47. return 1;
  48. }
  49. }
  50.  
  51. int main()
  52. {
  53. SpacePort s(5);
  54. cout << boolalpha << s.requestLanding(0) << endl;
  55. cout << boolalpha << s.requestLanding(4) << endl;
  56. cout << boolalpha << s.requestLanding(5) << endl;
  57.  
  58. cout << boolalpha << s.requestTakeoff(0) << endl;
  59. cout << boolalpha << s.requestTakeoff(4) << endl;
  60. cout << boolalpha << s.requestTakeoff(5) << endl;
  61. return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement