Created
February 12, 2017 17:35
-
-
Save Steffo99/01deb8dd02ecd01cd19ff90deec56ced to your computer and use it in GitHub Desktop.
More homework.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| class Insieme { | |
| private: | |
| int* pointers[10]; | |
| int size; | |
| public: | |
| Insieme() | |
| { | |
| this->size = 0; | |
| for(int p = 0; p < 10; p++) | |
| { | |
| this->pointers[p] = 0; | |
| } | |
| } | |
| Insieme(const Insieme& copy) | |
| { | |
| this->size = copy.size; | |
| for(int p = 0; p < copy.size; p++) | |
| { | |
| this->pointers[p] = new int(); | |
| *(this->pointers[p]) = *(copy.pointers[p]); | |
| } | |
| } | |
| ~Insieme() | |
| { | |
| for(int p = 0; p < this->size; p++) | |
| { | |
| delete pointers[p]; | |
| } | |
| } | |
| bool operator +=(int n) | |
| { | |
| if(this->size >= 10) | |
| { | |
| return false; | |
| } | |
| this->pointers[size] = new int(); | |
| *this->pointers[size] = n; | |
| this->size++; | |
| return true; | |
| } | |
| void del() | |
| { | |
| delete pointers[size]; | |
| size--; | |
| } | |
| bool operator ==(Insieme a) | |
| { | |
| if(this->size != a.size) | |
| { | |
| return false; | |
| } | |
| for(int c = 0; c < this->size; c++) | |
| { | |
| if(*(this->pointers[c]) != *(a.pointers[c])) | |
| { | |
| return false; | |
| } | |
| } | |
| return true; | |
| } | |
| friend ostream& operator<<(ostream& o, Insieme i); | |
| }; | |
| ostream& operator<<(ostream& o, Insieme i) | |
| { | |
| o << "["; | |
| for(int c = 0; c < i.size; c++) | |
| { | |
| o << *(i.pointers[c]); | |
| if(c < i.size-1) | |
| { | |
| o << ", "; | |
| } | |
| } | |
| o << "]"; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include "insieme.cpp" | |
| using namespace std; | |
| int main() | |
| { | |
| Insieme a, b, c, d; | |
| a += 1; | |
| a += 2; | |
| a += 3; | |
| cout << a << '\n'; | |
| b += 3; | |
| c += 3; | |
| b += 2; | |
| c += 2; | |
| b += 1; | |
| c += 1; | |
| cout << b << '\n' << c << '\n'; | |
| cout << (b==c) << '\n' << (a==b) << '\n'; | |
| d += 1; | |
| d += 2; | |
| d += 3; | |
| d += 999; | |
| d.del(); | |
| cout << d << '\n'; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment