Advertisement
evcamels

lab-8-6

Dec 23rd, 2021
984
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.15 KB | None | 0 0
  1. #include <vector>
  2. #include <iostream>
  3. #include <algorithm>
  4. using namespace std;
  5. class Compl
  6.   {
  7.   friend ostream& operator<<(ostream&, const Compl&);
  8.  
  9.   public:
  10.       Compl() {}
  11.       Compl(string c, int width, int height, int length, int windows = 0)
  12.       : _c(c), _width(width), _height(height), _length(length), _windows(windows) {}
  13.  
  14.     int width()   const { return _width; }
  15.     int height()  const { return _height; }
  16.     int length()  const { return _length; }
  17.     int windows() const { return _windows; }
  18.     string c() const {return _c;}
  19.     int square()  const { return _width * _length; }
  20.  
  21.   private:
  22.     int _width;
  23.     int _height;
  24.     int _length;
  25.     int _windows;
  26.     string _c;
  27.   };
  28.  
  29. class PC
  30.   {
  31.   friend ostream& operator<<(ostream&, const PC&);
  32.  
  33.   public:
  34.       PC(int level) : _level(level) {}
  35.  
  36.       Compl* add_room(Compl* room)
  37.       {
  38.       _rooms.push_back(room);
  39.       return _rooms.back();
  40.       }
  41.    
  42.       Compl* add_room(string c, int width, int height, int length)
  43.       {
  44.       _rooms.push_back(new Compl(c,width, height, length));
  45.       return _rooms.back();
  46.       }
  47.  
  48.     void remove_room(Compl *room)
  49.       {
  50.       _rooms.erase(remove(_rooms.begin(), _rooms.end(), room),
  51.           _rooms.end());
  52.       }
  53.  
  54.  
  55.   private:
  56.     int _level;
  57.     vector<Compl*> _rooms;
  58.   };
  59.  
  60. ostream& operator<<(ostream& out, const Compl& room)
  61.   {
  62.       return out << endl << room.c() << endl << "Цена: "  << room.width()
  63.       << " срок гарантии: " << room.height();
  64.   }
  65.  
  66. ostream& operator<<(ostream& out, const PC& flat)
  67.   {
  68.     out << "Кмоплектующие в компьютере: " << endl;
  69.     vector<Compl*>::const_iterator cit = flat._rooms.begin();
  70.     for ( ; cit != flat._rooms.end(); ++cit)
  71.       out << **cit << std::endl;
  72.  
  73.     return out;
  74.   }
  75.  
  76. int main()
  77.   {
  78.   setlocale(LC_ALL, "rus");
  79.      
  80.   vector<Compl*> other_rooms;
  81.   other_rooms.push_back(new Compl("Videocard",1000000, 10, 10));
  82.  
  83.       PC complect(2);
  84.  
  85.       Compl *room = complect.add_room(new Compl("Memmory", 20000, 20, 20));
  86.   other_rooms.push_back(room);
  87.  
  88.       complect.add_room(other_rooms[0]);
  89.  
  90.   cout << "Информация о компьютере: " << endl << complect << std::endl;
  91.  
  92.   return 0;
  93.   }
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement