Advertisement
Guest User

Untitled

a guest
May 21st, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.38 KB | None | 0 0
  1. #ifndef HEADER_H
  2. #define HEADER_H
  3. #include<fstream>
  4.  
  5. ifstream infile;
  6. ofstream outfile;
  7.  
  8. class List
  9. {
  10. private:
  11. struct Student
  12. {
  13. int bil;
  14. string name;
  15. string matricno;
  16. string plateno;
  17. string hostel;
  18. };
  19. class Node
  20. {
  21. public:
  22. Student StudentData;
  23. Node*link;
  24. };
  25. Node*pHead;
  26. Node*pCurr;
  27. Node*pPrev;
  28. Node*pTail;
  29. int numItem;
  30.  
  31. public:
  32. List();
  33. ~List();
  34. void AddToFront();
  35. void AddToMiddle();
  36. void DeleteFront();
  37. void DeleteMiddle();
  38. int NumberOfItem();
  39. bool searchDelete(int, int &);
  40. bool searchPlate(string, int &);
  41. void sortHostel(string target);
  42. void printSearch(int);
  43. void displayData();
  44. bool Traverse();
  45. void displayOutput();
  46. void AddToFrontInput(int, string, string, string, string);
  47. void AddToMiddleInput(int, string, string, string, string);
  48.  
  49. };
  50. #endif
  51.  
  52. List::List()
  53. {
  54. numItem = 0;
  55. pHead = 0;
  56. }
  57.  
  58. List::~List() {}
  59.  
  60. void List::AddToFront()
  61. {
  62. string item1, item2, item3, item4;
  63. int item5;
  64. Node*pNew = new Node;
  65. cout << "\nEnter Name : ";
  66. getline(cin, item1);
  67. cout << "Enter Matric No. : ";
  68. getline(cin, item2);
  69. cout << "Enter Plate No. : ";
  70. getline(cin, item3);
  71. cout << "Enter Hostel : ";
  72. getline(cin, item4);
  73. numItem++;
  74. item5 = numItem;
  75. pNew->StudentData.name = item1;
  76. pNew->StudentData.matricno = item2;
  77. pNew->StudentData.plateno = item3;
  78. pNew->StudentData.hostel = item4;
  79. pNew->StudentData.bil = item5;
  80. pNew->link = pHead;
  81. pHead = pNew;
  82. }
  83.  
  84. void List::AddToMiddle()
  85. {
  86. string item1, item2, item3, item4;
  87. int item5;
  88. Node*pNew = new Node;
  89. cout << "\nEnter Name : ";
  90. getline(cin, item1);
  91. cout << "Enter Matric No. : ";
  92. getline(cin, item2);
  93. cout << "Enter Plate No. : ";
  94. getline(cin, item3);
  95. cout << "Enter Hostel : ";
  96. getline(cin, item4);
  97. if (numItem == 1)
  98. pCurr = pHead;
  99. numItem++;
  100. item5 = numItem;
  101. pNew->StudentData.name = item1;
  102. pNew->StudentData.matricno = item2;
  103. pNew->StudentData.plateno = item3;
  104. pNew->StudentData.hostel = item4;
  105. pNew->StudentData.bil = item5;
  106. pNew->link = pCurr->link;
  107. pCurr->link = pNew;
  108. pCurr = pNew;
  109. }
  110.  
  111. void List::DeleteFront()
  112. {
  113. pHead = pHead->link;
  114. pCurr = pHead;
  115. numItem--;
  116. for (int i = 1; i <= numItem; i++)
  117. {
  118. pCurr->StudentData.bil = i;
  119. pPrev = pCurr;
  120. pCurr = pCurr->link;
  121. }
  122.  
  123. }
  124.  
  125. void List::DeleteMiddle()
  126. {
  127. pPrev->link = pCurr->link;
  128. numItem--;
  129. pCurr = pHead;
  130. for (int i = 1; i <= numItem; i++)
  131. {
  132. pCurr->StudentData.bil = i;
  133. pPrev = pCurr;
  134. pCurr = pCurr->link;
  135. }
  136. }
  137.  
  138. int List::NumberOfItem()
  139. {
  140. return numItem;
  141. }
  142.  
  143. bool List::searchDelete(int target1, int &loc)
  144. {
  145. if (numItem == 0)
  146. cout << "NO ITEM" << endl;
  147. else
  148. {
  149. pCurr = pHead;
  150. loc = 0;
  151. while (pCurr->StudentData.bil != target1 && pCurr->link != 0)
  152. {
  153. pPrev = pCurr;
  154. pCurr = pCurr->link;
  155. loc++;
  156. }
  157. if (pCurr->StudentData.bil == target1)
  158. return true;
  159. else
  160. return false;
  161. }
  162. }
  163.  
  164. bool List::searchPlate(string target, int &loc)
  165. {
  166. if (numItem == 0)
  167. cout << "NO ITEM" << endl;
  168. else
  169. {
  170. pCurr = pHead;
  171. loc = 0;
  172. while (pCurr->StudentData.plateno != target && pCurr->link != 0)
  173. {
  174. pPrev = pCurr;
  175. pCurr = pCurr->link;
  176. loc++;
  177. }
  178. if (pCurr->StudentData.plateno == target)
  179. return true;
  180. else
  181. return false;
  182. }
  183. }
  184.  
  185. void List::sortHostel(string target)
  186. {
  187. int total = 0;
  188. cout << endl;
  189. pCurr = pHead;
  190. cout << left << setw(20) << "----------" << left << setw(20) << "----------" << left << setw(20) << "----------" << left << setw(20) << "----------" << endl;
  191. cout << left << setw(20) << " Name " << left << setw(20) << "Matric No " << left << setw(20) << " Plate No " << left << setw(20) << " Hostel " << endl;
  192. cout << left << setw(20) << "----------" << left << setw(20) << "----------" << left << setw(20) << "----------" << left << setw(20) << "----------" << endl;
  193. for(int i = 0; i < numItem; i++)
  194. {
  195. if (pCurr->StudentData.hostel == target)
  196. {
  197. cout << endl;
  198. cout << left << setw(20) << pCurr->StudentData.name;
  199. cout << left << setw(20) << pCurr->StudentData.matricno;
  200. cout << left << setw(20) << pCurr->StudentData.plateno;
  201. cout << left << setw(20) << pCurr->StudentData.hostel;
  202. total++;
  203. }
  204. else;
  205. pPrev = pCurr;
  206. pCurr = pCurr->link;
  207. }
  208. cout << "\n\nTotal : " << total << endl << endl;
  209. }
  210.  
  211. void List::printSearch(int location)
  212. {
  213. pCurr = pHead;
  214. int loc = 0;
  215. while (loc != location && pCurr->link != 0)
  216. {
  217. pPrev = pCurr;
  218. pCurr = pCurr->link;
  219. loc++;
  220. }
  221. cout << left << setw(20) << pCurr->StudentData.name;
  222. cout << left << setw(20) << pCurr->StudentData.matricno;
  223. cout << left << setw(20) << pCurr->StudentData.plateno;
  224. cout << left << setw(20) << pCurr->StudentData.hostel;
  225. }
  226.  
  227. void List::displayData()
  228. {
  229. pCurr = pHead;
  230. while (pCurr != 0)
  231. {
  232. cout << " " << pCurr->StudentData.bil << " ";
  233. cout << left << setw(20) << pCurr->StudentData.name;
  234. cout << left << setw(20) << pCurr->StudentData.matricno;
  235. cout << left << setw(20) << pCurr->StudentData.plateno;
  236. cout << left << setw(20) << pCurr->StudentData.hostel;
  237. pCurr = pCurr->link;
  238. cout << endl;
  239. }
  240. }
  241.  
  242. bool List::Traverse()
  243. {
  244. pCurr = pHead;
  245. while (pCurr->link != NULL)
  246. {
  247. pPrev = pCurr;
  248. pCurr = pCurr->link;
  249. }
  250. if (pCurr->link == NULL)
  251. return true;
  252. else
  253. return false;
  254. }
  255.  
  256. void List::displayOutput()
  257. {
  258. outfile.open("info.txt");
  259. pCurr = pHead;
  260. while (pCurr != 0)
  261. {
  262. outfile << " " << pCurr->StudentData.bil << " ";
  263. outfile << left << setw(20) << pCurr->StudentData.name;
  264. outfile << left << setw(20) << pCurr->StudentData.matricno;
  265. outfile << left << setw(20) << pCurr->StudentData.plateno;
  266. outfile << left << setw(20) << pCurr->StudentData.hostel;
  267. pCurr = pCurr->link;
  268. outfile << endl;
  269. }
  270. outfile.close();
  271. }
  272.  
  273. void List::AddToFrontInput(int item5, string item1, string item2, string item3, string item4)
  274. {
  275. Node*pNew = new Node;
  276. numItem++;
  277. item5 = numItem;
  278. pNew->StudentData.name = item1;
  279. pNew->StudentData.matricno = item2;
  280. pNew->StudentData.plateno = item3;
  281. pNew->StudentData.hostel = item4;
  282. pNew->StudentData.bil = item5;
  283. pNew->link = pHead;
  284. pHead = pNew;
  285. }
  286.  
  287. void List::AddToMiddleInput(int item5, string item1, string item2, string item3, string item4)
  288. {
  289. Node*pNew = new Node;
  290. if (numItem == 1)
  291. pCurr = pHead;
  292. numItem++;
  293. item5 = numItem;
  294. pNew->StudentData.name = item1;
  295. pNew->StudentData.matricno = item2;
  296. pNew->StudentData.plateno = item3;
  297. pNew->StudentData.hostel = item4;
  298. pNew->StudentData.bil = item5;
  299. pNew->link = pCurr->link;
  300. pCurr->link = pNew;
  301. pCurr = pNew;
  302. }
  303.  
  304.  
  305. ---------------------------------------------------
  306. #include<iostream>
  307. #include<string>
  308. #include<iomanip>
  309. #include<fstream>
  310. #include<Windows.h>
  311. #include<conio.h>
  312. #include<stdlib.h>
  313. using namespace std;
  314. #include "Header.h"
  315.  
  316. void login();
  317.  
  318. void main()
  319. {
  320. List mylist;
  321. string target, name, matric, plate, hostel;
  322. int location, choice, bil, target1;
  323. char backOption, choice1;
  324.  
  325. login();
  326.  
  327. ifstream infile;
  328. infile.open("info.txt");
  329. while (infile >> bil >> name >> matric >> plate >> hostel)
  330. {
  331. if (mylist.NumberOfItem() == 0)
  332. mylist.AddToFrontInput(bil, name, matric, plate, hostel);
  333. else
  334. mylist.AddToMiddleInput(bil, name, matric, plate, hostel);
  335. }
  336. infile.close();
  337.  
  338. do
  339. {
  340. cout << "**********" << "MENU" << "**********" << endl << endl;
  341. cout << "========================\n1. ADD ITEM\n2. DELETE ITEM\n3. DISPLAY RECORD\n4. SORT BY HOSTEL\n5. SEARCH BY PLATE NO\n6. EXIT\n========================\n\n";
  342. cout << " = ";
  343. cin >> choice;
  344. cin.ignore();
  345. cout << endl;
  346. system("cls");
  347.  
  348. switch (choice)
  349. {
  350. case 1:
  351. cout << "-----ADD ITEM-----\n";
  352. if (mylist.NumberOfItem() == 0)
  353. {
  354. mylist.AddToFront();
  355. cout << "\nAdd some more? (Y=yes, N=no) : ";
  356. cin >> choice1;
  357. cin.ignore();
  358. if (choice1 == 'Y')
  359. {
  360. do
  361. {
  362. mylist.AddToMiddle();
  363. cout << "\nAdd some more? (Y=yes, N=no) : ";
  364. cin >> choice1;
  365. cin.ignore();
  366. } while (choice1 == 'Y');
  367. }
  368. else
  369. break;
  370. }
  371. else
  372. if (mylist.Traverse() == true)
  373. {
  374. do
  375. {
  376. mylist.AddToMiddle();
  377. cout << "\nAdd some more? (Y=yes, N=no) : ";
  378. cin >> choice1;
  379. cin.ignore();
  380. } while (choice1 == 'Y');
  381. }
  382. cout << "\nSUCCESSFULLY ADDED!\n";
  383. break;
  384.  
  385. case 2:
  386. do
  387. {
  388. system("cls");
  389. cout << "-----DELETE ITEM-----\n\n";
  390. cout << left << setw(8) << "-----" << left << setw(20) << "----------" << left << setw(20) << "----------" << left << setw(20) << "----------" << left << setw(20) << "----------" << endl;
  391. cout << left << setw(8) << " No. " << left << setw(20) << " Name " << left << setw(20) << "Matric No " << left << setw(20) << " Plate No " << left << setw(20) << " Hostel " << endl;
  392. cout << left << setw(8) << "-----" << left << setw(20) << "----------" << left << setw(20) << "----------" << left << setw(20) << "----------" << left << setw(20) << "----------" << endl;
  393. mylist.displayData();
  394. cout << "\nNo. : ";
  395. cin >> target1;
  396. if (mylist.searchDelete(target1, location) == true)
  397. {
  398. if (location == 0)
  399. {
  400. mylist.DeleteFront();
  401. }
  402. else
  403. {
  404. mylist.DeleteMiddle();
  405. }
  406. cout << "\nITEM DELETED!\n";
  407. }
  408. cout << "\nDelete more? (Y=yes, N=no) : ";
  409. cin >> choice1;
  410. cin.ignore();
  411. } while (choice1 == 'Y');
  412. break;
  413.  
  414. case 3:
  415. cout << "-----DISPLAY BY NAME-----\n\n";
  416. cout << left << setw(8) << "-----" << left << setw(20) << "----------" << left << setw(20) << "----------" << left << setw(20) << "----------" << left << setw(20) << "----------" << endl;
  417. cout << left << setw(8) << " No. " << left << setw(20) << " Name " << left << setw(20) << "Matric No " << left << setw(20) << " Plate No " << left << setw(20) << " Hostel " << endl;
  418. cout << left << setw(8) << "-----" << left << setw(20) << "----------" << left << setw(20) << "----------" << left << setw(20) << "----------" << left << setw(20) << "----------" << endl;
  419. mylist.displayData();
  420. cout << endl << "Total : " << mylist.NumberOfItem() << endl;
  421. break;
  422.  
  423. case 4:
  424. do
  425. {
  426. system("cls");
  427. cout << "-----SORT BY HOSTEL-----\n\n";
  428. cout << "HOSTEL : ";
  429. getline(cin, target);
  430. mylist.sortHostel(target);
  431. cout << "SORT AGAIN? (Y=yes, N=no) : ";
  432. cin >> choice1;
  433. cin.ignore();
  434. } while (choice1 == 'Y');
  435. break;
  436.  
  437. case 5:
  438. cout << "-----SEARCH BY PLATE NO-----" << "\n\nPlate No. : ";
  439. getline(cin, target);
  440. cout << endl;
  441. cout << left << setw(20) << "----------" << left << setw(20) << "----------" << left << setw(20) << "----------" << left << setw(20) << "----------" << endl;
  442. cout << left << setw(20) << " Name " << left << setw(20) << "Matric No" << left << setw(20) << " Plate No " << left << setw(20) << " Hostel " << endl;
  443. cout << left << setw(20) << "----------" << left << setw(20) << "----------" << left << setw(20) << "----------" << left << setw(20) << "----------" << endl;
  444. if (mylist.searchPlate(target, location) == true)
  445. mylist.printSearch(location);
  446. else
  447. cout << "Item is not found\n";
  448. cout << endl;
  449. break;
  450.  
  451. case 6:
  452. mylist.displayOutput();
  453. cout << "\n. . . EXITING SYSTEM . . .\n\n";
  454. exit(EXIT_FAILURE);
  455. break;
  456. }
  457. cout << "\nBACK TO MAIN MENU? (Y=yes, N=no) : ";
  458. cin >> backOption;
  459. system("cls");
  460. }
  461. while (backOption == 'Y');
  462. {
  463. mylist.displayOutput();
  464. cout << "\n. . . EXITING SYSTEM . . .\n\n";
  465. }
  466. }
  467.  
  468. void login()
  469. {
  470. string username;
  471. string password;
  472. username = "ADMIN";
  473. char ch;
  474. string input;
  475. karate:
  476. system("cls");
  477. cout << "\n\t\t\t\t\t=====VEHICLE STICKER REGISTRATION=====\n\n";
  478. cout << "\n\n\n\tENTER USERNAME : ";
  479. cin >> input;
  480.  
  481. if (input == username)
  482. {
  483. cout << "\n";
  484.  
  485. cout << "\tENTER PASSWORD : ";
  486. ch = _getch();
  487. while (ch != 13)
  488. {
  489. password.push_back(ch);
  490. cout << '*';
  491. ch = _getch();
  492. }
  493. if (password == "1234")
  494. {
  495. cout << "\n\n\n\n\n\n\t\t\t VERIFYING . . . ";
  496. for (int i = 0; i < 6; i++)
  497. {
  498. cout << "\xdb\xdb\xdb\xdb\xdb";
  499. Sleep(250);
  500. }
  501. Sleep(500);
  502. system("cls");
  503. return;
  504. }
  505. else
  506. cout << "\n\n\t\tAccess Denied.....Invalid Password\n\n";
  507. system("pause");
  508. goto karate;
  509. }
  510. else
  511. cout << "\n\n\t\tAccess Denied.....Invalid Username\n\n";
  512. system("pause");
  513. goto karate;
  514. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement