Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <iomanip>
- using namespace std;
- struct Quarter {
- string name;
- double area;
- int population;
- };
- struct City {
- string name;
- int population;
- vector <Quarter> quarters;
- };
- struct Apartment {
- double area;
- int floor;
- int rooms;
- string address;
- double price;
- bool hasElevator;
- Quarter quarter;
- };
- int main()
- {
- City sofia = { "Sofia", 1300000,{
- {"Ovcha Kupel", 4.5, 50000},
- {"Manastirski livadi", 3.0, 30000},
- {"Krasno Selo", 6.0, 60000}
- }};
- City plovdiv = { "Plovdiv", 400000,{
- {"Kapana", 1.5,15000},
- {"Center", 2.0,200000}
- }};
- vector<Apartment> apartments = {
- {80, 2, 3, "st. Narodno Horo 84, Ovcha Kupel, Sofia", 250000, true,
- sofia.quarters[0]},
- {90, 11, 3, "st. Golemo Malko 23, Manastirski livadi, Sofia", 600000,
- true, sofia.quarters[1]},
- {45, 1, 1, "st. Paco Rabana 3, Kapana, Plovdiv", 50000, false,
- plovdiv.quarters[0]},
- {30, 2, 1, "st. Strashen 5, Center, Plovdiv", 75000,
- false, plovdiv.quarters[1]},
- {150, 2, 4, "st. White Holes, Krasno Selo, Sofia", 1000000, true,
- sofia.quarters[2]}
- };
- string desiredCity, desiredQuarter;
- int desiredFloor, desiredRooms;
- double desiredBudget;
- //Client criteria
- getline(cin, desiredCity);
- getline(cin, desiredQuarter);
- cin >> desiredFloor >> desiredRooms >> desiredBudget;
- bool found = false;
- //filter
- for (const auto& apartment : apartments)
- {
- bool cityMatch = (desiredCity == "No type" || apartment.address.find(desiredCity) != string::npos);
- bool quarterMatch = (desiredQuarter == "No type" || apartment.quarter.name == desiredQuarter);
- bool floorMatch = (apartment.hasElevator || apartment.floor <= desiredFloor);
- bool roomsMatch = (apartment.rooms >= desiredRooms);
- bool budgetMatch = (apartment.price <= desiredBudget);
- if (cityMatch && quarterMatch && (floorMatch || apartment.hasElevator) && roomsMatch && budgetMatch)
- {
- cout << fixed << setprecision(0);
- cout << apartment.address << ", " << apartment.area << "m2, " << apartment.floor << " floor, " << apartment.rooms << " rooms, " << apartment.price << " euro" << endl;
- found = true;
- }
- if (!found)
- {
- cout << "No suitable apartments found." << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement