25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

126 satır
1.8 KiB

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