Advertisement
Guest User

Untitled

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