Slavik9510

Untitled

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