Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Методы классов
- // functions.cpp
- //
- // Класс boxstore::
- boxstore::boxstore(int n)
- {
- flats_number = n;
- flat = new box[flats_number];
- }
- boxstore::~boxstore()
- {
- delete[] flat;
- }
- void boxstore::read_file(string filename){
- ifstream afile;
- afile.open(filename);
- for (int i = 0; i < flats_number; i++) flat[i].read(afile);
- afile.close();
- for (int i = 0; i < flats_number; i++) flat[i].print();
- }
- void boxstore::total_space(string location)
- {
- int counter = 0;
- for (int i = 0; i < flats_number; i++)
- if (flat[i].get_districs() == location) counter = counter + flat[i].get_total();
- if (counter == 0) cout << "[Ошибка] Такого района нет\n";
- else cout << "[] Общая площадь: " << counter << "\n";
- }
- void boxstore::last_flat()
- {
- for (int i = 0; i < flats_number; i++)
- if (flat[i].get_floor() >= 5 && flat[i].get_floor() == flat[i].get_storeys()) flat[i].print();
- }
- // Класс box::
- string box::get_districs()
- {
- return district;
- }
- unsigned int box::get_total()
- {
- return total;
- }
- unsigned int box::get_floor()
- {
- return floor;
- }
- unsigned int box::get_storeys()
- {
- return storeys;
- }
- void box::read(ifstream& file)
- {
- getline(file, district);
- file >> rooms;
- file >> total;
- file >> living;
- file >> floor;
- file >> storeys;
- file.get();
- }
- void box::print()
- {
- cout << "Район: " << district << endl;
- cout << "Число комнат: " << rooms << endl;
- cout << "Общая площадь: " << total << endl;
- cout << "Жилая площадь: " << living << endl;
- cout << "Этаж: " << floor << endl;
- cout << "Этажность дома: " << storeys << "\n" << endl;
- }
- //
- // Класс Box
- // class.cpp
- //
- #include <iostream>
- #include <string>
- #include <clocale>
- #include <fstream>
- using namespace std;
- class box
- {
- private:
- unsigned int rooms;
- unsigned int total;
- unsigned int living;
- unsigned int floor;
- unsigned int storeys;
- string district;
- public:
- void read(ifstream& file);
- void print();
- string get_districs();
- unsigned int get_total();
- unsigned int get_floor();
- unsigned int get_storeys();
- };
- class boxstore
- {
- private:
- box* flat;
- int flats_number;
- public:
- void read_file(string filename);
- void total_space(string location);
- void last_flat();
- boxstore(int n);
- ~boxstore();
- };
- //
- // Квартиры
- // main.cpp
- //
- #include "stdafx.h"
- #include "class.cpp"
- #include "functions.cpp"
- int main()
- {
- setlocale(LC_ALL, "rus");
- int n;
- string location;
- cout << "Введите размер базы: ";
- cin >> n;
- cout << "------------ Квартиры ----------------\n";
- boxstore my_box(n);
- my_box.read_file("house.txt");
- cout << "------------ Действия ----------------\n";
- cout << "[Задание №1] Рассчитать общую площадь квартир, расположенных в заданном районе\n";
- cout << "Введите название района: ";
- cin.get();
- getline(cin, location);
- my_box.total_space(location);
- cout << "[Задание №2] Вывести на экран данные обо всех квартирах, расположенных на последнем этаже многоэтажного дома \n";
- my_box.last_flat();
- system("pause");
- }
- Luberci
- 12
- 150
- 80
- 6
- 6
- Ximki
- 55
- 880
- 390
- 1
- 1
- Ozerny
- 12
- 234
- 167
- 14
- 14
- Luberci
- 6
- 89
- 80
- 8
- 8
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement