Advertisement
Guest User

Untitled

a guest
May 21st, 2017
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.83 KB | None | 0 0
  1. #ifndef SHOPPING_H
  2. #define SHOPPING_H
  3.  
  4. template<class DataType>
  5. class Shopping
  6. {
  7. private:
  8. class Node
  9. {
  10. public:
  11. DataType data;
  12. Node * link;
  13. };
  14.  
  15. Node *pHead;
  16. Node *pCurr;
  17. Node *pPrev;
  18. int numItem;
  19.  
  20. public:
  21. Shopping();
  22. ~Shopping();
  23. bool Traverse(DataType, int &);
  24. void AddToFront();
  25. void AddToMiddle();
  26. void DeleteFront();
  27. void DeleteMiddle();
  28. void PrintData();
  29. int NumberOfItem();
  30. };
  31.  
  32. #endif
  33.  
  34. template<class DataType>
  35. Shopping<DataType>::Shopping()
  36. {
  37. numItem = 0;
  38. pHead = 0;
  39. }
  40.  
  41. template<class DataType>
  42. Shopping<DataType>::~Shopping()
  43. {
  44. }
  45.  
  46. template<class DataType>
  47. void Shopping<DataType>::AddToFront()
  48. {
  49. DataType item;
  50. Node *pNew = new Node;
  51. cout << "Enter data : ";
  52. cin >> item;
  53. pNew->data = item;
  54. pNew->link = pHead;
  55. pHead = pNew;
  56. numItem++;
  57. }
  58.  
  59. template<class DataType>
  60. void Shopping<DataType>::AddToMiddle()
  61. {
  62. DataType item;
  63. Node *pNew = new Node;
  64. cout << "Enter data : ";
  65. cin >> item;
  66. if (numItem == 1)
  67. pCurr = pHead;
  68. pNew->data = item;
  69. pNew->link = pCurr->link;
  70. pCurr = pNew;
  71. numItem++;
  72. }
  73.  
  74. template<class DataType>
  75. void Shopping<DataType>::DeleteFront()
  76. {
  77. pHead = pHead->link;
  78. numItem--;
  79. cout << "First Item Deleted" << endl;
  80. }
  81.  
  82. template<class DataType>
  83. void Shopping<DataType>::DeleteMiddle()
  84. {
  85. pPrev->link = pCurr->link;
  86. numItem--;
  87. cout << "Item Deleted" << endl;
  88. }
  89.  
  90. template<class DataType>
  91. void Shopping<DataType>::PrintData()
  92. {
  93. pCurr = pHead;
  94. while (pCurr != 0)
  95. {
  96. cout << pCurr->data << " ";
  97. pCurr = pCurr->link;
  98. }
  99. cout << "\n";
  100.  
  101. }
  102.  
  103. template<class DataType>
  104. int Shopping<DataType>::NumberOfItem()
  105. {
  106. return numItem;
  107. }
  108.  
  109. template <class DataType>
  110. bool Shopping<DataType>::Traverse(DataType target, int &loc)
  111. {
  112. if (numItem == 0)
  113. cout << "There is no item in the list" << endl;
  114. else
  115. {
  116. pCurr = pHead;
  117. loc = 0;
  118. while (pCurr->data != target && pCurr->link != 0)
  119. {
  120. pPrev = pCurr;
  121. pCurr = pCurr->link;
  122. loc++;
  123. }
  124.  
  125. if (pCurr->data == target)
  126. return true;
  127.  
  128. else
  129. return false;
  130. }
  131. }
  132.  
  133.  
  134.  
  135. -------------------------------------------------------------------------------
  136. .cpp
  137.  
  138.  
  139. #include <iostream>
  140. #include<string>
  141. #include<iomanip>
  142. #include<Windows.h>
  143. #include<conio.h>
  144. #include<stdlib.h>
  145. using namespace std;
  146. #include "shopping.h"
  147. void menuscreen();
  148. int login();
  149.  
  150. void main()
  151. {
  152. system("COLOR b");
  153. cout << "\t\t ***************************************\n\n\n\n";
  154. cout << "\t\t ASAEESAEKOSADKOSAKDOSAKDOAS \n";
  155.  
  156. cout << "\t\t ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n";
  157. cout << "\t\t\t ONLINE SHOPPING \n\n\t\t\t\t";
  158. system("pause");
  159. system("cls");
  160. login();
  161. }
  162. void menuscreen()
  163. {
  164. int option;
  165. int target;
  166. int location;
  167. Shopping<int> shop;
  168. system("color 4f");
  169. cout << " \t \t \t Welcome To ONLINE SHOPPING \n \n ";
  170. cout << " \t \t \t __________________________ \n ";
  171. cout << "\t\t Menu: \n";
  172. cout << "\t\t 1. \t add \n";
  173. cout << "\t\t 2. \t delete \n";
  174. cout << "\t\t 3. \t display \n";
  175. cout << "\t\t 4. \t search \n";
  176. cout << "\t\t 5. \t sort\n";
  177. cout << "\t\t 6. \t Log Out.\n";
  178. cout << "\t\t 7. \t Quit.\n";
  179. cout << " \t \t \t __________________________ \n\n ";
  180. cout << "\t\t *** Available only within Melacca.***\n";
  181. cout << " \n \n";
  182. do
  183. {
  184. cout << "\t User option >> ";
  185. cin >> option;
  186. switch (option)
  187. {
  188. case 1:
  189. for (int i = 1; i < 4; i++)
  190. {
  191. shop.AddToFront();
  192.  
  193. }
  194. cout << "\n The List Are : ";
  195. shop.PrintData();
  196. break;
  197. case 2:
  198. cout << "\nItem to delete : ";
  199. cin >> target;
  200.  
  201. if (shop.Traverse(target, location) == true)
  202. {
  203. if (location == 0)
  204. shop.DeleteFront();
  205. else
  206. shop.DeleteMiddle();
  207. }
  208.  
  209. else
  210. {
  211. cout << "Item is not found \n";
  212. }
  213.  
  214. break;
  215. case 3:
  216. cout << "\nNumber Of Item Now: " << shop.NumberOfItem();
  217. cout << "\n The List Are : ";
  218. shop.PrintData();
  219. break;
  220.  
  221. case 4:
  222. cout << "\nEnter the search item : ";
  223. cin >> target;
  224.  
  225. if (shop.Traverse(target, location) == true)
  226. {
  227. cout << "Item is found at location : " << location << endl;
  228. }
  229.  
  230. else
  231. {
  232. cout << "Item is not found \n";
  233. }
  234. break;
  235.  
  236. case 5:
  237. cout << "\n\n\t***sort***\n\n";
  238. break;
  239. case 6:
  240. cout << "\n\n\t***YOU HAVE SUCCESSFULLY LOGGED OUT !!!***\n\n";
  241. cout << "\n\n\t***THANK YOU FOR USING OUR SYSTEM***\n\n";
  242. system("pause");
  243. login();
  244. break;
  245. case 7:
  246. cout << "\n\n\t***THANK YOU FOR USING OUR SYSTEM***\n\n";
  247. return ;
  248. break;
  249. default:
  250. exit(0);
  251. break;
  252. }
  253. } while (option < 1 || option>5);
  254.  
  255.  
  256.  
  257.  
  258. cout << "\nNumber Of Item Now: " << shop.NumberOfItem();
  259. cout << "\n The List Are : ";
  260. shop.PrintData();
  261.  
  262.  
  263. cout << "\nNumber Of Item Now: " << shop.NumberOfItem();
  264. cout << "\n The List Are : ";
  265. shop.PrintData();
  266. }
  267.  
  268.  
  269. int login()
  270. {
  271. string username;
  272. string password;
  273. username = "ADMIN";
  274. char ch;
  275. string input;
  276. karate:
  277. system("cls");
  278. cout << "\n\t\t\t\t\t=====ADMINISTRATOR LOGIN=====\n\n";
  279. cout << "\n\t\t\t\t\t=====Enter 00 to Exit=====\n\n";
  280. cout << "\n\n\n\tENTER USERNAME : ";
  281. cin >> input;
  282.  
  283. if (input == username)
  284. {
  285. cout << "\n";
  286.  
  287. cout << "\tENTER PASSWORD : ";
  288. ch = _getch();
  289. while (ch != 13)
  290. {
  291. password.push_back(ch);
  292. cout << '*';
  293. ch = _getch();
  294. }
  295. if (password == "1234")
  296. {
  297. cout << "\n\n\n\n\n\n\t\t\t ACCESS GRANTED !!!\n ";
  298. for (int i = 0; i <3; i++)
  299. {
  300. cout << " ";
  301. Sleep(250);
  302. }
  303. Sleep(500);
  304. system("cls");
  305. menuscreen();
  306. }
  307.  
  308. else
  309. cout << "\n\n\t\tAccess Denied.....Invalid Password\n\n";
  310. system("pause");
  311. goto karate;
  312. }
  313. else if (password == "00")
  314. {
  315. cout << "\n\n\n\n\n\n\t\t\t EXITING PROGRAMME !!!\n ";
  316. return(0);
  317. }
  318.  
  319.  
  320. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement