Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <clocale>
- #include <windows.h>
- #include <vector>
- #include <conio.h>
- using namespace std;
- template <typename Type>
- Type MagicInput(Type input) // Ввод с проверкой
- {
- while (!(cin >> input) || (cin.peek() != '\n'))
- {
- cin.clear(); while (cin.get() != '\n');
- cout << "Ошибка ввода. Попробуйте еще раз.\n";
- }
- return input;
- }
- void SetLucidaFont()
- {
- HANDLE hCon = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
- if (hCon != INVALID_HANDLE_VALUE) {
- CONSOLE_FONT_INFOEX cfi;
- cfi.cbSize = sizeof(CONSOLE_FONT_INFOEX);
- cfi.nFont = 0;
- cfi.dwFontSize.X = 0;
- cfi.dwFontSize.Y = 12;
- cfi.FontFamily = FF_DONTCARE;
- cfi.FontWeight = 400;
- wcscpy_s(cfi.FaceName, L"Lucida Console");
- SetCurrentConsoleFontEx(hCon, FALSE, &cfi);
- }
- }
- class House
- {
- private:
- string Address;
- int Floor;
- int RoomsCount;
- float Area;
- public:
- House() {};
- House(string address, int floor, int roomsCount, float area) : Address(address), Floor(floor), RoomsCount(roomsCount), Area(area) {};
- void Show()
- {
- cout << endl << "Адресс: " << Address << "; этаж: " << Floor << "; количество комнат: " << RoomsCount << "; площадь: " << Area;
- }
- string getAddress() { return Address; }
- int getFloor() { return Floor; }
- int getRoomsCount() { return RoomsCount; }
- float getArea() { return Area; }
- void setAddress(string address) { Address = address; }
- void setFloor(int floor) { Floor = floor; }
- void setRoomsCount(int roomsCount) { RoomsCount = roomsCount; }
- void setArea(float area) { Area = area; }
- };
- void Pause()
- {
- cout << endl;
- system("pause");
- system("cls");
- }
- void InputHouse(vector <House> &Houses)
- {
- cin.clear();
- cin.sync();
- House house;
- cout << endl << "Введите адресс: ";
- string address;
- getline(cin, address);
- house.setAddress(address);
- cout << "Введите этаж: ";
- house.setFloor(MagicInput((int)0));
- cout << "Введите количество комнат: ";
- house.setRoomsCount(MagicInput((int)0));
- cout << "Введите площадь: ";
- house.setArea(MagicInput((float)0));
- Houses.push_back(house);
- Pause();
- }
- void OutputAllHouses(vector <House> &Houses)
- {
- for (int i = 0; i < (int)Houses.size(); i++)
- Houses[i].Show();
- Pause();
- }
- void OutputByFilterFirst(vector <House> &Houses)
- {
- cin.clear();
- cin.sync();
- cout << endl << "Введите количество комнат для поискового фильтра1(от 1 до 100000): ";
- int roomsCount = 0;
- do
- {
- roomsCount = MagicInput(roomsCount);
- } while (roomsCount <= 0 || roomsCount > 100000);
- for (int i = 0; i < (int)Houses.size(); i++)
- {
- if (roomsCount == (int)(Houses[i].getRoomsCount()))
- Houses[i].Show();
- }
- Pause();
- }
- void OutputByFilterSecond(vector <House> &Houses)
- {
- cin.clear();
- cin.sync();
- cout << endl << "Введите количество комнат для поискового фильтра2(от 1 до 100000): ";
- int roomsCount = 0;
- do
- {
- roomsCount = MagicInput(roomsCount);
- } while (roomsCount <= 0 || roomsCount > 100000);
- cout << endl << "Введите провежуток этажей: ";
- cout << endl << "Введите минимальный этаж: ";
- int floorMin = MagicInput((int)0);
- cout << endl << "Введите максимальный этаж: ";
- int floorMax = MagicInput((int)0);
- for (int i = 0; i < (int)Houses.size(); i++)
- {
- if (roomsCount == Houses[i].getRoomsCount() && (int)Houses[i].getFloor() >= floorMin && (int)Houses[i].getFloor() <= floorMax)
- Houses[i].Show();
- }
- Pause();
- }
- void Menu()
- {
- system("cls");
- cout << "---Выберите опцию: ";
- cout << endl << "1. Добавить здание";
- cout << endl << "2. Вывод всех зданий";
- cout << endl << "3. Вывод по фильтру 1";
- cout << endl << "4. Вывод по фильтру 2";
- cout << endl << "ESC. Выход";
- }
- int main()
- {
- SetLucidaFont();
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- vector <House> Houses;
- while (true)
- {
- Menu();
- switch (_getch())
- {
- case 49: InputHouse(Houses); // 1
- break;
- case 50: OutputAllHouses(Houses); // 2
- break;
- case 51: OutputByFilterFirst(Houses); // 3
- break;
- case 52: OutputByFilterSecond(Houses); // 4
- break;
- case 27: //ESC
- return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment