Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- class zad2
- {
- char* tab;
- int r,a;
- public:
- zad2(int a=5):zad2('a')
- {
- tab=new char[a];
- tab[0]='\0';
- }
- zad2(char)
- {
- cout<<"delegowany"<<endl;
- }
- ~zad2()
- {
- delete [] tab;
- }
- void wczytaj()
- {
- cout<<"podaj nr indeksu ";
- cin>>a;
- if(a<r) {
- cout<<"podaj znak ";
- cin>>tab[a];
- }
- else cout<<"poza zakresem"<<endl;
- }
- void pobierz()
- {
- cout<<"podaj nr indeksu ";
- cin>>a;
- if(a<r) cout<<tab[a]<<endl;
- else cout<<"poza zakresem"<<endl;
- }
- };
- class macierz
- {
- int x,y;
- char z;
- char **m;
- public:
- macierz(int x,int y=1,const char &z='A'):x(x),y(y),z(z)
- {
- m=new char *[x];
- for(int i=0; i<x;i++)
- {
- m[i]=new char [y];
- }
- for(int i=0;i<x;i++)
- for(int j=0;j<y;j++)
- m[i][j]=z;
- }
- ~macierz()
- {
- for(int i=0;i<x;i++)
- delete [] m[i];
- delete [] m;
- }
- int zwrocn() const {
- return x;
- }
- int zwrocm() const {
- return y;
- }
- char zwrocnm(int n,int c) const {
- if(n>x or n<0) if(c>y or c<0) return -1;
- return m[n][c];
- }
- friend istream& operator>> (istream&, macierz &);
- int operator++ (int)
- {
- return (x+5);
- }
- void wypelnij(char a='A',char b='Z')
- {
- for(int i=0;i<x;i++)
- for(int j=0;j<y;j++)
- m[i][j]=rand()%(b-a+1)+a;
- }
- };
- istream& operator>> (istream& a, macierz & b)
- {
- a>>b.x>>b.y;
- return a;
- }
- void wyswietl(int *wsk)
- {
- cout<<&wsk<<" "<<wsk<<" "<<*wsk<<endl;
- *wsk=10;
- }
- class postac
- {
- int hp;
- public:
- postac(int a):hp(a){};
- void pokaz_hp()
- {
- cout<<hp<<endl;
- }
- virtual void atak()=0;
- virtual ~postac();
- };
- postac::~postac(){};
- class rycerz: public postac
- {
- public:
- rycerz(int x):postac(x){};
- virtual void atak()
- {
- cout<<"Atak mieczem"<<endl;
- }
- };
- class chlop :public postac
- {
- public:
- chlop(int x):postac(x){};
- virtual void atak()
- {
- cout<<"Atak widłami"<<endl;
- }
- };
- class mag :public postac
- {
- public:
- mag(int x):postac(x){};
- virtual void atak()
- {
- cout<<"Atak kula ognia"<<endl;
- }
- };
- int main() {
- srand(time(NULL));
- rycerz ryc(50);
- mag mg(40);
- chlop ch(60);
- postac *wsk=&ch;
- wsk->pokaz_hp();
- wsk->atak();
- wsk=&ryc;
- wsk->atak();
- wsk->pokaz_hp();
- wsk=&mg;
- wsk->atak();
- wsk->pokaz_hp();
- /*int a=5;
- int* wsk=&a;
- cout<<*wsk<<" "<<wsk<<" "<<&wsk<<endl;
- wyswietl(wsk);
- cout<<*wsk<<" "<<wsk<<" "<<&wsk<<endl;
- zad2 *abc=new zad2(8);
- abc->wczytaj();
- abc->pobierz();
- //while(1)
- {
- zad2 *abg=new zad2();
- delete abg;
- }
- delete abc;
- macierz *ob1=new macierz(2,4,'T');
- macierz *ob2=new macierz(3);
- const macierz foo=2;
- cout<<foo++;
- int a=1,b=0;
- const int c=1,d=0;
- cout<<ob2->zwrocnm(5,4);
- while(1)
- {
- macierz *ob3=new macierz(3);
- delete ob3;
- }
- */
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement