Advertisement
Josif_tepe

Untitled

Sep 12th, 2021
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Computer{
  6. private:
  7.     string manufacturer;
  8.     int ram;
  9.     double cpu;
  10. public:
  11.     Computer(string manufacturer = "", int ram = 0, double cpu = 0.0) {
  12.         this->manufacturer = manufacturer;
  13.         this->ram = ram;
  14.         this->cpu = cpu;
  15.     }
  16. };
  17. class PCStore {
  18. private:
  19.     Computer *computers;
  20.     int n;
  21.     int sz;
  22. public:
  23.     PCStore() {
  24.         computers = new Computer[10];
  25.         n = 0;
  26.         sz = 10;
  27.     }
  28.    
  29.     void add_computer(Computer c) {
  30.         if(n == sz) {
  31.             Computer *copy_array = new Computer[sz];
  32.             for(int i = 0; i < n; i++) {
  33.                 copy_array[i] = computers[i];
  34.             }
  35.             sz *= 2;
  36.             computers = new Computer[sz];
  37.             for(int i = 0; i < n; i++) {
  38.                 computers[i] = copy_array[i];
  39.             }
  40.         }
  41.         computers[n] = c;
  42.         n++;
  43.        
  44.     }
  45. };
  46. int main()
  47. {
  48.    
  49.     return 0;
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement