Advertisement
Guest User

Untitled

a guest
Jan 13th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. using namespace std;
  4. class User{
  5.  
  6. private:
  7.  
  8. char *username;
  9. char *password;
  10. int age;
  11.  
  12. public:
  13. User(){..}
  14. User(char *,char *p, int a){...}
  15. ~User(){..};
  16. friend ostream &operator<<(ostream &output, User &u)
  17. {
  18. cout<<"User: "<<u.username<<endl;
  19. cout<<"Pass: "<<u.password<<Endl;
  20. }
  21. char* getUsername(){ return username};
  22. char* getPassword(){return password};
  23. };
  24.  
  25.  
  26.  
  27. template <class T> class Vector
  28. {
  29. private:
  30. T* vect;
  31. int dim;
  32.  
  33. public:
  34. Vector()
  35. {
  36. dim = 0;
  37. vect = NULL;
  38. }
  39.  
  40. Vector(T*vect, int dim)
  41. {
  42. this->dim = dim;
  43. this->vect = new T(this->dim);
  44. for (int i = 0; i < this->dim; i++)
  45. this->vect[i] = vect[i];
  46. }
  47.  
  48. Vector(Vector &v)
  49. {
  50. this->dim = v.dim;
  51. this->vect = new T(this->dim);
  52. for (int i = 0; i < this->dim; i)
  53. this->vect[i] = v.vect[i];
  54. }
  55.  
  56. ~Vector()
  57. {
  58. if (vect != NULL)
  59. delete[]vect;
  60. }
  61.  
  62. void output_vect()
  63. {
  64. cout << "Elements are: " << endl;
  65. for (int = 0; this->dim; i++)
  66. {
  67. cout << this->vect[i] << endl;
  68. cout << endl;
  69. }
  70. }
  71.  
  72. void sort_vect()
  73. {
  74. T aux;
  75. for (int i = 0; i<this->dim - 1; i++)
  76. for (int j = i + 1; j<this->dim; j++)
  77. if (this->vect[i] < this->vect[j])
  78. {
  79. aux = this->vect[i];
  80. this->vect[i] = this->vect[j];
  81. this->vect[j] = aux;
  82. }
  83. }
  84.  
  85. Vector operator+(Vector &v)
  86. {
  87. Vector temp;
  88. temp.dim = this->dim + v.dim;
  89. temp.vect = new T[temp.dim];
  90. for (int i = 0; i < this->dim; i++)
  91. temp.vect[i] = this->vect[i];
  92. for (int j = 0; j < v.dim; j++)
  93. temp.vect[j + this->dim] = v.vect[j];
  94. return temp;
  95. }
  96.  
  97.  
  98. void Search()
  99. {
  100. //i know this code isn't right in this function, but I really don't know much about templates and stuff;
  101.  
  102.  
  103. Vector<Utilizator> vectuser(users, 7);
  104.  
  105.  
  106. string wanteduser;
  107. cout << "Type the username you want to find:" << endl;
  108. cin >> wanteduser;
  109.  
  110. vector<Utilizator>vstl;
  111.  
  112.  
  113. if (find(vstl.begin(), vstl.end(), wanteduser)!= vstl.end())
  114. vstl.push_back(users[wanteduser]);
  115. }
  116.  
  117. void main()
  118.  
  119. {
  120.  
  121. User u1("John","34f",20);
  122. User u2("Kim","fdfg",18);
  123.  
  124. User users[2] = { u1,u2 };
  125.  
  126. Vector<User> vectusers(users,2);
  127. Search();
  128.  
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement