Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

Vehicle.cpp 2.2 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #include <string>
  2. #include "Vehicle.hpp"
  3. using namespace std;
  4. Vehicle::Vehicle(int length, int width, int id)
  5. {
  6. type = "TBA";
  7. origin = "TBA";
  8. destination = "TBA";
  9. dateNtime = "TBA";
  10. this->length = length;
  11. this->width = width;
  12. this->id = id;
  13. initialize();
  14. }
  15. Vehicle::Vehicle(string type, int length, int width, string origin, string destination, string dateNtime, int id)
  16. {
  17. this->type = type;
  18. this->length = length;
  19. this->width = width;
  20. this->origin = origin;
  21. this->destination = destination;
  22. this->dateNtime = dateNtime;
  23. this->id = id;
  24. initialize();
  25. }
  26. Vehicle::Vehicle(string type, int length, int width, string origin, string destination, string dateNtime, int id, vector< vector<int> > seatMap)
  27. {
  28. this->type = type;
  29. this->length = length;
  30. this->width = width;
  31. this->origin = origin;
  32. this->destination = destination;
  33. this->dateNtime = dateNtime;
  34. this->id = id;
  35. this->seatMap = seatMap;
  36. }
  37. void Vehicle::setType(string type)
  38. {
  39. this->type = type;
  40. }
  41. void Vehicle::setOrigin(string origin)
  42. {
  43. this->origin = origin;
  44. }
  45. void Vehicle::setDestination(string destination)
  46. {
  47. this->destination = destination;
  48. }
  49. string Vehicle::getType()
  50. {
  51. return type;
  52. }
  53. int Vehicle::getLength()
  54. {
  55. return length;
  56. }
  57. int Vehicle::getWidth()
  58. {
  59. return width;
  60. }
  61. string Vehicle::getOrigin()
  62. {
  63. return origin;
  64. }
  65. string Vehicle::getDestination()
  66. {
  67. return destination;
  68. }
  69. string Vehicle::getDateNTime()
  70. {
  71. return dateNtime;
  72. }
  73. int Vehicle::getId()
  74. {
  75. return id;
  76. }
  77. void Vehicle::initialize()
  78. {
  79. for (int i = 0; i < length; i++)
  80. {
  81. vector<int> row;
  82. for (int j = 0; j < width; j++)
  83. {
  84. row.push_back(-1);
  85. }
  86. seatMap.push_back(row);
  87. }
  88. }
  89. bool Vehicle::bookSeat(int x, int y, int guestId)
  90. {
  91. if (seatMap[x][y] == -1)
  92. {
  93. seatMap[x][y] = guestId;
  94. return true;
  95. }
  96. return false;
  97. }
  98. bool Vehicle::checkAvailabilty(int x, int y)
  99. {
  100. return seatMap[x][y] == -1;
  101. }
  102. void Vehicle::printMap(int guestId)
  103. {
  104. for (int i = 0; i < length; i++)
  105. {
  106. for (int j = 0; j < width; j++)
  107. {
  108. if (seatMap[i][j] == -1)
  109. {
  110. cout << "A ";
  111. }
  112. else if (seatMap[i][j] == guestId)
  113. {
  114. cout << "U ";
  115. }
  116. else
  117. {
  118. cout << "X ";
  119. }
  120. }
  121. cout << endl;
  122. }
  123. }