Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- using namespace std;
- class Bohater {
- private:
- string pseudonim;
- string klasa;
- int sila_ataku; //pola prywatnne
- static int licznik;
- public:
- Bohater()
- { //konstruktor domyślny
- }
- Bohater(Bohater* b, int sila_ataku)
- {
- this->pseudonim = b->getPseudonim();
- this->klasa = b->getKlasa();
- this->sila_ataku = sila_ataku; //kontruktor kopiujący
- wyswietl();
- }
- ~Bohater()
- {
- } //destruktor
- string getPseudonim()
- { //akcesor getter dzięki niemu możemy odczytać prywatne pole
- return this->pseudonim;
- }
- string getKlasa()
- {
- return this->klasa;
- }
- int getSila_ataku()
- {
- return this->sila_ataku;
- }
- static int getLicznik()
- {
- return licznik;
- }
- void setPseudonim(string p)
- {
- this->pseudonim = p; // setter pozwala na zmienianie prywatnego pola
- }
- void setKlasa(string k)
- {
- this->klasa = k;
- }
- void setSila_ataku(int s)
- {
- this->sila_ataku = s;
- }
- void wyswietl()
- {
- cout << "pseudonim: " << this->pseudonim << endl;
- cout << "klasa: " << this->klasa << endl; //wyświetlanie
- cout << "sila: " << this->sila_ataku << endl;
- }
- };
- class Ekwipunek // klasa ekwipuntek
- {
- private:
- string rodzaj; //pola prywantne klasy ekwipunek
- string material;
- float wartosc;
- Bohater* bohater_wsk;
- public:
- Ekwipunek()
- {
- wyswietl();
- }
- Ekwipunek(string rodzaj, string material, float wartosc, Bohater* b)
- {
- this->rodzaj = getRodzaj();
- this->material = getMaterial();
- this->wartosc = getWartosc();
- this->bohater_wsk = b;
- }
- string getRodzaj()
- {
- return this->rodzaj;
- }
- string getMaterial()
- {
- return this->material;
- }
- float getWartosc()
- {
- return this->wartosc;
- }
- void setRodzaj(string r)
- {
- this->rodzaj = r;
- }
- void setMaterial(string m)
- {
- this->material = m;
- }
- void setWartosc(float w)
- {
- this->wartosc = w;
- }
- void setBohater_wsk(Bohater* b)
- {
- this->bohater_wsk = b;
- }
- void wyswietl()
- {
- cout << "rodzaj: " << this->rodzaj<< endl;
- cout << "material: " << this-> material << endl;
- cout << "wartość: " << this->wartosc << endl;
- cout << "klasa: " << bohater_wsk->getKlasa() << endl;
- }
- };
- int main()
- {
- Bohater* b1 = new Bohater;
- b1->setPseudonim("aaron");
- b1->setKlasa("mag");
- b1->setSila_ataku(10);
- b1->Bohater::wyswietl();
- Bohater b2(b1, 93);
- int suma_sily=0;
- Bohater** obiekty = new Bohater*[2];
- obiekty[0][0].setPseudonim("xd");
- obiekty[0][0].setKlasa("mag");
- obiekty[0][0].setSila_ataku(55);
- obiekty[1][1].setPseudonim("bum");
- obiekty[1][1].setKlasa("złodziej");
- obiekty[1][1].setSila_ataku(56);
- for (int i = 0; i < 2; i++)
- {
- for (int j = 0; j < 2; j++)
- {
- suma_sily = suma_sily + obiekty[i][j].getSila_ataku();
- obiekty[i][j].wyswietl();
- }
- }
- cout << "suma sił ataku bohaterów:" << suma_sily << endl;
- for (int i = 0; i < 2; i++)
- {
- delete[] obiekty[i];
- }
- Ekwipunek obiekt_ekwip_1;
- obiekt_ekwip_1.setRodzaj("broń");
- obiekt_ekwip_1.setMaterial("stal");
- obiekt_ekwip_1.setWartosc(45.5);
- obiekt_ekwip_1.setBohater_wsk(&b2);
- obiekt_ekwip_1.wyswietl();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement