Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************
- Welcome to GDB Online.
- GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
- C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
- Code, Compile, Run and Debug online from anywhere in world.
- *******************************************************************************/
- #include <iostream>
- #include <vector>
- using namespace std;
- class Test {
- public:
- int chislo;
- Test () {}
- Test(int x) {
- chislo = x;
- }
- bool operator==(Test& other) {
- return chislo == other.chislo;
- }
- };
- ostream& operator<<(ostream& o, Test& x) {
- o << "chisloto e :" << x.chislo << endl;
- return o;
- }
- class Test2 {
- public:
- vector<Test> obekti; // или вектор
- Test obekti_2[10000]; // или масив
- int last_element = 0;
- Test2 () {}
- // funkciq, koqto kazva dali ima element s opredelena stoinost na chislo
- // funkciq, koqto dobavq element
- void add(Test x) {
- obekti.push_back(x);
- }
- Test2* operator+(Test& x) {
- obekti.push_back(x);
- return this;
- }
- void add_array(Test x) {
- obekti_2[last_element++] = x;
- //last_element++;
- }
- bool findObject(int x) {
- bool found = false;
- // for (Test a : obekti) {
- // if (obekti[i].chislo == x) found = true;
- // }
- for (int i = 0; i < obekti.size(); i++) {
- if (obekti[i].chislo == x) found = true;
- }
- return found;
- }
- };
- ostream& operator<<(ostream& o, Test2& x) {
- for (Test& a : x.obekti) {
- cout << a;
- }
- return o;
- }
- int main()
- {
- Test a(12);
- Test b(23);
- Test2 y;
- y + b;
- y + a;
- cout << y;
- y.findObject(10);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement