Advertisement
Underhing

Untitled

Dec 19th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.72 KB | None | 0 0
  1. //
  2. // Методы классов
  3. // functions.cpp
  4. //
  5.  
  6.  
  7. // Класс boxstore::
  8. boxstore::boxstore(int n)
  9. {
  10.     flats_number = n;
  11.     flat = new box[flats_number];
  12. }
  13.  
  14. boxstore::~boxstore()
  15. {
  16.     delete[] flat;
  17. }
  18.  
  19.  
  20. void boxstore::read_file(string filename) {
  21.     ifstream afile;
  22.  
  23.     afile.open(filename);
  24.     for (int i = 0; i < flats_number; i++) afile >> flat[i];
  25.     afile.close();
  26.     for (int i = 0; i < flats_number; i++) cout << flat[i];
  27.  
  28. }
  29.  
  30. void boxstore::total_space(string location)
  31. {
  32.     int counter = 0;
  33.  
  34.     for (int i = 0; i < flats_number; i++)
  35.         if (flat[i].get_districs() == location) counter = counter + flat[i].get_total();
  36.  
  37.  
  38.     if (counter == 0) cout << "[Ошибка] Такого района нет\n";
  39.     else cout << "[] Общая площадь: " << counter << "\n";
  40. }
  41.  
  42. void boxstore::last_flat()
  43. {
  44.     for (int i = 0; i < flats_number; i++)
  45.         if (flat[i].get_floor() >= 5 && flat[i].get_floor() == flat[i].get_storeys()) flat[i].print();
  46. }
  47.  
  48. // Класс box::
  49. string box::get_districs()
  50. {
  51.     return district;
  52. }
  53.  
  54. unsigned int box::get_total()
  55. {
  56.     return total;
  57. }
  58.  
  59. unsigned int box::get_floor()
  60. {
  61.     return floor;
  62. }
  63.  
  64. unsigned int box::get_storeys()
  65. {
  66.     return storeys;
  67. }
  68.  
  69. void box::read(ifstream& file)
  70. {
  71.     getline(file, district);
  72.     file >> rooms;
  73.     file >> total;
  74.     file >> living;
  75.     file >> floor;
  76.     file >> storeys;
  77.     file.get();
  78. }
  79.  
  80. void box::print()
  81. {
  82.     cout << "Район: " << district << endl;
  83.     cout << "Число комнат: " << rooms << endl;
  84.     cout << "Общая площадь: " << total << endl;
  85.     cout << "Жилая площадь: " << living << endl;
  86.     cout << "Этаж: " << floor << endl;
  87.     cout << "Этажность дома: " << storeys << "\n" << endl;
  88. }
  89.  
  90. bool box::operator ==(box abox)
  91. {
  92.     if (rooms != abox.rooms) return false;
  93.     if (total != abox.total) return false;
  94.     if (living != abox.living) return false;
  95.     if (floor != abox.floor) return false;
  96.     if (storeys != abox.storeys) return false;
  97.     if (district != abox.district) return false;
  98.  
  99.     return true;
  100. }
  101.  
  102. ifstream& operator>>(ifstream& stream, box& abox)
  103. {
  104.     getline(stream, abox.district);
  105.     stream >> abox.rooms;
  106.     stream >> abox.total;
  107.     stream >> abox.living;
  108.     stream >> abox.floor;
  109.     stream >> abox.storeys;
  110.     stream.get();
  111.     return stream;
  112. }
  113.  
  114. ostream& operator<<(ostream& stream, box& abox)
  115. {
  116.     stream << "Район: " << abox.district << endl;
  117.     stream << "Число комнат: " << abox.rooms << endl;
  118.     stream << "Общая площадь: " << abox.total << endl;
  119.     stream << "Жилая площадь: " << abox.living << endl;
  120.     stream << "Этаж: " << abox.floor << endl;
  121.     stream << "Этажность дома: " << abox.storeys << "\n" << endl;
  122.     return stream;
  123. }
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146. Luberci
  147. 12
  148. 150
  149. 80
  150. 6
  151. 6
  152. Ximki
  153. 55
  154. 880
  155. 390
  156. 1
  157. 1
  158. Ozerny
  159. 12
  160. 234
  161. 167
  162. 14
  163. 14
  164. Luberci
  165. 6
  166. 89
  167. 80
  168. 8
  169. 8
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190. //
  191. // Класс Box
  192. // class.cpp
  193. //
  194.  
  195. #include <iostream>
  196. #include <string>
  197. #include <clocale>
  198. #include <fstream>
  199.  
  200. using namespace std;
  201.  
  202. class box
  203. {
  204. private:
  205.     unsigned int rooms;
  206.     unsigned int total;
  207.     unsigned int living;
  208.     unsigned int floor;
  209.     unsigned int storeys;
  210.     string district;
  211. public:
  212.     void read(ifstream& file);
  213.     void print();
  214.     string get_districs();
  215.     unsigned int get_total();
  216.     unsigned int get_floor();
  217.     unsigned int get_storeys();
  218.  
  219.     bool operator ==(box another);
  220.     friend ifstream& operator>>(ifstream& stream, box& abox);
  221.     friend ostream& operator<<(ostream& stream, box& abox);
  222.  
  223.  
  224. };
  225.  
  226. class boxstore
  227. {
  228. private:
  229.     box* flat;
  230.     int flats_number;
  231. public:
  232.     void read_file(string filename);
  233.     void total_space(string location);
  234.     void last_flat();
  235.     boxstore(int n);
  236.     ~boxstore();
  237. };
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267. //
  268. // Квартиры
  269. // main.cpp
  270. //
  271.  
  272. #include "stdafx.h"
  273. #include "class.cpp"
  274. #include "functions.cpp"
  275.  
  276.  
  277. int main()
  278. {
  279.     setlocale(LC_ALL, "rus");
  280.     int n;
  281.     string location;
  282.     cout << "Введите размер базы: ";
  283.     cin >> n;
  284.     cout << "------------ Квартиры ----------------\n";
  285.     boxstore my_box(n);
  286.     my_box.read_file("house.txt");
  287.  
  288.     cout << "------------ Действия ----------------\n";
  289.     cout << "[Задание №1] Рассчитать общую площадь квартир, расположенных в заданном районе\n";
  290.     cout << "Введите название района: ";
  291.  
  292.     cin.get();
  293.     getline(cin, location);
  294.     my_box.total_space(location);
  295.  
  296.     cout << "[Задание №2] Вывести на экран данные обо всех квартирах, расположенных на последнем этаже многоэтажного дома \n";
  297.     my_box.last_flat();
  298.     system("pause");
  299. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement