Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Stworz klase int2d oraz przeciaz operator() aby mozna bylo wywolac program wg kodu ponizej:
- int main()
- {
- int2d t1(4,3);
- for(int i=0; i<4; i++)
- for(int j=0; j<3; j++)
- t1(i,j)=i+j;
- for(int i=0; i<4; i++)
- {
- for(int j=0; j<3; j++) cout << t1(i,j)<<" ";
- cout<<endl;
- }
- }
- Wyświetlał następujące wyniki:
- 0 1 2
- 1 2 3
- 2 3 4
- 3 4 5
- */
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- #include <queue>
- #include <fstream>
- #include <vector>
- using namespace::std;
- class int2d : public vector<vector<int>> {
- public:
- vector<vector<int>> vec;
- int a;
- int b;
- int2d(int a = 0, int b = 0) {
- vector<int> tmp(b);
- fill(tmp.begin(), tmp.end(), 0);
- for(int i = 0; i < a; i++) vec.push_back(tmp);
- }
- int2d& operator = (const int2d& X){
- if (this == &X)
- return *this;
- int2d tmp(X.a, X.b);
- }
- int& operator()(int aa, int bb){
- a = aa;
- b = bb;
- return vec[a][b];
- }
- };
- int _tmain(int argc, _TCHAR* argv[]){
- int2d t1(4, 3);
- for(int i = 0; i < 4; i++)
- {
- for(int j = 0; j < 3; j++)
- {
- t1(i, j) = i + j;
- }
- }
- for(int i = 0; i < 4; i++)
- {
- for(int j = 0; j < 3; j++)
- cout << t1(i, j) << " ";
- {
- cout<<endl;
- }
- }
- system("PAUSE");
- }
Advertisement
Add Comment
Please, Sign In to add comment