PhotoShaman

Laba17

Mar 14th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <clocale>
  4. #include <windows.h>
  5. #include <vector>
  6. #include <conio.h>
  7.  
  8. using namespace std;
  9.  
  10. template <typename Type>
  11. Type MagicInput(Type input) // Ввод с проверкой
  12. {
  13.     while (!(cin >> input) || (cin.peek() != '\n'))
  14.     {
  15.         cin.clear(); while (cin.get() != '\n');
  16.         cout << "Ошибка ввода. Попробуйте еще раз.\n";
  17.     }
  18.     return input;
  19. }
  20.  
  21. void SetLucidaFont()
  22. {
  23.     HANDLE hCon = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
  24.     if (hCon != INVALID_HANDLE_VALUE) {
  25.         CONSOLE_FONT_INFOEX cfi;
  26.         cfi.cbSize = sizeof(CONSOLE_FONT_INFOEX);
  27.         cfi.nFont = 0;
  28.         cfi.dwFontSize.X = 0;
  29.         cfi.dwFontSize.Y = 12;
  30.         cfi.FontFamily = FF_DONTCARE;
  31.         cfi.FontWeight = 400;
  32.         wcscpy_s(cfi.FaceName, L"Lucida Console");
  33.         SetCurrentConsoleFontEx(hCon, FALSE, &cfi);
  34.     }
  35. }
  36.  
  37. class House
  38. {
  39. private:
  40.     string Address;
  41.     int Floor;
  42.     int RoomsCount;
  43.     float Area;
  44. public:
  45.     House() {};
  46.     House(string address, int floor, int roomsCount, float area) : Address(address), Floor(floor), RoomsCount(roomsCount), Area(area) {};
  47.     void Show()
  48.     {
  49.         cout << endl << "Адресс: " << Address << "; этаж: " << Floor << "; количество комнат: " << RoomsCount << "; площадь: " << Area;
  50.     }
  51.     string getAddress() { return Address; }
  52.     int getFloor() { return Floor; }
  53.     int getRoomsCount() { return RoomsCount; }
  54.     float getArea() { return Area; }
  55.     void setAddress(string address) { Address = address; }
  56.     void setFloor(int floor) { Floor = floor; }
  57.     void setRoomsCount(int roomsCount) { RoomsCount = roomsCount; }
  58.     void setArea(float area) { Area = area; }
  59. };
  60.  
  61. void Pause()
  62. {
  63.     cout << endl;
  64.     system("pause");
  65.     system("cls");
  66. }
  67.  
  68. void InputHouse(vector <House> &Houses)
  69. {
  70.     cin.clear();
  71.     cin.sync();
  72.     House house;
  73.     cout << endl << "Введите адресс: ";
  74.     string address;
  75.     getline(cin, address);
  76.     house.setAddress(address);
  77.     cout << "Введите этаж: ";
  78.     house.setFloor(MagicInput((int)0));
  79.     cout << "Введите количество комнат: ";
  80.     house.setRoomsCount(MagicInput((int)0));
  81.     cout << "Введите площадь: ";
  82.     house.setArea(MagicInput((float)0));
  83.     Houses.push_back(house);
  84.     Pause();
  85. }
  86.  
  87. void OutputAllHouses(vector <House> &Houses)
  88. {
  89.     for (int i = 0; i < (int)Houses.size(); i++)
  90.         Houses[i].Show();
  91.     Pause();
  92. }
  93.  
  94. void OutputByFilterFirst(vector <House> &Houses)
  95. {
  96.     cin.clear();
  97.     cin.sync();
  98.     cout << endl << "Введите количество комнат для поискового фильтра1(от 1 до 100000): ";
  99.     int roomsCount = 0;
  100.     do
  101.     {
  102.         roomsCount = MagicInput(roomsCount);
  103.     } while (roomsCount <= 0 || roomsCount > 100000);
  104.     for (int i = 0; i < (int)Houses.size(); i++)
  105.     {
  106.         if (roomsCount == (int)(Houses[i].getRoomsCount()))
  107.             Houses[i].Show();
  108.     }
  109.     Pause();
  110. }
  111.  
  112. void OutputByFilterSecond(vector <House> &Houses)
  113. {
  114.     cin.clear();
  115.     cin.sync();
  116.     cout << endl << "Введите количество комнат для поискового фильтра2(от 1 до 100000): ";
  117.     int roomsCount = 0;
  118.     do
  119.     {
  120.         roomsCount = MagicInput(roomsCount);
  121.     } while (roomsCount <= 0 || roomsCount > 100000);
  122.     cout << endl << "Введите провежуток этажей: ";
  123.     cout << endl << "Введите минимальный этаж: ";
  124.     int floorMin = MagicInput((int)0);
  125.     cout << endl << "Введите максимальный этаж: ";
  126.     int floorMax = MagicInput((int)0);
  127.     for (int i = 0; i < (int)Houses.size(); i++)
  128.     {
  129.         if (roomsCount == Houses[i].getRoomsCount() && (int)Houses[i].getFloor() >= floorMin && (int)Houses[i].getFloor() <= floorMax)
  130.             Houses[i].Show();
  131.     }
  132.     Pause();
  133. }
  134.  
  135. void Menu()
  136. {
  137.     system("cls");
  138.     cout << "---Выберите опцию: ";
  139.     cout << endl << "1. Добавить здание";
  140.     cout << endl << "2. Вывод всех зданий";
  141.     cout << endl << "3. Вывод по фильтру 1";
  142.     cout << endl << "4. Вывод по фильтру 2";
  143.     cout << endl << "ESC. Выход";
  144. }
  145.  
  146. int main()
  147. {
  148.     SetLucidaFont();
  149.     SetConsoleCP(1251);
  150.     SetConsoleOutputCP(1251);
  151.  
  152.     vector <House> Houses;
  153.     while (true)
  154.     {
  155.         Menu();
  156.         switch (_getch())
  157.         {
  158.         case 49: InputHouse(Houses); // 1
  159.             break;
  160.         case 50: OutputAllHouses(Houses); // 2
  161.             break;
  162.         case 51: OutputByFilterFirst(Houses); // 3
  163.             break;
  164.         case 52: OutputByFilterSecond(Houses); // 4
  165.             break;
  166.         case 27: //ESC
  167.             return 0;
  168.         }
  169.     }
  170. }
Advertisement
Add Comment
Please, Sign In to add comment