Advertisement
BojidarDosev

Untitled

Jun 13th, 2024
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <iomanip>
  5.  
  6. using namespace std;
  7.  
  8. struct Quarter {
  9.  
  10. string name;
  11. double area;
  12. int population;
  13. };
  14.  
  15. struct City {
  16. string name;
  17. int population;
  18. vector <Quarter> quarters;
  19. };
  20.  
  21. struct Apartment {
  22. double area;
  23. int floor;
  24. int rooms;
  25. string address;
  26. double price;
  27. bool hasElevator;
  28. Quarter quarter;
  29. };
  30.  
  31. int main()
  32. {
  33. City sofia = { "Sofia", 1300000,{
  34. {"Ovcha Kupel", 4.5, 50000},
  35. {"Manastirski livadi", 3.0, 30000},
  36. {"Krasno Selo", 6.0, 60000}
  37. }};
  38.  
  39. City plovdiv = { "Plovdiv", 400000,{
  40. {"Kapana", 1.5,15000},
  41. {"Center", 2.0,200000}
  42. }};
  43.  
  44. vector<Apartment> apartments = {
  45. {80, 2, 3, "st. Narodno Horo 84, Ovcha Kupel, Sofia", 250000, true,
  46. sofia.quarters[0]},
  47. {90, 11, 3, "st. Golemo Malko 23, Manastirski livadi, Sofia", 600000,
  48. true, sofia.quarters[1]},
  49. {45, 1, 1, "st. Paco Rabana 3, Kapana, Plovdiv", 50000, false,
  50. plovdiv.quarters[0]},
  51. {30, 2, 1, "st. Strashen 5, Center, Plovdiv", 75000,
  52. false, plovdiv.quarters[1]},
  53. {150, 2, 4, "st. White Holes, Krasno Selo, Sofia", 1000000, true,
  54. sofia.quarters[2]}
  55. };
  56.  
  57. string desiredCity, desiredQuarter;
  58. int desiredFloor, desiredRooms;
  59. double desiredBudget;
  60.  
  61. //Client criteria
  62. getline(cin, desiredCity);
  63. getline(cin, desiredQuarter);
  64. cin >> desiredFloor >> desiredRooms >> desiredBudget;
  65.  
  66. bool found = false;
  67.  
  68. //filter
  69.  
  70. for (const auto& apartment : apartments)
  71. {
  72.  
  73. bool cityMatch = (desiredCity == "No type" || apartment.address.find(desiredCity) != string::npos);
  74. bool quarterMatch = (desiredQuarter == "No type" || apartment.quarter.name == desiredQuarter);
  75. bool floorMatch = (apartment.hasElevator || apartment.floor <= desiredFloor);
  76. bool roomsMatch = (apartment.rooms >= desiredRooms);
  77. bool budgetMatch = (apartment.price <= desiredBudget);
  78.  
  79. if (cityMatch && quarterMatch && (floorMatch || apartment.hasElevator) && roomsMatch && budgetMatch)
  80. {
  81. cout << fixed << setprecision(0);
  82. cout << apartment.address << ", " << apartment.area << "m2, " << apartment.floor << " floor, " << apartment.rooms << " rooms, " << apartment.price << " euro" << endl;
  83. found = true;
  84. }
  85.  
  86. if (!found)
  87. {
  88. cout << "No suitable apartments found." << endl;
  89. }
  90. }
  91.  
  92. return 0;
  93. }
  94.  
  95.  
  96.  
  97.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement