Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <ctime>
- #include <cstdlib>
- using namespace std;
- class Ekwipunek {
- string nazwa="miecz";
- int stat;
- public:
- Ekwipunek();
- int get_stat();
- void wypisz();
- void set_stat(int);
- };
- class Bohater {
- static int licznik;
- int iid = 0;
- const int limit = 5;
- int ilosc_elementow;
- Ekwipunek *ekwipunek;
- public:
- Bohater(int);
- Bohater(int, Ekwipunek*);
- Bohater(const Bohater&);
- Bohater();
- ~Bohater();
- void wypisz();
- void zmienStat(int);
- static int getLicznik()
- {
- return licznik;
- }
- };
- int Bohater::licznik = 0;
- Ekwipunek::Ekwipunek()
- {
- stat = rand() % 46 + 5;
- }
- int Ekwipunek::get_stat()
- {
- return stat;
- }
- void Ekwipunek::wypisz()
- {
- cout << "Nazwa: " <<nazwa<< endl;
- cout << "Sila: " << stat << endl;
- }
- void Ekwipunek::set_stat(int nowaStat)
- {
- stat = nowaStat;
- }
- Bohater::Bohater()
- {
- iid = ++licznik;
- ekwipunek = new Ekwipunek[1];
- ilosc_elementow = 1;
- }
- Bohater::Bohater(int ilosc):limit(ilosc)
- {
- iid = ++licznik;
- ilosc_elementow = ilosc;
- ekwipunek = new Ekwipunek[ilosc];
- }
- Bohater::Bohater(int ilosc, Ekwipunek* nEkwipunek):limit(ilosc)
- {
- iid = ++licznik;
- ilosc_elementow = ilosc;
- ekwipunek = nEkwipunek;
- }
- Bohater::Bohater(const Bohater & kBohater)
- {
- iid = kBohater.iid;
- licznik++;
- ilosc_elementow = kBohater.ilosc_elementow;
- Ekwipunek* kEkwipunek = kBohater.ekwipunek;
- ekwipunek = new Ekwipunek[ilosc_elementow];
- for(int i = 0; i < ilosc_elementow; i++)
- {
- ekwipunek[i].set_stat(kEkwipunek[i].get_stat());
- }
- }
- void Bohater::zmienStat(int nowaStat)
- {
- ekwipunek->set_stat(nowaStat);
- }
- void Bohater::wypisz()
- {
- cout << "IID: " << iid << endl;
- cout << "ilosc przedmiotow: " << ilosc_elementow << ": " << endl;
- for (int i = 0; i < ilosc_elementow; i++)
- {
- ekwipunek[i].wypisz();
- }
- }
- Bohater::~Bohater()
- {
- --licznik;
- delete[] ekwipunek;
- }
- int main()
- {
- srand(time(NULL));
- Bohater A;
- Bohater B(7);
- Bohater C(10, new Ekwipunek[10]);
- Bohater D(A);
- A.wypisz();
- B.wypisz();
- D.wypisz();
- D.zmienStat(7);
- A.wypisz();
- D.wypisz();
- A.~Bohater();
- D.~Bohater();
- B.~Bohater();
- C.~Bohater();
- Bohater** sto = new Bohater*[100];
- for (int i = 0; i < 100; i++)
- {
- sto[i] = new Bohater(100);
- }
- for (int i = 0; i < 100; i++)
- {
- delete sto[i];
- }
- cout<<Bohater::getLicznik()<<endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement