Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- using namespace std;
- class MyClass
- {
- int *array1;
- int size1;
- int *array2;
- int size2;
- public:
- MyClass();
- MyClass(int*, int, int*, int);
- MyClass(const MyClass&);
- ~MyClass();
- void input();
- void output();
- void operator=(MyClass&);
- };
- MyClass::MyClass(int* t1,int n1, int* t2, int n2)
- {
- size1 = n1; size2 = n2;
- array1 = new int[size1 + 1];
- for(int i = 0; i < size1 + 1; i++)
- array1[i] = t1[i];
- array2 = new int[size2 + 1];
- for(int i = 0; i < size2 + 1; i++)
- array2[i] = t2[i];
- }
- MyClass::MyClass()
- {
- array1 = new int; array1[0] = 0;
- array2 = new int; array2[0] = 0;
- }
- MyClass::MyClass(const MyClass& ob)
- {
- size1 = ob.size1;
- size2 = ob.size2;
- array1 = new int[ob.size1 + 1];
- for(int i = 0; i < size1 + 1; i++)
- array1[i] = ob.array1[i];
- array2 = new int[ob.size2 + 1];
- for(int i = 0; i < size2 + 1; i++)
- array2[i] = ob.array2[i];
- }
- MyClass::~MyClass()
- {
- delete[]array1;
- delete[]array2;
- }
- void MyClass::input()
- {
- delete[] array1;
- delete[] array2;
- cout << "Input size1: ";
- cin >> size1;
- cout << "Array1: ";
- array1 = new int[size1 + 1];
- for(int i = 0; i < size1 + 1; i++)
- cin >> array1[i];
- cout << "Input size2: ";
- cin >> size2;
- cout << "Array2: ";
- array2 = new int[size2 + 1];
- for(int i = 0; i < size2 + 1; i++)
- cin >> array2[i];
- }
- void MyClass::output()
- {
- cout << "Result: ";
- for(int i = 0; i < size1 + 1; i++)
- cout << array1[i] << " ";
- cout << endl;
- for(int i = 0; i < size2 + 1; i++)
- cout << array2[i] << " ";
- }
- void MyClass::operator=(MyClass& ob)
- {
- if(this == &ob) return;
- delete[] array1;
- delete[] array2;
- array1 = new int[size1 + 1];
- for(int i = 0; i < size1 + 1; i++)
- array1[i] = ob.array1[i];
- array2 = new int[size2 + 1];
- for(int i = 0; i < size2 + 1; i++)
- array2[i] = ob.array2[i];
- }
- int main()
- {
- MyClass A, B;
- A.input();
- B = A;
- B.output();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement