Advertisement
Guest User

Untitled

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