Advertisement
Guest User

A6

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