Guest User

Untitled

a guest
Dec 11th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. int PCPurchase()
  2. {
  3. struct customer cust;
  4. system("color 0A");
  5. char laptop[100];
  6. double total_bill;
  7. const double TAX=0.06;
  8.  
  9. system("cls");
  10. cout << setfill ('-') << setw (55) << "-" << endl;
  11. cout << "ttCustomer Dashboard" << endl;
  12. cout << setfill ('-') << setw (55) << "-" << endl;
  13.  
  14. fptr=fopen("laptop.txt","ab+");
  15. cout << "Available laptops: " << endl;
  16. rewind(fptr);
  17. while(fread(&PC,sizeof(PC),1,fptr)==1)
  18. {
  19. cout << endl << "Laptop company and name: ";
  20. cout << PC.laptopcompany << endl;
  21. cout << "RAM: ";
  22. cout << PC.RAM << endl;
  23. cout << "Processor: ";
  24. cout << PC.Processor << endl;
  25. cout << "Price: RM";
  26. cout << PC.price << endl;
  27. }
  28. cout << "nPress any key to continue purchase" << endl;
  29. getch();
  30. fflush(stdin);
  31.  
  32. getInfo(cust); //get information of customer
  33.  
  34. cout << "Enter the laptop company and name you want to buy: " << endl;
  35. cout << "(Type 'RETURN' if you do not want to purchase)" << endl << endl;
  36. gets(laptop);
  37. rewind(fptr);
  38. while(fread(&PC,sizeof(PC),1,fptr)==1)
  39. {
  40. if(strcmpi(PC.laptopcompany,laptop)==0)
  41. {
  42. cout << setfill ('-') << setw (55) << "-" << endl;
  43. cout << "tYou have selected" << endl;
  44. cout << setfill ('-') << setw (55) << "-" << endl;
  45. cout << "Laptop company and name: ";
  46. cout << PC.laptopcompany << endl;
  47. cout << "RAM: ";
  48. cout << PC.RAM << endl;
  49. cout << "Processor: ";
  50. cout << PC.Processor << endl;
  51. cout << "Price: ";
  52. cout << PC.price << endl;
  53.  
  54. total_bill=PC.price+(PC.price*TAX);
  55.  
  56. cout << setfill ('-') << setw (55) << "-" << endl;
  57. cout << fixed << showpoint << setprecision (2);
  58. cout << "Name: "<< cust.name << endl; // struct output
  59. cout << "Email: "<< cust.email << endl;
  60. cout << "Phone Number: " << cust.number << endl;
  61. cout << "Your total bill (including 6% tax): RM" << total_bill << endl;
  62. cout << setfill ('-') << setw (55) << "-" << endl;
  63.  
  64. cout << endl << "tPress 1 to return to main screen!";
  65. cout << endl << "tPress 2 to quit the program!";
  66.  
  67. char afterpurchase;
  68. afterpurchase=getche();
  69.  
  70. if (afterpurchase=='1')
  71. {
  72. fclose(fptr);
  73. main();
  74. }
  75. else
  76. exit_system();
  77. }
  78. else if(strcmpi("RETURN",laptop)==0)
  79. main();
  80. else
  81. {
  82. cout << endl << "tNot available!" << endl;
  83. cout << "tPress A to try again or B to return to main menu" << endl;
  84. char choice1;
  85. choice1=getche();
  86. choice1=toupper(choice1); // Transform to uppercase
  87.  
  88. switch (choice1)
  89. {
  90. case 'A': fclose(fptr);
  91. PCPurchase();
  92. break;
  93.  
  94. default : fclose(fptr);
  95. main();
  96. break;
  97. }
  98. }
  99. }
  100. }
Add Comment
Please, Sign In to add comment