Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- class Compl
- {
- friend ostream& operator<<(ostream&, const Compl&);
- public:
- Compl() {}
- Compl(string c, int width, int height, int length, int windows = 0)
- : _c(c), _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; }
- string c() const {return _c;}
- int square() const { return _width * _length; }
- private:
- int _width;
- int _height;
- int _length;
- int _windows;
- string _c;
- };
- class PC
- {
- friend ostream& operator<<(ostream&, const PC&);
- public:
- PC(int level) : _level(level) {}
- Compl* add_room(Compl* room)
- {
- _rooms.push_back(room);
- return _rooms.back();
- }
- Compl* add_room(string c, int width, int height, int length)
- {
- _rooms.push_back(new Compl(c,width, height, length));
- return _rooms.back();
- }
- void remove_room(Compl *room)
- {
- _rooms.erase(remove(_rooms.begin(), _rooms.end(), room),
- _rooms.end());
- }
- private:
- int _level;
- vector<Compl*> _rooms;
- };
- ostream& operator<<(ostream& out, const Compl& room)
- {
- return out << endl << room.c() << endl << "Цена: " << room.width()
- << " срок гарантии: " << room.height();
- }
- ostream& operator<<(ostream& out, const PC& flat)
- {
- out << "Кмоплектующие в компьютере: " << endl;
- vector<Compl*>::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<Compl*> other_rooms;
- other_rooms.push_back(new Compl("Videocard",1000000, 10, 10));
- PC complect(2);
- Compl *room = complect.add_room(new Compl("Memmory", 20000, 20, 20));
- other_rooms.push_back(room);
- complect.add_room(other_rooms[0]);
- cout << "Информация о компьютере: " << endl << complect << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement