Advertisement
Guest User

Untitled

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