Slavik9510

Untitled

Oct 6th, 2022
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. #pragma once
  2. #include <string.h>
  3. class CPU
  4. {
  5. private:
  6.     char* name;
  7.     int cores;
  8. public:
  9.     CPU(char* name, int cores)
  10.     {
  11.         if (name == nullptr)
  12.         {
  13.             this->name = nullptr;
  14.         }
  15.         else
  16.         {
  17.             this->name = new char[strlen(name) + 1];
  18.             strcpy(this->name, name);
  19.         }
  20.         this->cores = cores;
  21.     }
  22.     CPU(const CPU& cpu)
  23.     {
  24.         this->cores = cpu.cores;
  25.         if (this->name != nullptr)
  26.         {
  27.             delete[] this->name;
  28.         }
  29.         if (cpu.name == nullptr)
  30.         {
  31.             this->name = nullptr;
  32.             return;
  33.         }
  34.         this->name = new char[strlen(cpu.name) + 1];
  35.         strcpy(this->name, cpu.name);
  36.     }
  37.     ~CPU()
  38.     {
  39.         if (name != nullptr)
  40.         {
  41.             delete[] name;
  42.         }
  43.     }
  44.     void setName(char* name)
  45.     {
  46.         if (this->name != nullptr)
  47.         {
  48.             delete[] this->name;
  49.         }
  50.         if (name == nullptr)
  51.         {
  52.             this->name = nullptr;
  53.             return;
  54.         }
  55.         this->name = new char[strlen(name) + 1];
  56.         strcpy(this->name, name);
  57.     }
  58.     char* getName()
  59.     {
  60.         char* toReturn = new char[strlen(this->name) + 1];
  61.         strcpy(toReturn, this->name);
  62.         return toReturn;
  63.     }
  64.     void setCores(int cores)
  65.     {
  66.         this->cores = cores;
  67.     }
  68.     int getCores()
  69.     {
  70.         return cores;
  71.     }
  72. };
Advertisement
Add Comment
Please, Sign In to add comment