Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- B6
- #include <iostream>
- using namespace std;
- typedef int TElem;
- class Sir {
- 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 Sir &v) {
- this->dim = v.dim;
- for (int i = 0; i < v.dim; i++) {
- this->elem[i] = v.elem[i];
- }
- }
- int operator()(int val) {
- for (int i = 0; i < dim; i++) {
- if (this->elem[i] == val) {
- return i;
- }
- }
- return -1;
- }
- int getLg() {
- return this->dim;
- }
- };
- int main() {
- Sir v;
- Sir v2;
- 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";
- cout << "Introduceti un element sa il cautam : ";
- int el;
- cin >> el;
- cout << "Elementul " << el << " se gaseste pe poz " << v2(el) << "\n";
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement