Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- using namespace std;
- class User{
- private:
- char *username;
- char *password;
- int age;
- public:
- User(){..}
- User(char *,char *p, int a){...}
- ~User(){..};
- friend ostream &operator<<(ostream &output, User &u)
- {
- cout<<"User: "<<u.username<<endl;
- cout<<"Pass: "<<u.password<<Endl;
- }
- char* getUsername(){ return username};
- char* getPassword(){return password};
- };
- template <class T> class Vector
- {
- private:
- T* vect;
- int dim;
- public:
- Vector()
- {
- dim = 0;
- vect = NULL;
- }
- Vector(T*vect, int dim)
- {
- this->dim = dim;
- this->vect = new T(this->dim);
- for (int i = 0; i < this->dim; i++)
- this->vect[i] = vect[i];
- }
- Vector(Vector &v)
- {
- this->dim = v.dim;
- this->vect = new T(this->dim);
- for (int i = 0; i < this->dim; i)
- this->vect[i] = v.vect[i];
- }
- ~Vector()
- {
- if (vect != NULL)
- delete[]vect;
- }
- void output_vect()
- {
- cout << "Elements are: " << endl;
- for (int = 0; this->dim; i++)
- {
- cout << this->vect[i] << endl;
- cout << endl;
- }
- }
- void sort_vect()
- {
- T aux;
- for (int i = 0; i<this->dim - 1; i++)
- for (int j = i + 1; j<this->dim; j++)
- if (this->vect[i] < this->vect[j])
- {
- aux = this->vect[i];
- this->vect[i] = this->vect[j];
- this->vect[j] = aux;
- }
- }
- Vector operator+(Vector &v)
- {
- Vector temp;
- temp.dim = this->dim + v.dim;
- temp.vect = new T[temp.dim];
- for (int i = 0; i < this->dim; i++)
- temp.vect[i] = this->vect[i];
- for (int j = 0; j < v.dim; j++)
- temp.vect[j + this->dim] = v.vect[j];
- return temp;
- }
- void Search()
- {
- //i know this code isn't right in this function, but I really don't know much about templates and stuff;
- Vector<Utilizator> vectuser(users, 7);
- string wanteduser;
- cout << "Type the username you want to find:" << endl;
- cin >> wanteduser;
- vector<Utilizator>vstl;
- if (find(vstl.begin(), vstl.end(), wanteduser)!= vstl.end())
- vstl.push_back(users[wanteduser]);
- }
- void main()
- {
- User u1("John","34f",20);
- User u2("Kim","fdfg",18);
- Utilizator users[7] = { u1,u2,u3,u4,u5,u6,u7 };
- Vector<Utilizator> vectusers(users,7);
- Search();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement