fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. // book a room for meeting and return the name of the room booked
  4. // History of meetings booked
  5. // api which string meeting_room_scheduled(start,end)
  6. // -->if already booked
  7. // a.) change room
  8. // b.) change timings
  9. class Meeting;
  10. class Room;
  11. bool clash(vector<int> a, vector<int> b)
  12. {
  13. return max(a[0], b[0]) <= min(a[1], b[1]);
  14. }
  15.  
  16. class Meeting
  17. {
  18. private:
  19. int start, end;
  20. Room room;
  21.  
  22. public:
  23. Meeting(int _start, int _end, Room _room)
  24. {
  25. start = _start;
  26. end = _end;
  27. room = _room;
  28. }
  29. vector<int> get_interval()
  30. {
  31. vector<int> x = {start, end};
  32. return x;
  33. }
  34. };
  35. class Room
  36. {
  37. private:
  38. string name;
  39. vector<Meeting> calendar;
  40.  
  41. public:
  42. Room()
  43. {
  44. name = "";
  45. calendar = vector<Meeting>();
  46. }
  47. Room(string _name)
  48. {
  49. name = _name;
  50. calendar = vector<Meeting>();
  51. }
  52. string get_name()
  53. {
  54. return name;
  55. }
  56. vector<Meeting> get_calendar()
  57. {
  58. return calendar;
  59. }
  60. bool book(int _start, int _end)
  61. {
  62. vector<int> new_interval = {_start, _end};
  63. bool ok = true;
  64. for (Meeting &i : calendar)
  65. {
  66. vector<int> temp = i.get_interval();
  67. if (clash(temp, new_interval))
  68. ok = false;
  69. }
  70. if (ok == false)
  71. return false;
  72. calendar.push_back(Meeting(_start, _end, this));
  73. //cout<<calendar.size()<<"\n";
  74. return true;
  75. }
  76. };
  77.  
  78. class Scheduler
  79. {
  80. public:
  81. vector<Room> rooms;
  82. bool book(int start, int end, string room_id)
  83. {
  84. if(start>=end)
  85. return false;
  86. for (auto &i : rooms)
  87. {
  88. if (i.get_name() == room_id && i.book(start, end))
  89. {
  90. return true;
  91. }
  92. }
  93. return false;
  94. }
  95. };
  96. void print(Room room)
  97. {
  98. auto x=room.get_calendar();
  99. for(auto j: x)
  100. {
  101. cout<<j.get_interval()[0]<<" "<<j.get_interval()[1]<<"\n";
  102. }
  103. }
  104. int main()
  105. {
  106. Scheduler scheduler;
  107. for (int i = 0; i < 5; i++)
  108. {
  109. string name = "x" + to_string(i);
  110. scheduler.rooms.push_back(Room(name));
  111. }
  112. if (scheduler.book(1, 10, "x1"))
  113. {
  114. cout << "[SUCCESS]: Meeting scheduled successfully\n";
  115. }
  116. else
  117. {
  118. cout << "[ERROR]: Unexpected error\n";
  119. }
  120.  
  121. if (scheduler.book(4, 10, "x1"))
  122. {
  123. cout << "[SUCCESS]: Meeting scheduled successfully\n";
  124. }
  125. else
  126. {
  127. cout << "[ERROR]: Unexpected error\n";
  128. }
  129. if (scheduler.book(18, 19, "x1"))
  130. {
  131. cout << "[SUCCESS]: Meeting scheduled successfully\n";
  132. }
  133. else
  134. {
  135. cout << "[ERROR]: Unexpected error\n";
  136. }
  137. if (scheduler.book(1, 111, "x1"))
  138. {
  139. cout << "[SUCCESS]: Meeting scheduled successfully\n";
  140. }
  141. else
  142. {
  143. cout << "[ERROR]: Unexpected error\n";
  144. }
  145. if (scheduler.book(41, 42, "x1"))
  146. {
  147. cout << "[SUCCESS]: Meeting scheduled successfully\n";
  148. }
  149. else
  150. {
  151. cout << "[ERROR]: Unexpected error\n";
  152. }
  153. if (scheduler.book(1, 2, "x2"))
  154. {
  155. cout << "[SUCCESS]: Meeting scheduled successfully\n";
  156. }
  157. else
  158. {
  159. cout << "[ERROR]: Unexpected error\n";
  160. }
  161.  
  162. if (scheduler.book(4, 10, "x2"))
  163. {
  164. cout << "[SUCCESS]: Meeting scheduled successfully\n";
  165. }
  166. else
  167. {
  168. cout << "[ERROR]: Unexpected error\n";
  169. }
  170.  
  171. print(scheduler.rooms[1]);
  172. cout<<"===\n";
  173. print(scheduler.rooms[2]);
  174.  
  175. return 0;
  176. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:20:10: error: field ‘room’ has incomplete type ‘Room’
     Room room;
          ^~~~
prog.cpp:10:7: note: forward declaration of ‘class Room’
 class Room;
       ^~~~
prog.cpp:23:40: error: ‘_room’ has incomplete type
     Meeting(int _start, int _end, Room _room)
                                   ~~~~~^~~~~
prog.cpp:10:7: note: forward declaration of ‘class Room’
 class Room;
       ^~~~
prog.cpp: In member function ‘bool Room::book(int, int)’:
prog.cpp:72:54: error: no matching function for call to ‘Meeting::Meeting(int&, int&, Room*)’
         calendar.push_back(Meeting(_start, _end, this));
                                                      ^
prog.cpp:23:5: note: candidate: ‘Meeting::Meeting(int, int, Room)’
     Meeting(int _start, int _end, Room _room)
     ^~~~~~~
prog.cpp:23:5: note:   no known conversion for argument 3 from ‘Room*’ to ‘Room’
prog.cpp:16:7: note: candidate: ‘constexpr Meeting::Meeting(const Meeting&)’
 class Meeting
       ^~~~~~~
prog.cpp:16:7: note:   candidate expects 1 argument, 3 provided
prog.cpp:16:7: note: candidate: ‘constexpr Meeting::Meeting(Meeting&&)’
prog.cpp:16:7: note:   candidate expects 1 argument, 3 provided
stdout
Standard output is empty