Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- #define MAX 5
- class NizBrojeva {
- public:
- int* niz;
- public:
- NizBrojeva();
- NizBrojeva(int*, int);
- NizBrojeva& operator-=(const NizBrojeva&);
- friend NizBrojeva operator+(const NizBrojeva&, const NizBrojeva&);
- friend ostream& operator<<(ostream&, const NizBrojeva&);
- };
- NizBrojeva::NizBrojeva() {
- niz = new int[MAX];
- for (int i = 0; i < MAX; i++)
- niz[i] = 0;
- }
- NizBrojeva::NizBrojeva(int* pok, int n) {
- niz = new int[MAX];
- for (int i = 0; i < MAX; i++)
- if (i < n)
- niz[i] = pok[i];
- else
- niz[i] = 0;
- }
- NizBrojeva& NizBrojeva::operator-=(const NizBrojeva& n) {
- for (int i = 0; i < MAX; i++)
- niz[i] -= n.niz[i];
- return *this;
- }
- NizBrojeva operator+(const NizBrojeva& n1, const NizBrojeva& n2) {
- NizBrojeva n;
- int br = 0;
- for (int i = 0; i < MAX; i++)
- if (n1.niz[i] == n2.niz[i])
- n.niz[br++] = 1;
- else
- n.niz[br++] = 0;
- return n;
- }
- ostream& operator<<(ostream& out, const NizBrojeva& n) {
- for (int i = 0; i < MAX; i++)
- out << n.niz[i] << " ";
- return out;
- }
- int main()
- {
- int niz1[] = { 3, 5, 6, 8, 9, 1 };
- int niz2[] = { 5, 2, 6, 0, 9, 1 };
- int niz3[] = { 5, 2, 6 };
- NizBrojeva n1, n2(niz1, 5), n3(niz2, 5), n4(niz3, 3);
- cout << "n1: " << n1 << endl;
- cout << "n2: " << n2 << endl;
- cout << "n3: " << n3 << endl;
- cout << "n4: " << n4 << endl << endl;
- cout << "n1 + n2: " << n1 + n2 << endl;
- cout << "n2 + n3: " << n2 + n3 << endl;
- cout << "n3 + n4: " << n3 + n4 << endl << endl;
- cout << "n1 -= n2" << endl;
- n1 -= n2;
- cout << "n1: " << n1 << endl << endl;
- cout << "n2 -= n3" << endl;
- n2 -= n3;
- cout << "n2: " << n2 << endl << endl;
- cout << "n3 -= n4" << endl;
- n3 -= n4;
- cout << "n3: " << n3 << endl << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement