Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. using namespace std;
  2. class Tablica2d{
  3. private:
  4.     int name;
  5.     int width;
  6.     int height;
  7.     int *w;
  8.  
  9.  
  10. public:
  11.     Tablica2d(int width, int height, int name){
  12.         this->name = name;
  13.         this->width = width;
  14.         this->height = height;
  15.         w = new int[width*height];
  16.     }
  17.     Tablica2d(const Tablica2d&copy)
  18.     {
  19.         name = copy.name;
  20.         width = copy.width;
  21.         height = copy.height;
  22.         w = copy.w;
  23.     }
  24.     void read(){
  25.         cout << name << endl;
  26.         cout << height << endl;
  27.         cout << width << endl;
  28.     }
  29. //    void readArray(int c){
  30. //        cout << w[c]<< endl;
  31. //    }
  32.  
  33.     void changeName(int name){
  34.         this->name = name;
  35.     }
  36.  
  37.     void setValue(int row, int column, int value)
  38.     {
  39.         int cell = row*width+column;
  40.         this->w[cell] = value;
  41.  
  42.     }
  43.  
  44.     void readCell(int cell){
  45.         cout << w[cell];
  46.     }
  47.  
  48.     ~Tablica2d(){
  49.         delete[] w;
  50.     }
  51. };
  52.  
  53. int main()
  54. {
  55.  
  56.     Tablica2d tablica1(2,3,1);
  57.     Tablica2d tablica2(tablica1);
  58.  
  59.     tablica2.setValue(0,0,22);
  60.     tablica2.readCell(0);
  61.  
  62.  
  63.  
  64.  
  65.  
  66.     return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement