Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. using namespace std;
  5.  
  6. class zad2
  7. {
  8. char* tab;
  9. int r,a;
  10. public:
  11. zad2(int a=5):zad2('a')
  12. {
  13. tab=new char[a];
  14. tab[0]='\0';
  15. }
  16. zad2(char)
  17. {
  18. cout<<"delegowany"<<endl;
  19. }
  20. ~zad2()
  21. {
  22. delete [] tab;
  23. }
  24.  
  25. void wczytaj()
  26. {
  27. cout<<"podaj nr indeksu ";
  28. cin>>a;
  29. if(a<r) {
  30. cout<<"podaj znak ";
  31. cin>>tab[a];
  32. }
  33. else cout<<"poza zakresem"<<endl;
  34. }
  35. void pobierz()
  36. {
  37. cout<<"podaj nr indeksu ";
  38. cin>>a;
  39. if(a<r) cout<<tab[a]<<endl;
  40. else cout<<"poza zakresem"<<endl;
  41. }
  42.  
  43. };
  44.  
  45. class macierz
  46. {
  47. int x,y;
  48. char z;
  49. char **m;
  50. public:
  51. macierz(int x,int y=1,const char &z='A'):x(x),y(y),z(z)
  52. {
  53. m=new char *[x];
  54. for(int i=0; i<x;i++)
  55. {
  56. m[i]=new char [y];
  57. }
  58. for(int i=0;i<x;i++)
  59. for(int j=0;j<y;j++)
  60. m[i][j]=z;
  61. }
  62. ~macierz()
  63. {
  64. for(int i=0;i<x;i++)
  65. delete [] m[i];
  66. delete [] m;
  67. }
  68. int zwrocn() const {
  69. return x;
  70. }
  71. int zwrocm() const {
  72. return y;
  73. }
  74. char zwrocnm(int n,int c) const {
  75. if(n>x or n<0) if(c>y or c<0) return -1;
  76. return m[n][c];
  77. }
  78. friend istream& operator>> (istream&, macierz &);
  79. int operator++ (int)
  80. {
  81. return (x+5);
  82. }
  83. void wypelnij(char a='A',char b='Z')
  84. {
  85. for(int i=0;i<x;i++)
  86. for(int j=0;j<y;j++)
  87. m[i][j]=rand()%(b-a+1)+a;
  88. }
  89.  
  90. };
  91.  
  92. istream& operator>> (istream& a, macierz & b)
  93. {
  94. a>>b.x>>b.y;
  95. return a;
  96. }
  97.  
  98. void wyswietl(int *wsk)
  99. {
  100. cout<<&wsk<<" "<<wsk<<" "<<*wsk<<endl;
  101. *wsk=10;
  102. }
  103.  
  104. class postac
  105. {
  106. int hp;
  107. public:
  108. postac(int a):hp(a){};
  109. void pokaz_hp()
  110. {
  111. cout<<hp<<endl;
  112. }
  113. virtual void atak()=0;
  114. virtual ~postac();
  115. };
  116. postac::~postac(){};
  117.  
  118. class rycerz: public postac
  119. {
  120. public:
  121. rycerz(int x):postac(x){};
  122. virtual void atak()
  123. {
  124. cout<<"Atak mieczem"<<endl;
  125. }
  126.  
  127. };
  128.  
  129. class chlop :public postac
  130. {
  131. public:
  132. chlop(int x):postac(x){};
  133. virtual void atak()
  134. {
  135. cout<<"Atak widłami"<<endl;
  136. }
  137.  
  138. };
  139.  
  140. class mag :public postac
  141. {
  142. public:
  143. mag(int x):postac(x){};
  144. virtual void atak()
  145. {
  146. cout<<"Atak kula ognia"<<endl;
  147. }
  148. };
  149.  
  150.  
  151. int main() {
  152. srand(time(NULL));
  153. rycerz ryc(50);
  154. mag mg(40);
  155. chlop ch(60);
  156.  
  157. postac *wsk=&ch;
  158. wsk->pokaz_hp();
  159. wsk->atak();
  160. wsk=&ryc;
  161. wsk->atak();
  162. wsk->pokaz_hp();
  163. wsk=&mg;
  164. wsk->atak();
  165. wsk->pokaz_hp();
  166.  
  167. /*int a=5;
  168. int* wsk=&a;
  169. cout<<*wsk<<" "<<wsk<<" "<<&wsk<<endl;
  170. wyswietl(wsk);
  171. cout<<*wsk<<" "<<wsk<<" "<<&wsk<<endl;
  172. zad2 *abc=new zad2(8);
  173. abc->wczytaj();
  174. abc->pobierz();
  175. //while(1)
  176. {
  177. zad2 *abg=new zad2();
  178. delete abg;
  179. }
  180. delete abc;
  181.  
  182. macierz *ob1=new macierz(2,4,'T');
  183. macierz *ob2=new macierz(3);
  184. const macierz foo=2;
  185. cout<<foo++;
  186. int a=1,b=0;
  187. const int c=1,d=0;
  188. cout<<ob2->zwrocnm(5,4);
  189. while(1)
  190. {
  191. macierz *ob3=new macierz(3);
  192. delete ob3;
  193. }
  194. */
  195. return 0;
  196. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement