Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- class Room
- {
- friend ostream& operator<<(ostream&, const Room&);
- public:
- Room() {}
- Room(int width, int height, int length, int windows = 0)
- : _width(width), _height(height), _length(length), _windows(windows) {}
- int width() const { return _width; }
- int height() const { return _height; }
- int length() const { return _length; }
- int windows() const { return _windows; }
- int square() const { return _width * _length; }
- private:
- int _width;
- int _height;
- int _length;
- int _windows;
- };
- class Flat
- {
- friend ostream& operator<<(ostream&, const Flat&);
- public:
- Flat(int level) : _level(level) {}
- Room* add_room(Room* room)
- {
- _rooms.push_back(room);
- return _rooms.back();
- }
- Room* add_room(int width, int height, int length)
- {
- _rooms.push_back(new Room(width, height, length));
- return _rooms.back();
- }
- void remove_room(Room *room)
- {
- _rooms.erase(remove(_rooms.begin(), _rooms.end(), room),
- _rooms.end());
- }
- int rooms_count() const { return _rooms.size(); }
- private:
- int _level;
- vector<Room*> _rooms;
- };
- ostream& operator<<(ostream& out, const Room& room)
- {
- return out << "ширина: " << room.width()
- << " высота: " << room.height()
- << " длина: " << room.length();
- }
- ostream& operator<<(ostream& out, const Flat& flat)
- {
- out << "Этаж квартиры: " << flat._level << std::endl;
- out << "Комнаты в квартире: " << endl;
- vector<Room*>::const_iterator cit = flat._rooms.begin();
- for ( ; cit != flat._rooms.end(); ++cit)
- out << **cit << std::endl;
- return out;
- }
- int main()
- {
- setlocale(LC_ALL, "rus");
- vector<Room*> other_rooms;
- other_rooms.push_back(new Room(10, 10, 10));
- Flat flat(2);
- Room *room = flat.add_room(new Room(20, 20, 20));
- other_rooms.push_back(room);
- flat.add_room(other_rooms[0]);
- cout << "Информация о кв: " << endl << flat << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment