Advertisement
Underhing

Untitled

Dec 12th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1. //
  2. // Квартиры
  3. // main.cpp
  4. //
  5.  
  6. #include "class.cpp"
  7.  
  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. void boxstore::read_file(string filename){
  20. ifstream afile;
  21.  
  22. afile.open(filename);
  23. for (int i = 0; i < flats_number; i++) flat[i].read(afile);
  24. afile.close();
  25. for (int i = 0; i < flats_number; i++) flat[i].print();
  26.  
  27. }
  28.  
  29. void boxstore::total_space(string location)
  30. {
  31. int counter = 0;
  32.  
  33. for (int i = 0; i < flats_number; i++)
  34. if (flat[i].get_districs() == location) counter = counter + flat[i].get_total();
  35.  
  36.  
  37. if (counter == 0) cout << "[Ошибка] Такого района нет\n";
  38. else cout << "[] Общая площадь: " << counter << "\n";
  39. }
  40.  
  41. void boxstore::last_flat()
  42. {
  43. for (int i = 0; i < flats_number; i++)
  44. if (flat[i].get_floor() >= 5 && flat[i].get_floor() == flat[i].get_storeys()) flat[i].print();
  45. }
  46.  
  47.  
  48. string box::get_districs()
  49. {
  50. return district;
  51. }
  52.  
  53. unsigned int box::get_total()
  54. {
  55. return total;
  56. }
  57.  
  58. unsigned int box::get_floor()
  59. {
  60. return floor;
  61. }
  62.  
  63. unsigned int box::get_storeys()
  64. {
  65. return storeys;
  66. }
  67.  
  68. void box::read(ifstream& file)
  69. {
  70. getline(file, district);
  71. file >> rooms;
  72. file >> total;
  73. file >> living;
  74. file >> floor;
  75. file >> storeys;
  76. file.get();
  77. }
  78.  
  79. void box::print()
  80. {
  81. cout << "Район: " << district << endl;
  82. cout << "Число комнат: " << rooms << endl;
  83. cout << "Общая площадь: " << total << endl;
  84. cout << "Жилая площадь: " << living << endl;
  85. cout << "Этаж: " << floor << endl;
  86. cout << "Этажность дома: " << storeys << "\n" << endl;
  87. }
  88.  
  89. int main()
  90. {
  91. setlocale(LC_ALL, "rus");
  92. int n;
  93. string location;
  94. cout << "Введите размер базы: ";
  95. cin >> n;
  96. cout << "------------ Квартиры ----------------\n";
  97. boxstore my_box(n);
  98. my_box.read_file("house.txt");
  99.  
  100. cout << "------------ Действия ----------------\n";
  101. cout << "[Задание №1] Рассчитать общую площадь квартир, расположенных в заданном районе\n";
  102. cout << "Введите название района: ";
  103.  
  104. cin.get();
  105. getline(cin, location);
  106. my_box.total_space(location);
  107.  
  108. cout << "[Задание №2] Вывести на экран данные обо всех квартирах, расположенных на последнем этаже многоэтажного дома \n";
  109. my_box.last_flat();
  110.  
  111. delete my_box;
  112. }
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129. //
  130. // Класс Box
  131. // class.cpp
  132. //
  133.  
  134. #include <iostream>
  135. #include <string>
  136. #include <clocale>
  137. #include <fstream>
  138.  
  139. using namespace std;
  140.  
  141. class box
  142. {
  143. private:
  144. unsigned int rooms;
  145. unsigned int total;
  146. unsigned int living;
  147. unsigned int floor;
  148. unsigned int storeys;
  149. string district;
  150. public:
  151. void read(ifstream& file);
  152. void print();
  153. string get_districs();
  154. unsigned int get_total();
  155. unsigned int get_floor();
  156. unsigned int get_storeys();
  157. };
  158.  
  159. class boxstore
  160. {
  161. private:
  162. box* flat;
  163. int flats_number;
  164. public:
  165. void read_file(string filename);
  166. void total_space(string location);
  167. void last_flat();
  168. boxstore(int n);
  169. ~boxstore();
  170. };
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180. Люберцы
  181. 12
  182. 150
  183. 80
  184. 6
  185. 6
  186. Химки
  187. 55
  188. 880
  189. 390
  190. 1
  191. 1
  192. Озерный
  193. 12
  194. 234
  195. 167
  196. 14
  197. 14
  198. Люберцы
  199. 6
  200. 89
  201. 80
  202. 8
  203. 8
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement