Advertisement
PhotoShaman

Laba16

Mar 7th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.24 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <clocale>
  4. #include <windows.h>
  5.  
  6. using namespace std;
  7.  
  8. template <typename Type>
  9. Type MagicInput(Type imputNumber) // Ввод с проверкой
  10. {
  11.     while (!(cin >> imputNumber) || (cin.peek() != '\n'))
  12.     {
  13.         cin.clear();
  14.         while (cin.get() != '\n');
  15.         cout << "Ошибка ввода. Попробуйте еще раз.\n";
  16.     }
  17.     return imputNumber;
  18. }
  19.  
  20. void SetLucidaFont()
  21. {
  22.     HANDLE hCon = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
  23.     if (hCon != INVALID_HANDLE_VALUE) {
  24.         CONSOLE_FONT_INFOEX cfi;
  25.         cfi.cbSize = sizeof(CONSOLE_FONT_INFOEX);
  26.         cfi.nFont = 0;
  27.         cfi.dwFontSize.X = 0;
  28.         cfi.dwFontSize.Y = 12;
  29.         cfi.FontFamily = FF_DONTCARE;
  30.         cfi.FontWeight = 400;
  31.         wcscpy_s(cfi.FaceName, L"Lucida Console");
  32.         SetCurrentConsoleFontEx(hCon, FALSE, &cfi);
  33.     }
  34. }
  35.  
  36. class House
  37. {
  38. private:
  39.     string Address;
  40.     int Floor;
  41.     int RoomsCount;
  42.     float Area;
  43. public:
  44.     House() : Address("Улица Пушкина, дом Колотушкина."), Floor(1), RoomsCount(1), Area(1) {};
  45.     void Show()
  46.     {
  47.         cout << endl << "Адресс: " << Address << "; этаж: " << Floor << "; количество комнат: " << RoomsCount << "; площадь: " << Area;
  48.     }
  49.     string getAddress() { return Address; }
  50.     int getFloor() { return Floor; }
  51.     int getRoomsCount() { return RoomsCount; }
  52.     float getArea() { return Area; }
  53.     void setAddress(string address) { Address = address; }
  54.     void setFloor(int floor) { Floor = floor; }
  55.     void setRoomsCount(int roomsCount) { RoomsCount = roomsCount; }
  56.     void setArea(float area) { Area = area; }
  57. };
  58.  
  59. void main()
  60. {
  61.     SetLucidaFont();
  62.     SetConsoleCP(1251);
  63.     SetConsoleOutputCP(1251);
  64.  
  65.     House house;
  66.     cout << "Введите адресс: " ;
  67.     string address;
  68.     getline(cin, address);
  69.     house.setAddress(address);
  70.     cout << endl << "Введите этаж: ";
  71.     house.setFloor(MagicInput((int)0));
  72.     cout << endl << "Введите количество комнат: ";
  73.     house.setRoomsCount(MagicInput((int)0));
  74.     cout << endl << "Введите площадь: ";
  75.     house.setArea(MagicInput((float)0));
  76.     house.Show();
  77.  
  78.     cout << endl << endl << "ESC - Выход";
  79.     while (!GetAsyncKeyState(VK_ESCAPE)){}
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement