Advertisement
Jaymlbnn

Untitled

May 23rd, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.11 KB | None | 0 0
  1. #include <iostream>
  2. #include<conio.h>
  3. #include<cstring>
  4. #include<cstdlib>
  5. #include <iomanip>
  6. #include<windows.h>
  7. #include<cstdio>
  8. #include <fstream>
  9. #include <cstring>
  10. #include <string>
  11.  
  12.  
  13.  
  14. using namespace std;
  15.  
  16. struct boarder {
  17.  
  18. string fname, lname, address;
  19. string contact;
  20. string b_id;
  21. int b_list = 0;
  22. };
  23.  
  24. int occupant_ptr = 0;
  25. int sss;
  26. string yourchoice, choice;
  27. boarder dormer[50], tempemp[40], sortemp[50], sorttemp1[50];
  28.  
  29. void show();
  30. //void first();
  31. //void second();
  32.  
  33. void display_list();
  34. void add();
  35. void deletes();
  36. void menu();
  37. void edit();
  38. void search();
  39.  
  40.  
  41. void edit_menu();
  42. void id(int);
  43. void edit_fname(int);
  44. void editlastname(int);
  45. void edit_contact(int);
  46.  
  47.  
  48. int main()
  49. {
  50. string user, pw;
  51. int attempt = 0, ch;
  52. s:
  53. std::system("cls");
  54. std::cout << "\t ====================================================== \n";
  55. std::cout << "\t LOG IN \n";
  56. std::cout << "\t ====================================================== \n";
  57. std::cout << "\t \tUsername: ";
  58. std::cin >> user;
  59. std::cout << "\t \tPassword: ";
  60. while (ch = _getch()) {
  61. if (ch == 13) {
  62. if (user == "admin" && pw == "1234") {
  63. menu();
  64. break;
  65. }
  66. attempt += 1;
  67. std::cout << " \n ------------------------------------------------------ \n";
  68. std::cout << " Invalid username or password. Try again! \n";
  69. std::cout << " ";
  70. system("pause");
  71. if (attempt == 3) {
  72. exit(0);
  73. }
  74. pw = "";
  75. goto s;
  76.  
  77.  
  78. }
  79.  
  80. else if (ch == 8) {
  81. if (pw.length() > 0) {
  82. std::cout << "\b";
  83. pw.erase(pw.length() - 1);
  84. }
  85. }
  86. else {
  87. std::cout << "*";
  88. pw += ch;
  89. }
  90. }
  91.  
  92.  
  93. _getch();
  94. return 0;
  95. }
  96. void menu()
  97. {
  98. int option;
  99. std::system("cls");
  100. std::cout << "\t ====================================================== \n";
  101. std::cout << "\t MENU \n";
  102. std::cout << "\t ====================================================== \n";
  103. std::cout << "\t \t 1. View Boarder List \n";
  104. std::cout << "\t \t 2. Add Boarder \n";
  105. std::cout << "\t \t 3. Delete Boarder \n";
  106. std::cout << "\t \t 4. Search Boarder \n";
  107. std::cout << "\t \t 5. Edit Boarder \n";
  108. std::cout << "\t \t 6. Exit \n";
  109. std::cout << "\t ------------------------------------------------------ \n";
  110. std::cout << "\t Enter your choice: ";
  111. std::cin >> option;
  112. switch (option)
  113. {
  114. case 1:
  115. display_list();
  116. break;
  117. case 2:
  118. add();
  119. break;
  120. case 3:
  121. deletes();
  122. break;
  123. case 4:
  124. search();
  125. break;
  126. case 5:
  127. edit();
  128. break;
  129. case 6:
  130. exit(0);
  131.  
  132. default:
  133. std::cout << "\t Invalid Input. Please try again! \n";
  134. std::cout << "\t ";
  135.  
  136. }
  137. std::system("pause");
  138. menu();
  139. }
  140. void display_list()
  141. {
  142. std::system("cls");
  143. std::cout << "\t ====================================================== \n";
  144. std::cout << "\t BOARDER LIST \n";
  145. std::cout << "\t ====================================================== \n";
  146. for (int i = 0;i < occupant_ptr; i++)
  147.  
  148. {
  149. std::cout << "\t Boarder ID: " << dormer[i].b_id << "\n";
  150. std::cout << "\t Name: " << dormer[i].fname << ' ' << dormer[i].lname << "\n";
  151. std::cout << "\t Address: " << dormer[i].address << "\n";
  152. std::cout << "\t Contact no: " << dormer[i].contact << "\n";
  153. std::cout << "\t ------------------------------------------------------ \n";
  154.  
  155. }
  156. std::cout << "\t ";
  157. std::system("pause");
  158. menu();
  159.  
  160. }
  161. void add()
  162. {
  163. int i = occupant_ptr;
  164. std::system("cls");
  165. d:
  166. std::cout << "\t ====================================================== \n";
  167. std::cout << "\t ADD BOARDER \n";
  168. std::cout << "\t ====================================================== \n";
  169.  
  170. std::cout << "\t Enter Boarder ID: "; std::cin >> dormer[i].b_id;
  171. std::cout << "\t Enter Firstname: "; std::cin.ignore(); getline(cin, dormer[i].fname);
  172. std::cout << "\t Enter Lastname: "; getline(cin, dormer[i].lname);
  173. std::cout << "\t Enter Address: "; getline(cin, dormer[i].address);
  174. std::cout << "\t Enter Contact NO.: "; std::cin >> dormer[i].contact;
  175.  
  176. std::cout << "\t ------------------------------------------------------ \n";
  177. occupant_ptr++;
  178. jump:
  179. std::cout << "\t Do you want to add another boarder? [Y/N:] ";
  180. std::cin >> yourchoice;
  181. if (yourchoice == "Y" || yourchoice == "y") {
  182. std::system("cls");
  183. add();
  184. }
  185. else if (yourchoice == "n" || yourchoice == "N") {
  186. menu();
  187. }
  188. else {
  189. std::cout << "\t Invalid input. Try again! \n" << "\t ";
  190. std::system("pause");
  191. goto jump;
  192. }
  193. }
  194.  
  195. void show() {
  196.  
  197. std::system("cls");
  198. std::cout << "\t ====================================================== \n";
  199. std::cout << "\t BOARDER LIST \n";
  200. std::cout << "\t ====================================================== \n";
  201. for (int s = 0; s < occupant_ptr; s++)
  202.  
  203. {
  204. std::cout << "\t Boarder ID: " << dormer[s].b_id << "\n";
  205. std::cout << "\t Name: " << dormer[s].fname << ' ' << dormer[s].lname << "\n";
  206. std::cout << "\t Address: " << dormer[s].address << "\n";
  207. std::cout << "\t Contact no: " << dormer[s].contact << "\n";
  208. std::cout << "\t ------------------------------------------------------ \n";
  209. }
  210. }
  211. void deletes() {
  212. show();
  213. string del, c; int count = 0, check = 0;
  214. std::cout << "\t Enter the ID boarder you want to delete ('0' to back): ";
  215. std::cin >> del;
  216. if (del == "0") {
  217. menu();
  218. }
  219. int i;
  220. for (i = 0;i <= occupant_ptr;i++)
  221. {
  222.  
  223. if (dormer[i].b_id == del)
  224. {
  225. count++;
  226. check = i;
  227. }
  228. }
  229.  
  230.  
  231. if (count == 0) {
  232. std::cout << "\t The boarder you want to delete is not existing. \n" << "\t ";
  233. std::system("pause");
  234. deletes();
  235. }
  236.  
  237. else {
  238. g:
  239. std::cout << "\t Are you sure you want to delete this boarder? [Y/N]: ";
  240. cin >> c;
  241. if (c == "Y" || c == "y") {
  242. for (i = 0;i <= occupant_ptr;i++)
  243. {
  244.  
  245. if (i == check)
  246. {
  247. continue;
  248. }
  249. else
  250.  
  251. if (i>check)
  252. {
  253.  
  254. tempemp[i - 1] = dormer[i];
  255.  
  256. }
  257. else
  258. {
  259. tempemp[i] = dormer[i];
  260. }
  261.  
  262. }
  263. occupant_ptr--;
  264.  
  265. for (i = 0;i <= occupant_ptr;i++)
  266. {
  267. dormer[i] = tempemp[i];
  268. }
  269. std::cout << "\t Successfully Deleted! \n";
  270. std::cout << "\t ";
  271. std::system("pause");
  272. menu();
  273. }
  274. else if (c == "N" || c == "n") {
  275. deletes();
  276. }
  277. else {
  278. std::cout << "\t Invalid input. \n";
  279. std::cout << "\t ";
  280. std::system("pause");
  281. goto g;
  282.  
  283. }
  284. }
  285.  
  286.  
  287.  
  288.  
  289. }
  290.  
  291. void edit()
  292. {
  293. int count = 0;
  294. ifstream boarder("boarder.txt");
  295. if (!boarder.eof())
  296. std::system("cls");
  297. string edt;
  298. std::system("cls");
  299.  
  300. show();
  301. std::cout << "\t Enter the ID of boarder you want to edit('0' to back): ";
  302. std::cin >> edt;
  303. if (edt == "0"){
  304. menu();
  305. }
  306. for (int i = 0;i <= occupant_ptr - 1;i++)
  307. {
  308. if (dormer[i].b_id == edt)
  309. {
  310. std::system("cls");
  311. count++;
  312. }
  313. if (count == 0) {
  314. std::cout << "\t The boarder you want to edit is not existing. \n" << "\t ";
  315. std::system("pause");
  316. edit();
  317. }
  318. else {
  319. std::cout << "\t ====================================================== \n";
  320. std::cout << "\t EDIT INFORMATIONS \n";
  321. std::cout << "\t ====================================================== \n";
  322. std::cout << "\t Boarder ID: " << dormer[i].b_id << "\n";
  323. std::cout << "\t Name: " << dormer[i].fname << ' ' << dormer[i].lname << "\n";
  324. std::cout << "\t Address: " << dormer[i].address << "\n";
  325. std::cout << "\t Contact no: " << dormer[i].contact << "\n";
  326. std::cout << "\t ------------------------------------------------------ \n";
  327. }
  328. }
  329. jump:
  330. std::cout << "\t Is this the boarder you want to edit? [Y/N]: ";
  331. std::cin >> choice;
  332. if (choice == "Y" || choice == "y") {
  333. edit_menu();
  334. }
  335. else if (choice == "N" || choice == "n") {
  336. edit();
  337. }
  338. else {
  339. std::cout << "\t Invalid input. Try again! \n";
  340. std::cout << "\t ";
  341. std::system("pause");
  342. goto jump;
  343.  
  344. }
  345.  
  346. }
  347. void edit_menu() {
  348. int option;
  349. std::system("cls");
  350. std::cout << "\t ====================================================== \n";
  351. std::cout << "\t EDIT OPTIONS \n";
  352. std::cout << "\t ====================================================== \n";
  353. std::cout << "\t 1. Edit Boarder ID \n";
  354. std::cout << "\t 2. Edit First Name \n";
  355. std::cout << "\t 3. Edit Last Name \n";
  356. std::cout << "\t 4. Edit Contact NO. \n";
  357. std::cout << "\t 5. Back \n";
  358. std::cout << "\t ------------------------------------------------------ \n";
  359. std::cout << "\t What do you want to edit?: ";
  360. std::cin >> option;
  361. for (int i = 0;i <= occupant_ptr ;i++)
  362. {
  363. switch (option)
  364. {
  365.  
  366. case 1:
  367. id(i);
  368. break;
  369. case 2:
  370. edit_fname(i);
  371. break;
  372. case 3:
  373. editlastname(i);
  374. break;
  375. case 4:
  376. edit_contact(i);
  377. break;
  378. case 5:
  379. menu();
  380. break;
  381. default:
  382. std::cout << "\t Invalid input. \n";
  383. std::cout << "\t ";
  384. std::system("pause");
  385. std::system("cls");
  386.  
  387. break;
  388. }
  389. }
  390. }
  391. void id(int i) {
  392. std::cout << "\t Enter new boarder id: ";
  393. cin.ignore(); getline(cin, dormer[i].b_id);
  394. std::cout << "\t Successfully Changed! \n";
  395. std::cout << "\t ";
  396. std::system("pause");
  397. menu();
  398. }
  399.  
  400. void edit_fname(int i)
  401. {
  402. std::cout << "\t Enter new firstname: ";
  403. cin.ignore(); getline(cin, dormer[i].fname);
  404. std::cout << "\t Successfully Changed! \n";
  405. std::cout << "\t ";
  406. std::system("pause");
  407. menu();
  408. }
  409. void editlastname(int i)
  410. {
  411. std::cout << "\t Enter new lastname: ";
  412. cin.ignore(); getline(cin, dormer[i].lname);
  413. std::cout << "\t Successfully Changed! \n";
  414. std::cout << "\t ";
  415. std::system("pause");
  416. menu();
  417. }
  418. void edit_contact(int i)
  419. {
  420. std::cout << "\t Enter new contact no.: ";
  421. cin.ignore(); getline(cin, dormer[i].contact);
  422. std::cout << "\t Successfully Change! \n";
  423. std::cout << "\t ";
  424. std::system("pause");
  425. menu();
  426. }
  427.  
  428.  
  429. void search()
  430. {
  431. string srch; int count = 0;
  432. std::system("cls");
  433. std::cout << "\t ====================================================== \n";
  434. std::cout << "\t SEARCH OPTIONS \n";
  435. std::cout << "\t ====================================================== \n";
  436. std::cout << "\t 1. Search by ID \n";
  437. std::cout << "\t 2. Search by First name \n";
  438. std::cout << "\t 3. Search by Last name \n";
  439. std::cout << "\t 4. Back \n";
  440. std::cout << "\t ------------------------------------------------------ \n";
  441. std::cout << "\t Enter your choice: ";
  442. cin >> sss;
  443. switch (sss) {
  444. case 1:
  445. system("cls");
  446. std::cout << "\t ====================================================== \n";
  447. std::cout << "\t SEARCH BY ID \n";
  448. std::cout << "\t ====================================================== \n";
  449. std::cout << "\t Enter the id boarder you want to search('0' to back): ";
  450. cin >> srch;
  451. if (srch == "0") {
  452. search();
  453. }
  454. for (int i = 0;i <= occupant_ptr - 1;i++)
  455. {
  456. if (dormer[i].b_id == srch)
  457. {
  458. count++;
  459. system("cls");
  460. std::cout << "\t ====================================================== \n";
  461. std::cout << "\t BOARDER FOUND \n";
  462. std::cout << "\t ====================================================== \n";
  463. std::cout << "\t Boarder ID: " << dormer[i].b_id << "\n";
  464. std::cout << "\t Name: " << dormer[i].fname << ' ' << dormer[i].lname << "\n";
  465. std::cout << "\t Address: " << dormer[i].address << "\n";
  466. std::cout << "\t Contact no: " << dormer[i].contact << "\n";
  467. std::cout << "\t ------------------------------------------------------ \n";
  468. }
  469. }
  470. break;
  471. case 2:
  472. system("cls");
  473. std::cout << "\t ====================================================== \n";
  474. std::cout << "\t SEARCH BY FIRST NAME \n";
  475. std::cout << "\t ====================================================== \n";
  476. std::cout << "\t Enter the first name of boarder you want to search('0' to back): ";
  477. cin.ignore(); getline(cin, srch);
  478. if (srch == "0") {
  479. search();
  480. }
  481. for (int i = 0;i <= occupant_ptr - 1;i++)
  482. {
  483. if (dormer[i].fname == srch)
  484. {
  485. count++;
  486. system("cls");
  487. std::cout << "\t ====================================================== \n";
  488. std::cout << "\t BOARDER FOUND \n";
  489. std::cout << "\t ====================================================== \n";
  490. std::cout << "\t Boarder ID: " << dormer[i].b_id << "\n";
  491. std::cout << "\t Name: " << dormer[i].fname << ' ' << dormer[i].lname << "\n";
  492. std::cout << "\t Address: " << dormer[i].address << "\n";
  493. std::cout << "\t Contact no: " << dormer[i].contact << "\n";
  494. std::cout << "\t ------------------------------------------------------ \n";
  495.  
  496. }
  497. }
  498. break;
  499. case 3:
  500. system("cls");
  501. std::cout << "\t ====================================================== \n";
  502. std::cout << "\t SEARCH BY LAST NAME \n";
  503. std::cout << "\t ====================================================== \n";
  504. std::cout << "\t Enter the last name of boarder you want to search('0' to back): ";
  505. cin.ignore(); getline(cin, srch);
  506. if (srch == "0") {
  507. search();
  508. }
  509. for (int i = 0;i <= occupant_ptr - 1;i++)
  510. {
  511. if (dormer[i].lname == srch)
  512. {
  513. count++;
  514. system("cls");
  515. std::cout << "\t ====================================================== \n";
  516. std::cout << "\t BOARDER FOUND \n";
  517. std::cout << "\t ====================================================== \n";
  518. std::cout << "\t Boarder ID: " << dormer[i].b_id << "\n";
  519. std::cout << "\t Name: " << dormer[i].fname << ' ' << dormer[i].lname << "\n";
  520. std::cout << "\t Address: " << dormer[i].address << "\n";
  521. std::cout << "\t Contact no: " << dormer[i].contact << "\n";
  522. std::cout << "\t ------------------------------------------------------ \n";
  523. }
  524. }
  525. break;
  526. case 4:
  527. menu();
  528. break;
  529. default:
  530. std::cout << "\t Invalid input. Try again! \n";
  531. std::cout << "\t ";
  532. std::system("pause");
  533. search();
  534. }
  535.  
  536.  
  537. if (count == 0) {
  538. std::cout << "\t Boarder is not existing. \n";
  539. std::cout << "\t ";
  540. std::system("pause");
  541. search();
  542. }
  543. std::cout << "\t ";
  544. std::system("pause");
  545. search();
  546. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement