Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. class macierz {
  5.  
  6. int **tab;
  7. int wymiar_x;
  8. int wymiar_y;
  9. public:
  10. macierz()
  11. {
  12. int **tab = new int*[1];
  13. //tab[0] = new int[1];
  14. wymiar_x = 1;
  15. wymiar_y = 1;
  16. this->tab = tab;
  17. }
  18.  
  19. macierz(int x,int y)
  20. {
  21. if(x>0 && y>0)
  22. {
  23. this->wymiar_x = x;
  24. this->wymiar_y = y;
  25. int **tab = new int*[x];
  26. for (int i=0;i<x;i++)
  27. {
  28. tab[i] = new int[y];
  29. }
  30.  
  31. this->tab = tab;
  32. }
  33.  
  34. }
  35. //konstruktor kopiujacy
  36. macierz(macierz &m)
  37. {
  38. this->tab = m.tab;
  39. this->wymiar_x = m.wymiar_x;
  40. this->wymiar_y = m.wymiar_y;
  41. }
  42.  
  43. int get_wymiar_x()
  44. {
  45. return this->wymiar_x;
  46. }
  47.  
  48. int get_wymiar_y()
  49. {
  50. return this->wymiar_y;
  51. }
  52.  
  53. int get_tab(int x, int y)
  54. {
  55. if(x<=this->wymiar_x && y<=this->wymiar_y)
  56. return tab[x][y];
  57. else
  58. return 0;
  59. }
  60.  
  61. void set_tab(int wartosc,int x, int y)
  62. {
  63. if(x<=this->wymiar_x && y<=this->wymiar_y)
  64. tab[x][y] = wartosc;
  65.  
  66. }
  67.  
  68. void realokuj_macierz(int x, int y)
  69. {
  70. int **nowy_tab = new int*[x];
  71. for (int i=0;i<x;i++)
  72. {
  73. tab[i] = new int[y];
  74. }
  75.  
  76. for(int i=0;i<x;i++)
  77. {
  78. for(int j=0;j<y;j++)
  79. {
  80. nowy_tab[i][j] = this->tab[i][j];
  81. }
  82. }
  83.  
  84. this->tab = nowy_tab;
  85. }
  86.  
  87. };
  88.  
  89. int main()
  90. {
  91. macierz *m = new macierz();
  92. macierz *m1 = new macierz(10,10);
  93.  
  94. m1->set_tab(777,5,6);
  95.  
  96.  
  97. macierz *m3 = new macierz(*m1);
  98. cout << m3->get_tab(5,6);
  99.  
  100. return 0;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement