Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <fstream>
  5.  
  6.  
  7. using namespace std;
  8.  
  9. class card {
  10. private:
  11. string ID;
  12. string name;
  13. string lastname;
  14. string age;
  15. string university;
  16. public:
  17. card(string _ID, string _name, string _lastname, string _age, string _university) {
  18. ID = _ID;
  19. name = _name;
  20. lastname = _lastname;
  21. age = _age;
  22. university = _university;
  23. }
  24. #pragma region getters
  25. string getID() {
  26. return ID;
  27. }
  28. string getName() {
  29. return name;
  30. }
  31. string getLastname() {
  32. return lastname;
  33. }
  34. string getAge() {
  35. return age;
  36. }
  37. string getUniversity() {
  38. return university;
  39. }
  40. #pragma endregion
  41. };
  42.  
  43. void menu(vector<card> sl);
  44.  
  45. void studentsBrowser(vector<card> sl);
  46.  
  47. void lookForStudentWithID(vector<card> sl);
  48.  
  49. vector<card> getAllUsersFromDB();
  50.  
  51. void addDeclaredUsersToDB(vector<card> instance);
  52.  
  53. void addUsersToDB(vector<card>ls);
  54.  
  55. int main() {
  56. //card stud1("01001089009", "Tornike", "Qurdadze", "19", "Tbilisi State University");
  57. //card stud2("65012305914", "Gio", "Bitsadze", "20", "Tbilisi State University");
  58. //card stud3("93851399302", "Mate", "Gvaramadze", "21", "Tbilisi Free University");
  59.  
  60. vector<card> sl = getAllUsersFromDB();
  61.  
  62. //sl.push_back(stud1);
  63. //sl.push_back(stud2);
  64. //sl.push_back(stud3);
  65. //addDeclaredUsersToDB(sl);
  66. menu(sl);
  67.  
  68. cin.get();
  69. cin.get();
  70. }
  71.  
  72. void menu(vector<card> sl) {
  73. system("cls");
  74. cout << "1) Check all students" << endl;
  75. cout << "2) Find student with specific ID" << endl;
  76. cout << "3) Add a new user" << endl;
  77. cout << "4) Exit" << endl;
  78. int switcher = 0;
  79. cin >> switcher;
  80. switch (switcher)
  81. {
  82. case 1:
  83. studentsBrowser(sl);
  84. break;
  85. case 2:
  86. lookForStudentWithID(sl);
  87. break;
  88. case 3:
  89. addUsersToDB(sl);
  90. break;
  91. case 4:
  92. exit(1);
  93. break;
  94. default:
  95. exit(1);
  96. break;
  97. }
  98. }
  99.  
  100. void studentsBrowser(vector<card> sl) {
  101. system("cls");
  102. for (auto item : sl)
  103. {
  104. cout << "ID: " << item.getID() << endl;
  105. cout << "Name: " << item.getName() << endl;
  106. cout << "Lastname: " << item.getLastname() << endl;
  107. cout << "Age: " << item.getAge() << endl;
  108. cout << "University: " << item.getUniversity() << endl;
  109. cout << endl;
  110. cout << "****************************************";
  111. cout << endl;
  112. }
  113. }
  114.  
  115. void lookForStudentWithID(vector<card> sl)
  116. {
  117. system("cls");
  118. cout << "Enter the ID of student you are looking for : ";
  119. string _ID;
  120. cin >> _ID;
  121. for (auto item : sl)
  122. {
  123. if (item.getID() == _ID)
  124. {
  125. cout << "ID: " << item.getID() << endl;
  126. cout << "Name: " << item.getName() << endl;
  127. cout << "Lastname: " << item.getLastname() << endl;
  128. cout << "Age: " << item.getAge() << endl;
  129. cout << "University: " << item.getUniversity() << endl;
  130. cout << endl;
  131. cout << endl;
  132. }
  133. }
  134. }
  135.  
  136. vector<card> getAllUsersFromDB()
  137. {
  138. vector<card> sl;
  139. string ID;
  140. string name;
  141. string lastname;
  142. string age;
  143. string university;
  144.  
  145. ifstream db;
  146. db.open("AdditionalUsers.dat");
  147.  
  148. string line;
  149. int amountOfUsers = 0;
  150. int lineNumber = 0;
  151.  
  152. while (getline(db, line)) {
  153. if (lineNumber == 0) {
  154. ID = line;
  155. }
  156. else if (lineNumber == 1) {
  157. name = line;
  158. }
  159. else if (lineNumber == 2) {
  160. lastname = line;
  161. }
  162. else if (lineNumber == 3) {
  163. age = line;
  164. }
  165. else if (lineNumber == 4) {
  166. university = line;
  167. lineNumber = -1;
  168. card student(ID, name, lastname, age, university);
  169. sl.push_back(student);
  170. }
  171. lineNumber++;
  172. }
  173. db.close();
  174. return sl;
  175. }
  176.  
  177. void addDeclaredUsersToDB(vector<card> instance) {
  178. ofstream dbFile;
  179. string ID;
  180. string name;
  181. string lastname;
  182. string age;
  183. string university;
  184. dbFile.open("AdditionalUsers.dat", ios::app);
  185. for (auto item : instance)
  186. {
  187. ID = item.getID();
  188. name = item.getName();
  189. lastname = item.getLastname();
  190. age = item.getAge();
  191. university = item.getUniversity();
  192.  
  193. dbFile << ID << endl << name << endl << lastname << endl << age << endl << university;
  194. }
  195. }
  196.  
  197. void addUsersToDB(vector<card> ls)
  198. {
  199. system("cls");
  200. #pragma region declarations
  201. string ID;
  202. string name;
  203. string lastname;
  204. string age;
  205. string university;
  206. cout << "Enter ID: ";
  207. cin >> ID;
  208. cout << endl << "Enter name: ";
  209. cin >> name;
  210. cout << endl << "Enter lastname: ";
  211. cin >> lastname;
  212. cout << endl << "Enter age: ";
  213. cin >> age;
  214. cout << endl << "Enter university: ";
  215. cin >> university;
  216. cout << endl;
  217. #pragma endregion
  218.  
  219. ofstream dbFile;
  220. dbFile.open("AdditionalUsers.dat", ios::app);
  221. dbFile << ID << endl << name << endl << lastname << endl << age << endl << university;
  222. cout << "User Successfully added to database." << endl;
  223. dbFile.close();
  224. ls = getAllUsersFromDB();
  225. menu(ls);
  226. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement