Files
uni_notes/00 Inbox/29605321 - OOP 4_16.md
2026-04-16 11:47:56 +02:00

709 B

created, course, topic, related, type, status, tags
created course topic related type status tags
2026-04-16 08:01 lecture 🔴
university

📌 Summary

[!abstract]


📝 Content

Classes

C approach of defining a Pokemon:

typedef struct {
	int exp;
	int level;
	int attack;
	int defense;
	int speed;
	int hp;
} Pokemon;

void upgrade(*Pokemon p, int gainedExp) {
	p->exp += gainedExp;
	if (p->exp >= 4000) {
		p->exp -= 4000;
		p->level += 1;	
	}
}

In C++ we use classes:

class Pokemon {
public: // visibility modifier
	int exp;
	int level;
	int attack;
	int defense;
	int speed;
	int hp;

	void upgrade(int gainedExp) {
		exp += gainedExp;
		if (exp >= 4000) {
			exp -= 4000;
			level += 1;	
		}
	}
}