Объектно-ориентированное программирование. Сивохин А.В - 42 стр.

UptoLike

42
static int how_many; // Сколько создано объектов класса?
public:
//Конструктор по умолчанию
TextPoint () {color=15; x=1; y=1; visible=0; how_many++;};
//Конструктор копии
TextPoint (const TextPoint & a)
{color=a.color; x=a.x; y=a.y; visible=a.visible; how_many++;};
//Конструктор
TextPoint (int nx, int ny, int ncolor)
{color=ncolor; x=nx; y=ny; visible=0; how_many++;};
//Деструктор
~TextPoint () {how_many--;};
//Доступ к данным из секции private
void ChangeColor (int newColor) {color=newColor;}
int GetX (void) {return x;}
int GetY (void) {return y;}
int GetColor (void) {return color;}
int IsVisible (void) {return visible;}
static int HowMany (void) {return TextPoint::how_many;}
//Методы вывода изображения, сокрытия и движения
void Hide (void);
void Show (void);
void Mov (int, int);
//Перегрузка операций: ++ и -- - движение по диагонали
TextPoint operator ++ (int); //постфиксная форма
TextPoint operator -- (void); //префиксная форма
//Умножение перегружается (в данном
случае) как "друг".
//Перегрузка * как элемента класса: TextPoint operator * (int).
friend TextPoint operator * (TextPoint &, int );
};
#endif
//----------------------------------------------------------------
// Реализация класса - файл textpoint.cpp
#include <conio.h>
#include <dos.h>
#include "textpoint.h"
void TextPoint::Hide (void)
{if (visible)
                                                                     42
   static int how_many; // Сколько создано объектов класса?
  public:
//Конструктор по умолчанию
   TextPoint () {color=15; x=1; y=1; visible=0; how_many++;};
//Конструктор копии
   TextPoint (const TextPoint & a)
{color=a.color; x=a.x; y=a.y; visible=a.visible; how_many++;};
//Конструктор
   TextPoint (int nx, int ny, int ncolor)
{color=ncolor; x=nx; y=ny; visible=0; how_many++;};
//Деструктор
  ~TextPoint () {how_many--;};
//Доступ к данным из секции private
   void ChangeColor (int newColor) {color=newColor;}
   int GetX (void) {return x;}
   int GetY (void) {return y;}
   int GetColor (void) {return color;}
   int IsVisible (void) {return visible;}
   static int HowMany (void) {return TextPoint::how_many;}
//Методы вывода изображения, сокрытия и движения
   void Hide (void);
   void Show (void);
   void Mov (int, int);
//Перегрузка операций: ++ и -- - движение по диагонали
   TextPoint operator ++ (int); //постфиксная форма
   TextPoint operator -- (void); //префиксная форма
//Умножение перегружается (в данном случае) как "друг".
//Перегрузка * как элемента класса: TextPoint operator * (int).
   friend TextPoint operator * (TextPoint &, int );
};
#endif

//----------------------------------------------------------------
// Реализация класса - файл textpoint.cpp
#include 
#include 
#include "textpoint.h"

void TextPoint::Hide (void)
{if (visible)