Advertisement
Underhing

Untitled

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