Advertisement
Razorspined

Untitled

Jan 14th, 2025
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.86 KB | None | 0 0
  1. /******************************************************************************
  2.  
  3. Welcome to GDB Online.
  4. GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
  5. C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
  6. Code, Compile, Run and Debug online from anywhere in world.
  7.  
  8. *******************************************************************************/
  9. #include <iostream>
  10. #include <vector>
  11.  
  12. using namespace std;
  13.  
  14. class Test {
  15.     public:
  16.     int chislo;
  17.    
  18.     Test () {}
  19.    
  20.     Test(int x) {
  21.         chislo = x;
  22.     }
  23.    
  24.     bool operator==(Test& other) {
  25.         return chislo == other.chislo;
  26.     }
  27.    
  28.  
  29. };
  30.  
  31. ostream& operator<<(ostream& o, Test& x) {
  32.     o << "chisloto e :" << x.chislo << endl;
  33.     return o;
  34. }
  35.  
  36. class Test2 {
  37.     public:
  38.     vector<Test> obekti;  // или вектор
  39.     Test obekti_2[10000]; // или масив
  40.     int last_element = 0;
  41.    
  42.     Test2 () {}
  43.    
  44.     // funkciq, koqto kazva dali ima element s opredelena stoinost na chislo
  45.     // funkciq, koqto dobavq element
  46.    
  47.     void add(Test x) {
  48.         obekti.push_back(x);
  49.     }
  50.    
  51.     Test2* operator+(Test& x) {
  52.         obekti.push_back(x);
  53.         return this;
  54.     }
  55.    
  56.     void add_array(Test x) {
  57.         obekti_2[last_element++] = x;
  58.         //last_element++;
  59.     }
  60.    
  61.    
  62.    
  63.     bool findObject(int x) {
  64.          bool found = false;
  65.        // for (Test a : obekti) {
  66.             //  if (obekti[i].chislo == x) found = true;
  67.        // }
  68.        
  69.         for (int i = 0; i < obekti.size(); i++) {
  70.             if (obekti[i].chislo == x) found = true;
  71.         }
  72.        
  73.         return found;
  74.     }
  75. };
  76.  
  77. ostream& operator<<(ostream& o, Test2& x) {
  78.     for (Test& a : x.obekti) {
  79.         cout << a;
  80.     }
  81.     return o;
  82. }
  83.  
  84. int main()
  85. {
  86.  
  87.     Test a(12);
  88.     Test b(23);
  89.    
  90.     Test2 y;
  91.     y + b;
  92.     y + a;
  93.    
  94.    
  95.     cout << y;
  96.     y.findObject(10);
  97.     return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement