Программалау оқулық Алматы, 012 Қазақстан Республикасы Білім жəне ғылым министрлігінің «Оқулық»



Pdf көрінісі
бет303/642
Дата30.03.2022
өлшемі3,66 Mb.
#29231
түріПрограмма
1   ...   299   300   301   302   303   304   305   306   ...   642
enum color {red, green, blue};

// -----------  monstr класы -----------  

class monstr{

// ------ Кластың жасырын өрістері:

int health, ammo; 

color skin; 

char *name; 

public:

// ------ Конструкторлар:

monstr(int he = 100, int am = 10); 

monstr(color sk); 

monstr(char * nam); 

monstr(monstr &M);

// ------ 

Деструктор:

~monstr() {delete [] name;}

// ------ Операциялар:

monstr& operator ++(){ 

++health; return *this;

}

monstr operator ++(int){

   monstr M(*this); health++; return M;

}

operator int(){ 

   return health;

}

bool operator >(monstr &M){

   if( health > M.get_health()) return true

   return false;

}

const monstr& operator = (monstr &M){ 

   if (&M == this) return *this; 

   if (name) delete [] name; 

   if (M.name){

      name = new char [strlen(M.name) + 1]; 

      strcpy(name, M.name);} 

   else name = 0;

   health = M.health; ammo = M.ammo; skin = M.skin; 

   return *this;

}

// ------ Өрістерге қол жеткізу əдістері:

int get_health() const {return health;} 

int get_ammo() const {return ammo;}


219

// ------ Өрістердің мəндерін өзгертетін əдістер:

void change_health(int he){ health = he;}

// ------ Басқа əдістер:

void draw(int x, int y, int scale, int position);

};

// ------- monstr класының жүзеге асырылуы -------

monstr::monstr(int he, int am):

   health (he), ammo (am), skin (red), name (0){}

monstr::monstr(monstr &M){ 



Достарыңызбен бөлісу:
1   ...   299   300   301   302   303   304   305   306   ...   642




©emirsaba.org 2024
әкімшілігінің қараңыз

    Басты бет