Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- typedef int TElem;
- class Vector {
- TElem elem[512];
- int dim;
- public:
- void citire() {
- cout << "Dimensiunea = (>2)";
- cin >> dim;
- for (int i = 0; i < dim; i++) {
- cout << "elem[" << i << "] = ";
- cin >> elem[i];
- }
- }
- TElem operator[](int i) {
- return this->elem[i];
- }
- void operator=(const Vector &v) {
- this->dim = v.dim;
- for (int i = 0; i < v.dim; i++) {
- this->elem[i] = v.elem[i];
- }
- }
- void operator()(const Vector &v) {
- for (int i = 0; i < v.dim; i++) {
- this->elem[i] = v.elem[i];
- }
- this->dim = v.dim;
- for (int i = 0; i <= v.dim - 2; i++) {
- for (int j = i + 1; j < v.dim; j++) {
- if (elem[i] > elem[j]) {
- int aux = elem[i];
- elem[i] = elem[j];
- elem[j] = aux;
- }
- }
- }
- }
- int getLg() {
- return this->dim;
- }
- };
- int main() {
- Vector v;
- Vector v2;
- Vector v3;
- v.citire();
- v2 = v;
- cout << "Elementul de pe poz 2 este : ";
- cout << v[2] << "\n";
- cout << "Elementul de pe poz 2 in vectorul 2 este : ";
- cout << v2[2] << "\n";
- v3(v);
- int lg = v3.getLg();
- cout << "Vectorul sortat este \n";
- for (int i = 0; i < lg; i++) {
- cout << v3[i] << " ";
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement