Guest User

Untitled

a guest
Apr 26th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.05 KB | None | 0 0
  1. class Image: public AbstrImage {
  2. private:
  3.     int width, height;
  4.     int depth, dpi;
  5.     friend Slide;
  6.  
  7. public:
  8. // Конструкторы
  9.     Image();
  10.     Image(Image &I);
  11.     Image(Image *pI);
  12.     Image(const char *Name, int Width, int Height, int Depth = 32, int Dpi = 96);
  13.     ~Image();
  14.  
  15. // Оператор присваивания
  16.     void operator =(Image &I);
  17.  
  18. // Виртуальные методы
  19.     virtual int classType() { return ImageClass; }
  20.     virtual char* className() { return "Image"; }
  21.     virtual void printOn(ostream &out);
  22.  
  23. // Методы
  24.     void setName(const char *Name);
  25.     void setSize(int Width, int Height) { width = Width; height = Height; }
  26.     void setDepth(int Depth) { depth = Depth; }
  27.     void setDpi(int Dpi) { dpi = Dpi; }
  28.     void setAll(const char *Name, int Width, int Height, int Depth, int Dpi)
  29.         { this->setName(Name); this->setSize(Width, Height); this->setDepth(Depth); this->setDpi(Dpi); }
  30.     const char *getName() { return (const char *)name; }
  31.     int getWidth() { return width; }
  32.     int getHeight() { return height; }
  33.     int getDepth() { return depth; }
  34.     int getDpi() { return dpi; }
  35.     int getNo() { return no; }
  36. };
  37.  
  38. Image::Image():AbstrImage() {
  39.     name = (char *)NULL;
  40.     width = NULL, height = NULL;
  41.     depth = NULL, dpi = NULL;
  42. }
  43.  
  44. Image::Image(Image &I):AbstrImage() {
  45.     no = 0;
  46.     if(I.name != (char *)NULL) {
  47.         name = new char[strlen(I.getName()) + 1];
  48.         strcpy_s(name, strlen(I.getName()) + 1, I.getName());
  49.     } else
  50.         name = (char *)NULL;
  51.  
  52.     width = I.width, height = I.height;
  53.     depth = I.depth, dpi = I.dpi;
  54. }
  55.  
  56. Image::Image(Image *pI):AbstrImage() {
  57.     no = 0;
  58.     if(pI->name != (char *)NULL) {
  59.         name = new char[strlen(pI->getName()) + 1];
  60.         strcpy_s(name, strlen(pI->getName()) + 1, pI->getName());
  61.     } else
  62.         name = (char *)NULL;
  63.  
  64.     width = pI->width, height = pI->height;
  65.     depth = pI->depth, dpi = pI->dpi;
  66. }
  67.  
  68. Image::Image(const char *Name, int Width, int Height, int Depth = 32, int Dpi = 96) {
  69.     no = 0;
  70.     if(Name != (char *)NULL) {
  71.         name = new char[strlen(Name) + 1];
  72.         strcpy_s(name, strlen(Name) + 1, Name);
  73.     } else
  74.         name = (char *)NULL;
  75.  
  76.     width = Width, height = Height;
  77.     depth = Depth, dpi = Dpi;
  78. }
  79.  
  80. void Image::operator =(Image &I) {
  81.     no = 0;
  82.     if(I.name != (char *)NULL) {
  83.         name = new char[strlen(I.getName()) + 1];
  84.         strcpy_s(name, strlen(I.getName()) + 1, I.getName());
  85.     } else
  86.         name = (char *)NULL;
  87.    
  88.     width = I.width, height = I.height;
  89.     depth = I.depth, dpi = I.dpi;
  90. }
  91.  
  92. void Image::printOn(ostream &out) {
  93.     out << "Номер в списке: " << no;
  94.     if(name != (char *)NULL)
  95.         out << " Название: " << name << endl;
  96.     else
  97.         out << " Название не задано" << endl;
  98.    
  99.     out << " Размеры изображения: " << width << "x" << height << endl;
  100.     out << " Глубина цвета: " << depth << endl << " Точек на дюйм: " << dpi << endl;
  101. }
  102.  
  103. void Image::setName(const char *Name) {
  104.     if(name != NULL) delete[] name;
  105.     if(Name != (char *)NULL) {
  106.         name = new char[strlen(Name) + 1];
  107.         strcpy_s(name, strlen(Name) + 1, Name);
  108.     } else
  109.         name = (char *)NULL;
  110. }
Add Comment
Please, Sign In to add comment