Advertisement
Guest User

Untitled

a guest
Dec 6th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4. #include <conio.h> //for loading screen
  5. #include <dos.h> //for loading screen
  6. #include <windows.h> //for loading screen (sleep)
  7. using namespace std;
  8. struct customer // struct for customer details
  9. {
  10. string name;
  11. string email;
  12. int number;
  13. };
  14.  
  15. //function prototype
  16. void welcomeScreen(); //display welcome screen and customer information
  17. void getInfo(struct customer &cust); //get information from customer
  18. void listHardware(); //list of names of hardwares for the type that has been chosen by the customer
  19. double calcFunc(int,int,int,int,int,int,int,int,int,int,double,char); //to calculate price
  20. void search_hardware(); //to search any hardwares available
  21. void exit_system(); //to exit program
  22. int admin_login(); //function accessible for admin/shopkeeper only
  23.  
  24. void welcomeScreen()
  25. {
  26. struct customer cust; // struct declaration
  27. char ordermore = 'y';
  28. const int SIZE=5;
  29.  
  30. system("cls");
  31.  
  32. getInfo(cust); //function call to get info from customer
  33.  
  34. while (ordermore == 'y' || ordermore == 'Y')
  35. {
  36. system("cls");
  37.  
  38. cout << endl << "Type of hardwares that we sell:" << endl; //list of hardwares (1d Array)
  39. string item[SIZE]={"Monitor","CPU","RAM","Solid-State Drive","Graphic Card"};
  40. for(int i=0;i<SIZE;i++)
  41. cout << "\t" << i+1 << ". " << item[i] << endl;
  42.  
  43. listHardware(); //function call list of names of hardwares
  44.  
  45. cout << endl;
  46. cout << fixed << showpoint << setprecision (2);
  47. cout << "Name: "<< cust.name << endl; // struct output
  48. cout << "Email: "<< cust.email << endl;
  49. cout << "Phone Number: " << cust.number << endl;
  50. cout << setfill ('-') << setw (55) << "-" << endl;
  51.  
  52. cout << "\nMore Order?(New Transaction) Press Y for yes: ";
  53. cin >> ordermore;
  54. }
  55. }
  56.  
  57. void getInfo(struct customer &cust)
  58. {
  59. cout << endl << "Enter name: "; // struct input
  60. //cin >> cust.name;
  61. getline(cin, cust.name);
  62. cout << "Enter email: ";
  63. cin >> cust.email;
  64. cin.ignore();
  65. cout << "Enter phone number: ";
  66. cin >> cust.number;
  67. }
  68.  
  69. void listHardware()
  70. {
  71. int i,j,type,m_type,c_type,r_type,s_type,g_type,m_quantity,c_quantity,r_quantity,s_quantity,g_quantity;
  72. const int SIZE=3;
  73. char shopmember,addorder = 'y';
  74. double price=0;
  75. const double discount=0.1;
  76.  
  77. cout << endl;
  78. cout << "Membership (Y/N): ";
  79. cin >> shopmember;
  80.  
  81. while(addorder=='Y' || addorder=='y')
  82. {
  83. cout << endl << "Select which type of hardware that you want to purchase: ";
  84. cin >> type;
  85.  
  86. if(type==1)
  87. {
  88. const char *monitor[SIZE][2]=
  89. {
  90. {"BenQ PD3200U", "(RM3000)"},
  91. {"Acer Predator X34", "(RM4000)"},
  92. {"Dell UltraSharp UP3218K", "(RM8000)"}
  93. };
  94.  
  95. cout << "Monitors:" << endl;
  96. for(i=0;i<SIZE;i++)
  97. {
  98. cout << "\t" << i+1 << ". ";
  99. for(j=0;j<2;j++)
  100. {
  101. cout << monitor[i][j] << " ";
  102. }
  103. cout << endl;
  104. }
  105. cout << endl << "Enter which Monitor you would like to purchase: ";
  106. cin >> m_type; //monitor
  107. cout << endl << "How many Monitor would you like to purchase?" << endl;
  108. cin >> m_quantity;
  109. }
  110. if(type==2)
  111. {
  112. const char *cpu[SIZE][2]=
  113. {
  114. {"AMD Ryzen 7 2700X", "(RM1200)"},
  115. {"Intel Core i5-8600K", "(RM1200)"},
  116. {"Intel Core i9-7980XE", "(RM8000)"}
  117. };
  118.  
  119. cout << "CPU:" << endl;
  120. for(i=0;i<SIZE;i++)
  121. {
  122. cout << "\t" << i+1 << ". ";
  123. for(j=0;j<2;j++)
  124. {
  125. cout << cpu[i][j] << " ";
  126. }
  127. cout << endl;
  128. }
  129. cout << endl << "Enter which CPU would you like to purchase: ";
  130. cin >> c_type; //cpu
  131. cout << endl << "How many CPU would you like to purchase?" << endl;
  132. cin >> c_quantity;
  133. }
  134. if(type==3)
  135. {
  136. const char *ram[SIZE][2]=
  137. {
  138. {"Patriot Viper Elite 8GB DDR4-2400MHz", "(RM400)"},
  139. {"G.Skill Ripjaws V 16GB DDR4-2400MHz", "(RM1200)"},
  140. {"Corsair Dominator Platinum 32GB DDR4-3333MHz", "(RM2000)"}
  141. };
  142.  
  143. cout << "RAM:" << endl;
  144. for(i=0;i<SIZE;i++)
  145. {
  146. cout << "\t" << i+1 << ". ";
  147. for(j=0;j<2;j++)
  148. {
  149. cout << ram[i][j] << " ";
  150. }
  151. cout << endl;
  152. }
  153. cout << endl << "Enter which RAM would you like to purchase: ";
  154. cin >> r_type; //ram
  155. cout << endl << "How many RAM would you like to purchase?" << endl;
  156. cin >> r_quantity;
  157. }
  158. if(type==4)
  159. {
  160. const char *ssd[SIZE][2]=
  161. {
  162. {"Samsung 860 Pro 1TB", "(RM1250)"},
  163. {"Crucial MX500 1TB", "(RM600)"},
  164. {"WD Blue 2TB", "(RM1600)"}
  165. };
  166.  
  167. cout << "SSD:" << endl;
  168. for(i=0;i<SIZE;i++)
  169. {
  170. cout << "\t" << i+1 << ". ";
  171. for(j=0;j<2;j++)
  172. {
  173. cout << ssd[i][j] << " ";
  174. }
  175. cout << endl;
  176. }
  177. cout << endl << "Enter which SSD would you like to purchase: ";
  178. cin >> s_type; //ssd
  179. cout << endl << "How many SSD would you like to purchase?" << endl;
  180. cin >> s_quantity;
  181. }
  182. if(type==5)
  183. {
  184. const char *gcard[SIZE][2]=
  185. {
  186. {"Nvidia GeForce RTX 2080 Ti", "(RM4000)"},
  187. {"Nvidia GeForce GTX 1080 Ti", "(RM2900)"},
  188. {"AMD Radeon RX 580 8GB", "(RM2100)"}
  189. };
  190.  
  191. cout << "Graphic Card:" << endl;
  192. for(i=0;i<SIZE;i++)
  193. {
  194. cout << "\t" << i+1 << ". ";
  195. for(j=0;j<2;j++)
  196. {
  197. cout << gcard[i][j] << " ";
  198. }
  199. cout << endl;
  200. }
  201. cout << endl << "Enter which Graphic Card would you like to purchase: ";
  202. cin >> g_type; //gpu
  203. cout << endl << "How many Graphic Card would you like to purchase?" << endl;
  204. cin >> g_quantity;
  205. }
  206.  
  207. price=calcFunc(m_type,c_type,r_type,s_type,g_type,m_quantity,c_quantity,r_quantity,s_quantity,g_quantity,price,shopmember); //function call
  208.  
  209. cout << setfill ('-') << setw (55) << "-" << endl;
  210. cout << "Total price for now (not including membership discount): RM" << price << endl;
  211. cout << setfill ('-') << setw (55) << "-" << endl;
  212.  
  213. cout << "Do you want to purchase more? Press y for yes." << endl;
  214. cin >> addorder;
  215. }
  216. cout << setfill ('-') << setw (55) << "-" << endl;
  217. if (shopmember == 'y' || shopmember == 'Y')
  218. cout << "Total Price: RM" << price-(price*discount) << endl;
  219. else
  220. cout << "Total Price: RM" << price << endl;
  221. cout << setfill ('-') << setw (55) << "-" << endl;
  222. }
  223.  
  224. double calcFunc(int m_type,int c_type,int r_type, int s_type, int g_type,int m_quantity,int c_quantity,int r_quantity,int s_quantity,int g_quantity,double price, char shopmember)
  225. {
  226. if(m_type==1) //monitor
  227. {
  228. price+=3000*m_quantity;
  229. }
  230. else if(m_type==2) //monitor
  231. {
  232. price+=4000*m_quantity;
  233. }
  234. else if(m_type==3) //monitor
  235. {
  236. price+=8000*m_quantity;
  237. }
  238.  
  239. if(c_type==1) //cpu
  240. {
  241. price+=1200*c_quantity;
  242. }
  243. else if(c_type==2) //cpu
  244. {
  245. price+=1200*c_quantity;
  246. }
  247. else if(c_type==3) //cpu
  248. {
  249. price+=8000*c_quantity;
  250. }
  251.  
  252. if(r_type==1) //ram
  253. {
  254. price+=400*r_quantity;
  255. }
  256. else if(r_type==2) //ram
  257. {
  258. price+=1200*r_quantity;
  259. }
  260. else if(r_type==3) //ram
  261. {
  262. price+=2000*r_quantity;
  263. }
  264.  
  265. if(s_type==1) //ssd
  266. {
  267. price+=1250*s_quantity;
  268. }
  269. else if(s_type==2) //ssd
  270. {
  271. price+=600*s_quantity;
  272. }
  273. else if(s_type==3) //ssd
  274. {
  275. price+=1600*s_quantity;
  276. }
  277.  
  278. if(g_type==1) //gpu
  279. {
  280. price+=4000*g_quantity;
  281. }
  282. else if(g_type==2) //gpu
  283. {
  284. price+=2900*g_quantity;
  285. }
  286. else if(g_type==3) //gpu
  287. {
  288. price+=2100*g_quantity;
  289. }
  290. //cout << price << endl;
  291. return price;
  292. }
  293.  
  294. void search_hardware()
  295. {
  296. /*string hardware[2] = {"BENQ", "ACER PREDATOR X34"};
  297. char searchmore = 'y';
  298.  
  299. system("cls");
  300. while (searchmore == 'y' || searchmore == 'Y')
  301. {
  302.  
  303. cout << "Enter hardware to search: ";
  304. getline(cin,hardware[2]);
  305.  
  306. int found=0;
  307.  
  308. for (int j=0; j<2; j++)
  309. {
  310. if (strcmp(hardware[j], hardware)==0)
  311. {
  312. found=1;
  313. break;
  314. }
  315. }
  316. if (found==1)
  317. {
  318. cout << setfill ('-') << setw (30) << "-" << endl;
  319. cout << "The model is available" << endl;
  320. cout << setfill ('-') << setw (30) << "-" << endl;
  321. }
  322. else
  323. {
  324. cout << endl;
  325. cout << "Sorry, the model is not available";
  326. }
  327.  
  328. cout << "\nSearch again? (Y/N): ";
  329. cin >> searchmore;
  330. }
  331.  
  332. system ("cls");*/
  333. }
  334.  
  335. void exit_system()
  336. {
  337. cout << endl;
  338. cout << setfill ('-') << setw (55) << "-" << endl;
  339. cout << "\tHave a nice day!" << endl;
  340. cout << setfill ('-') << setw (55) << "-" << endl;
  341. cout << endl;
  342. }
  343.  
  344. int admin_login()
  345. {
  346. string userName;
  347. string password;
  348. int loginAttempt = 0;
  349.  
  350. while (loginAttempt < 3)
  351. {
  352. cout << "Please enter username: ";
  353. cin >> userName;
  354. cout << "Please enter password: ";
  355. cin >> password;
  356.  
  357. if (userName == "admin" && password == "eop123")
  358. {
  359. cout << "Welcome Admin!" << endl;
  360. break;
  361. }
  362. else
  363. {
  364. cout << "Invalid login attempt. Please try again.\n" << '\n';
  365. loginAttempt++;
  366. }
  367. }
  368. if (loginAttempt == 3)
  369. {
  370. cout << "Too many login attempts! The program will now terminate.";
  371. return 0;
  372. }
  373. }
  374.  
  375. int main()
  376. {
  377. char choice;
  378.  
  379. //loading screen
  380. /*system("cls");
  381. for(int i=1;i<=50;i++)
  382. {
  383. system("cls");
  384. cout<<"\n\n\n\n\t\t\t\t Loading "<<'\n'<<'\t'<<'\t';
  385.  
  386. for(int j=1;j<=i;j++)
  387. cout<<"²";
  388. cout<<"\n\n\t "<<2*i<<"%";
  389.  
  390. if(i>1 && i<20)
  391. cout<<"\n\n\tConnecting to server...";
  392. else if(i>20 && i<40)
  393. cout<<"\n\n\tChecking your browser...";
  394. else if(i>40 && i<48)
  395. cout<<"\n\n\tAccessing Cache...";
  396. else cout<<"\n\n\tComplete. Press Enter to Continue ";
  397. Sleep(10);
  398. }
  399. getch();
  400. system("cls");*/
  401.  
  402. cout << endl;
  403. cout << setfill ('-') << setw (55) << "-" << endl;
  404. cout << "\tWelcome to IIUM Computer Hardware Shop" << endl;
  405. cout << setfill ('-') << setw (55) << "-" << endl;
  406.  
  407. do
  408. {
  409.  
  410. cout << "\nA - Search hardware availability" << endl;
  411. cout << "\nB - Buy PC hardware" << endl;
  412. cout << "\nC - Exit System" << endl;
  413. cout << "\nX - Shopkeeper/Admin Access" << endl;
  414. cout << "\nPlease enter your selection: ";
  415. cin >> choice;
  416. cin.ignore();
  417.  
  418. choice = toupper(choice); // Transform to uppercase
  419.  
  420. switch (choice)
  421. {
  422. case 'A': search_hardware();
  423. break;
  424.  
  425. case 'B': welcomeScreen();
  426. break;
  427.  
  428. case 'C': exit_system();
  429. break;
  430.  
  431. case 'X': admin_login();
  432. break;
  433.  
  434. default: cout << endl;
  435. cout << "==== Invalid entry. Please select A, B, or C ====" << endl;
  436. break;
  437. }
  438. }while (choice!= 'C');
  439.  
  440. system ("pause");
  441. return 0;
  442. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement