Advertisement
Underhing

Untitled

Dec 13th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 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++) flat[i].read(afile);
  25. afile.close();
  26. for (int i = 0; i < flats_number; i++) flat[i].print();
  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.  
  91.  
  92.  
  93.  
  94. //
  95. // Класс Box
  96. // class.cpp
  97. //
  98.  
  99. #include <iostream>
  100. #include <string>
  101. #include <clocale>
  102. #include <fstream>
  103.  
  104. using namespace std;
  105.  
  106. class box
  107. {
  108. private:
  109. unsigned int rooms;
  110. unsigned int total;
  111. unsigned int living;
  112. unsigned int floor;
  113. unsigned int storeys;
  114. string district;
  115. public:
  116. void read(ifstream& file);
  117. void print();
  118. string get_districs();
  119. unsigned int get_total();
  120. unsigned int get_floor();
  121. unsigned int get_storeys();
  122. };
  123.  
  124. class boxstore
  125. {
  126. private:
  127. box* flat;
  128. int flats_number;
  129. public:
  130. void read_file(string filename);
  131. void total_space(string location);
  132. void last_flat();
  133. boxstore(int n);
  134. ~boxstore();
  135. };
  136.  
  137.  
  138.  
  139.  
  140. //
  141. // Квартиры
  142. // main.cpp
  143. //
  144.  
  145. #include "stdafx.h"
  146. #include "class.cpp"
  147. #include "functions.cpp"
  148.  
  149.  
  150. int main()
  151. {
  152. setlocale(LC_ALL, "rus");
  153. int n;
  154. string location;
  155. cout << "Введите размер базы: ";
  156. cin >> n;
  157. cout << "------------ Квартиры ----------------\n";
  158. boxstore my_box(n);
  159. my_box.read_file("house.txt");
  160.  
  161. cout << "------------ Действия ----------------\n";
  162. cout << "[Задание №1] Рассчитать общую площадь квартир, расположенных в заданном районе\n";
  163. cout << "Введите название района: ";
  164.  
  165. cin.get();
  166. getline(cin, location);
  167. my_box.total_space(location);
  168.  
  169. cout << "[Задание №2] Вывести на экран данные обо всех квартирах, расположенных на последнем этаже многоэтажного дома \n";
  170. my_box.last_flat();
  171. system("pause");
  172. }
  173.  
  174.  
  175.  
  176.  
  177. Luberci
  178. 12
  179. 150
  180. 80
  181. 6
  182. 6
  183. Ximki
  184. 55
  185. 880
  186. 390
  187. 1
  188. 1
  189. Ozerny
  190. 12
  191. 234
  192. 167
  193. 14
  194. 14
  195. Luberci
  196. 6
  197. 89
  198. 80
  199. 8
  200. 8
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement