Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. B6
  2.  
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. typedef int TElem;
  8.  
  9. class Sir {
  10.  
  11.     TElem elem[512];
  12.     int dim;
  13.  
  14. public:
  15.  
  16.  
  17.     void citire() {
  18.         cout << "Dimensiunea = (>2)";
  19.         cin >> dim;
  20.         for (int i = 0; i < dim; i++) {
  21.             cout << "elem[" << i << "] = ";
  22.             cin >> elem[i];
  23.         }
  24.     }
  25.    
  26.     TElem operator[](int i) {
  27.         return this->elem[i];
  28.     }
  29.  
  30.     void  operator=(const Sir &v) {
  31.         this->dim = v.dim;
  32.         for (int i = 0; i < v.dim; i++) {
  33.             this->elem[i] = v.elem[i];
  34.         }
  35.     }
  36.  
  37.     int  operator()(int val) {
  38.         for (int i = 0; i < dim; i++) {
  39.             if (this->elem[i] == val) {
  40.                 return i;
  41.             }
  42.         }
  43.         return -1;
  44.     }
  45.  
  46.     int getLg() {
  47.         return this->dim;
  48.     }
  49.  
  50. };
  51.  
  52. int main() {
  53.  
  54.     Sir v;
  55.     Sir v2;
  56.     v.citire();
  57.     v2 = v;
  58.     cout << "Elementul de pe poz 2 este : ";
  59.     cout << v[2] << "\n";
  60.     cout << "Elementul de pe poz 2  in vectorul 2 este : ";
  61.     cout << v2[2] << "\n";
  62.     cout << "Introduceti un element sa il cautam : ";
  63.     int el;
  64.     cin >> el;
  65.     cout << "Elementul " << el << " se gaseste pe poz " << v2(el) << "\n";
  66.  
  67.     system("pause");
  68.  
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement