Advertisement
Guest User

Untitled

a guest
Dec 6th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.96 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,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,quantity=0;
  72. const int SIZE=3;
  73. char shopmember,addorder = 'y';
  74. double total_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 >> 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 >> 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 >> 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 >> 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 >> quantity;
  205. }
  206.  
  207. total_price=calcFunc(m_type,c_type,r_type,s_type,g_type,quantity,total_price,shopmember); //function call
  208.  
  209. cout << setfill ('-') << setw (55) << "-" << endl;
  210. cout << "Total price for now (not including membership discount): RM" << total_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.  
  218. if (shopmember == 'y' || shopmember == 'Y')
  219. cout << "Total Price: RM" << total_price-(total_price*discount) << endl;
  220. else
  221. cout << "Total Price: RM" << total_price << endl;
  222. cout << setfill ('-') << setw (55) << "-" << endl;
  223. }
  224.  
  225. double calcFunc(int m_type,int c_type,int r_type, int s_type, int g_type,int quantity,double total_price, char shopmember)
  226. {
  227. double m_price=0,c_price=0,r_price=0,s_price=0,g_price=0;
  228.  
  229. if(m_type==1) //monitor
  230. {
  231. m_price+=3000*quantity;
  232. }
  233. else if(m_type==2) //monitor
  234. {
  235. m_price+=4000*quantity;
  236. }
  237. else if(m_type==3) //monitor
  238. {
  239. m_price+=8000*quantity;
  240. }
  241.  
  242. if(c_type==1) //cpu
  243. {
  244. c_price+=1200*quantity;
  245. }
  246. else if(c_type==2) //cpu
  247. {
  248. c_price+=1200*quantity;
  249. }
  250. else if(c_type==3) //cpu
  251. {
  252. c_price+=8000*quantity;
  253. }
  254.  
  255. if(r_type==1) //ram
  256. {
  257. r_price+=400*quantity;
  258. }
  259. else if(r_type==2) //ram
  260. {
  261. r_price+=1200*quantity;
  262. }
  263. else if(r_type==3) //ram
  264. {
  265. r_price+=2000*quantity;
  266. }
  267.  
  268. if(s_type==1) //ssd
  269. {
  270. s_price+=1250*quantity;
  271. }
  272. else if(s_type==2) //ssd
  273. {
  274. s_price+=600*quantity;
  275. }
  276. else if(s_type==3) //ssd
  277. {
  278. s_price+=1600*quantity;
  279. }
  280.  
  281. if(g_type==1) //gpu
  282. {
  283. g_price+=4000*quantity;
  284. }
  285. else if(g_type==2) //gpu
  286. {
  287. g_price+=2900*quantity;
  288. }
  289. else if(g_type==3) //gpu
  290. {
  291. g_price+=2100*quantity;
  292. }
  293.  
  294. cout << m_price << endl;
  295. cout << c_price << endl;
  296. cout << r_price << endl;
  297. cout << s_price << endl;
  298. cout << g_price << endl;
  299.  
  300. total_price=m_price+c_price+r_price+s_price+g_price;
  301. return total_price;
  302. }
  303.  
  304. void search_hardware()
  305. {
  306. /*string hardware[2] = {"BENQ", "ACER PREDATOR X34"};
  307. char searchmore = 'y';
  308.  
  309. system("cls");
  310. while (searchmore == 'y' || searchmore == 'Y')
  311. {
  312.  
  313. cout << "Enter hardware to search: ";
  314. getline(cin,hardware[2]);
  315.  
  316. int found=0;
  317.  
  318. for (int j=0; j<2; j++)
  319. {
  320. if (strcmp(hardware[j], hardware)==0)
  321. {
  322. found=1;
  323. break;
  324. }
  325. }
  326. if (found==1)
  327. {
  328. cout << setfill ('-') << setw (30) << "-" << endl;
  329. cout << "The model is available" << endl;
  330. cout << setfill ('-') << setw (30) << "-" << endl;
  331. }
  332. else
  333. {
  334. cout << endl;
  335. cout << "Sorry, the model is not available";
  336. }
  337.  
  338. cout << "\nSearch again? (Y/N): ";
  339. cin >> searchmore;
  340. }
  341.  
  342. system ("cls");*/
  343. }
  344.  
  345. void exit_system()
  346. {
  347. cout << endl;
  348. cout << setfill ('-') << setw (55) << "-" << endl;
  349. cout << "\tHave a nice day!" << endl;
  350. cout << setfill ('-') << setw (55) << "-" << endl;
  351. cout << endl;
  352. }
  353.  
  354. int admin_login()
  355. {
  356. string userName;
  357. string password;
  358. int loginAttempt = 0;
  359.  
  360. while (loginAttempt < 3)
  361. {
  362. cout << "Please enter username: ";
  363. cin >> userName;
  364. cout << "Please enter password: ";
  365. cin >> password;
  366.  
  367. if (userName == "admin" && password == "eop123")
  368. {
  369. cout << "Welcome Admin!" << endl;
  370. break;
  371. }
  372. else
  373. {
  374. cout << "Invalid login attempt. Please try again.\n" << '\n';
  375. loginAttempt++;
  376. }
  377. }
  378. if (loginAttempt == 3)
  379. {
  380. cout << "Too many login attempts! The program will now terminate.";
  381. return 0;
  382. }
  383. }
  384.  
  385. int main()
  386. {
  387. char choice;
  388.  
  389. //loading screen
  390. /*system("cls");
  391. for(int i=1;i<=50;i++)
  392. {
  393. system("cls");
  394. cout<<"\n\n\n\n\t\t\t\t Loading "<<'\n'<<'\t'<<'\t';
  395.  
  396. for(int j=1;j<=i;j++)
  397. cout<<"²";
  398. cout<<"\n\n\t "<<2*i<<"%";
  399.  
  400. if(i>1 && i<20)
  401. cout<<"\n\n\tConnecting to server...";
  402. else if(i>20 && i<40)
  403. cout<<"\n\n\tChecking your browser...";
  404. else if(i>40 && i<48)
  405. cout<<"\n\n\tAccessing Cache...";
  406. else cout<<"\n\n\tComplete. Press Enter to Continue ";
  407. Sleep(10);
  408. }
  409. getch();
  410. system("cls");*/
  411.  
  412. cout << endl;
  413. cout << setfill ('-') << setw (55) << "-" << endl;
  414. cout << "\tWelcome to IIUM Computer Hardware Shop" << endl;
  415. cout << setfill ('-') << setw (55) << "-" << endl;
  416.  
  417. do
  418. {
  419.  
  420. cout << "\nA - Search hardware availability" << endl;
  421. cout << "\nB - Buy PC hardware" << endl;
  422. cout << "\nC - Exit System" << endl;
  423. cout << "\nX - Shopkeeper/Admin Access" << endl;
  424. cout << "\nPlease enter your selection: ";
  425. cin >> choice;
  426. cin.ignore();
  427.  
  428. choice = toupper(choice); // Transform to uppercase
  429.  
  430. switch (choice)
  431. {
  432. case 'A': search_hardware();
  433. break;
  434.  
  435. case 'B': welcomeScreen();
  436. break;
  437.  
  438. case 'C': exit_system();
  439. break;
  440.  
  441. case 'X': admin_login();
  442. break;
  443.  
  444. default: cout << endl;
  445. cout << "==== Invalid entry. Please select A, B, or C ====" << endl;
  446. break;
  447. }
  448. }while (choice!= 'C');
  449.  
  450. system ("pause");
  451. return 0;
  452. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement