Advertisement
Guest User

SPP store Adam Chester George Dawoud

a guest
Jan 16th, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 17.19 KB | None | 0 0
  1. // SPP COMPUTER STORE - Created by Adam Chester and George Dawoud
  2. #include <stdio.h>
  3. #include <iostream>
  4. #include <string.h>
  5. #include <stdlib.h>
  6. #include <cmath>
  7. #include <vector>
  8. using namespace std;
  9.  
  10. void login(); //login here
  11. void store(); // main store
  12. void purchase(); // purchase item
  13. void inventory(); // displays list of inventory
  14. void randomid(); //generates random ID for each item purchased
  15. void checkout(); //function to checkout
  16. void trans_id(); //transaction id
  17.  
  18. static const char transid[] = // letters and numbers for the transaction id
  19. "0123456789"
  20. "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  21.  
  22. int stringLength = sizeof(transid) - 1; // the size of the string of the transaction id
  23.  
  24. char genRandom() {
  25.     return transid[rand() % stringLength];
  26. }
  27.  
  28. double bank = 1000; // maximum dollars to spend
  29.  
  30.  
  31. void purchase() // function for purchasing each item
  32. {
  33. cout << "What would you like to buy?";
  34. inventory();
  35. checkout();
  36. }
  37.  
  38. void checkout() // prices of items and checkout function.
  39. {
  40. int choice;
  41. string answer;
  42.  
  43. double keyboard = 7.99;
  44. double mouse = 2.99;
  45. double moniter = 69.99;
  46. double fan =27.99;
  47. double motherboard = 64.98;
  48. double cpu = 29.99;
  49. double graphic_card =344.99;
  50. double operating_system =12.99;
  51. double pc_case =19.53;
  52. double hardrive =99.96;
  53. cin >> choice;
  54. switch (choice)
  55.     {
  56.         case 1:
  57.             cout << "You have chosen a Keyboard.\n"; // case for keyboard
  58.             cout << "Price: $7.99 \n"; // price of item
  59.             cout << "Sales tax: $0.56\n"; // tax on item
  60.             cout << "Shipping Rate: $2.00 \n";  // shipping on item
  61.             keyboard += (.07 * keyboard) + 2;
  62.             cout << "Total: $" << keyboard << endl;
  63.                 if (keyboard > bank) {
  64.                     cout << "Sorry you can't afford this #BROKE"; // if you do not have enough money for the item
  65.                     exit(0);
  66.                 }
  67.                 if (keyboard < bank) { // transaction if you buy
  68.                     randomid();
  69.                     bank -= keyboard;
  70.                     cout << "\n" << "Account Balance: $" << bank << endl; // the amount of money in the bank before and after expenses
  71.                     cout << "Would you like to purchase anything else? (y for Yes - n for No)\n";
  72.                     cin >> answer;
  73.                         if (answer == "y") { // continue function if you continue shopping
  74.                             cout << "\n\n";
  75.                             purchase();
  76.                         }
  77.                         if (answer == "n") { // if you chose not to continur shopping
  78.                             cout << "Thank you for shopping";
  79.                             exit(0);    
  80.                         }
  81.                        
  82.                 }
  83.            
  84.         break;
  85.         case 2:
  86.             cout << "You have chosen a Mouse.\n"; // case for mouse
  87.             cout << "Price: $2.99 \n"; // price of mouse
  88.             cout << "Sales tax: $0.20 \n"; // tax on mouse
  89.             cout << "Shipping Rate: $1.50 \n"; // shipping on item
  90.             mouse += (.07 * mouse) + 1.5;
  91.             cout << "Total: $" << mouse << endl;
  92.                 if (mouse > bank) { // if you do not have enough money for the item this is the statement that appears.
  93.                 cout << "Sorry you can't afford this #BROKE";
  94.                 exit(0);
  95.                 }
  96.                 if (mouse < bank) { // if you choose to buy the item
  97.                     randomid();
  98.                     bank -= mouse;
  99.                     cout << "\n" << "Account Balance: $" << bank << endl;
  100.                     cout<< "Would you like to purchase anything else? (y for Yes - n for No)\n";
  101.                     cin >> answer;
  102.                         if (answer == "y") { // if you continue shoppig
  103.                             cout << "\n\n";
  104.                             purchase();
  105.                         }
  106.                         if (answer == "n") { // if you stop shopping
  107.                             cout << "Thank you for shopping";
  108.                             exit(0);    
  109.                         }
  110.                 }
  111.         break;
  112.         case 3:
  113.             cout << "You have chosen a Moniter.\n"; // case for item
  114.             cout << "Price: $69.99 \n"; // price of item
  115.             cout << "Sales tax: $4.90 \n"; // amound of tax
  116.             cout << "Shipping Rate: $9.00 \n"; // price of shipping on item
  117.             moniter += (.07 * moniter) + 9.00;
  118.             cout << "Total: $" << moniter << endl;
  119.                 if (moniter > bank) { // if you dont have enough money for the item this statement appears
  120.                     cout << "Sorry you can't afford this #BROKE";
  121.                     exit(0);
  122.                 }
  123.                 if (moniter < bank) { // if you have enough money buy the item this function occurs
  124.                     randomid();
  125.                     bank -= moniter;
  126.                     cout << "\n" << "Account Balance: $" << bank << endl;
  127.                     cout<< "Would you like to purchase anything else? (y for Yes - n for No)\n"; // to choose whether or not to continue shopping
  128.                     cin >> answer;
  129.                         if (answer == "y") { // if yes continue shopping
  130.                             cout << "\n\n";
  131.                             purchase();
  132.                         }
  133.                         if (answer == "n") { // if no it exits
  134.                             cout << "Thank you for shopping";
  135.                             exit(0);    
  136.                         }
  137.                 }
  138.         break;
  139.         case 4:
  140.             cout << "You have chosen a Motherboard.\n"; // case of motherboard
  141.             cout << "Price: $64.98 \n"; // price of item
  142.             cout << "Sales tax: $4.55\n"; // tax on item
  143.             cout << "Shipping Rate: $6.50 \n"; // shipping on item
  144.             motherboard += (.07 * motherboard) + 6.5;
  145.             cout << "Total: $" << motherboard << endl;
  146.                 if (motherboard > bank) { // if you cant buy the item this prints
  147.                     cout << "Sorry you can't afford this #BROKE";
  148.                     exit(0);
  149.                 }
  150.                 if (motherboard < bank) { // math of subtracting item from total money
  151.                     randomid();
  152.                     bank -= motherboard;
  153.                     cout << "\n" << "Account Balance: $" << bank << endl;
  154.                     cout<< "Would you like to purchase anything else? (y for Yes - n for No)\n";
  155.                     cin >> answer;
  156.                         if (answer == "y") { // if you continue to shop re run function and buy again
  157.                             cout << "\n\n";
  158.                             purchase();
  159.                         }
  160.                         if (answer == "n") { // if choose not to continue shopping exit code
  161.                             cout << "Thank you for shopping";
  162.                             exit(0);    
  163.                         }
  164.                 }
  165.         break;
  166.         case 5:
  167.             cout << "You have chosen a CPU.\n"; // case of cpu
  168.             cout << "Price: $29.99 \n"; // price of item
  169.             cout << "Sales tax: $2.09\n"; // tax on item
  170.             cout << "Shipping Rate: $3.00 \n"; // shipping on item
  171.             cpu += (.07 * cpu) + 3.00;
  172.             cout << "Total: $" << cpu << endl;
  173.                 if (cpu > bank) { // if you cant afford the item this prints
  174.                     cout << "Sorry you can't afford this #BROKE";
  175.                     exit(0);
  176.                 }
  177.                 if (cpu < bank) { // if you have enough money to buy and choose too the math occurs here
  178.                     randomid();
  179.                     bank -= cpu;
  180.                     cout << "\n" << "Account Balance: $" << bank << endl;
  181.                     cout<< "Would you like to purchase anything else? (y for Yes - n for No)\n";
  182.                     cin >> answer;
  183.                         if (answer == "y") { // if you choose to continue shopping you re run the purchase function
  184.                             cout << "\n\n";
  185.                             purchase();
  186.                         }
  187.                         if (answer == "n") { // if not to continue shopping you exit the program
  188.                             cout << "Thank you for shopping";
  189.                             exit(0);    
  190.                         }
  191.                 }
  192.         break;
  193.         case 6:
  194.             cout << "You have chosen a Graphic Card.\n"; // case of graphic card
  195.             cout << "Price: $344.99 \n"; // price of item
  196.             cout << "Sales tax: $24.15\n"; // tax on item
  197.             cout << "Shipping Rate: $11.00 \n"; // shipping on item
  198.             graphic_card += (.07 * graphic_card) + 11.00;
  199.             cout << "Total: $" << graphic_card << endl;
  200.                 if (graphic_card > bank) { // if you cant afford the item this  prints
  201.                     cout << "Sorry you can't afford this #BROKE";
  202.                     exit(0);
  203.                 }
  204.                 if (graphic_card < bank) { // if you have enough money the transaction goes through and you choose to continue or stop shopping
  205.                     randomid();
  206.                     bank -= graphic_card;
  207.                     cout << "\n" << "Account Balance: $" << bank << endl;
  208.                     cout<< "Would you like to purchase anything else? (y for Yes - n for No)\n";
  209.                     cin >> answer;
  210.                         if (answer == "y") { // if you choose to shop re run the purchase function
  211.                             cout << "\n\n";
  212.                             purchase();
  213.                         }
  214.                         if (answer == "n") { // if you choose to stop shopping exit program
  215.                             cout << "Thank you for shopping";
  216.                             exit(0);    
  217.                         }
  218.                 }
  219.         break;
  220.         case 7:
  221.             cout << "You have chosen Windows Vista Operating System.\n"; // case of operating system
  222.             cout << "Price: $12.99 \n"; // price of item
  223.             cout << "Sales tax: $0.91 \n"; // tax on item
  224.             cout << "Shipping Rate: $4.00 \n"; // shipping on item
  225.             operating_system += (.07 * operating_system) + 4;
  226.             cout << "Total: $" << operating_system << endl;
  227.                 if (operating_system > bank) { // if you dont have enough money for the item this prints
  228.                     cout << "Sorry you can't afford this #BROKE";
  229.                     exit(0);
  230.                 }
  231.                 if (operating_system < bank) { // if you have enough the transaction goes through and you choose whether or not to buy
  232.                     randomid();
  233.                     bank -= operating_system;
  234.                     cout << "\n" << "Account Balance: $" << bank << endl;
  235.                     cout<< "Would you like to purchase anything else? (y for Yes - n for No)\n";
  236.                     cin >> answer;
  237.                         if (answer == "y") { // if you choose to continue shopping purchase function re runs
  238.                             cout << "\n\n";
  239.                             purchase();
  240.                         }
  241.                         if (answer == "n") { // if choose to stop shopping exit program
  242.                             cout << "Thank you for shopping";
  243.                             exit(0);    
  244.                         }
  245.                 }
  246.         break;
  247.         case 8:
  248.             cout << "You have chosen the computer case.\n"; // case for pc case
  249.             cout << "Price: $19.53 \n"; // price of item
  250.             cout << "Sales tax: $1.37\n"; // tax on item
  251.             cout << "Shipping Rate: $0.50\n"; // shipping on item
  252.             pc_case += (.07 * pc_case) +.5;
  253.             cout << "Total: $" << pc_case << endl;
  254.                 if (pc_case > bank) { // if you dont have enough money for the item this prints  
  255.                     cout << "Sorry you can't afford this #BROKE";
  256.                     exit(0);
  257.                 }
  258.                 if (pc_case < bank) {
  259.                     randomid();
  260.                     bank -= pc_case; // if you have enough money the math is here
  261.                     cout << "\n" << "Account Balance: $" << bank << endl;
  262.                     cout<< "Would you like to purchase anything else? (y for Yes - n for No)\n";
  263.                     cin >> answer;
  264.                         if (answer == "y") { // if you continue to shop the purchase function runs again
  265.                             cout << "\n\n";
  266.                             purchase();
  267.                         }
  268.                         if (answer == "n") { // code exits if choose not to continue shopping
  269.                             cout << "Thank you for shopping";
  270.                             exit(0);    
  271.                         }
  272.                 }
  273.         break;
  274.         case 9:
  275.             cout << "You have chosen a Fan.\n"; // case for fan
  276.             cout << "Price: $27.99 \n"; // price of fan
  277.             cout << "Sales tax: $1.96\n"; // tax on item
  278.             cout << "Shipping Rate: $2.25\n"; // shipping on item
  279.             fan += (.07 * fan) + 2.25;
  280.             cout << "Total: $" << fan << endl;
  281.                 if (fan > bank){
  282.                     cout << "Sorry you can't afford this #BROKE"; // if you dont have enough money this prints out
  283.                     exit(0);
  284.                 }
  285.                 if (fan < bank){ // if you have enough money the math is here that subtracts the money from the total amount of money that you have
  286.                     randomid();
  287.                     bank -= fan;
  288.                     cout << "\n" << "Account Balance: $" << bank << endl;
  289.                     cout<< "Would you like to purchase anything else? (y for Yes - n for No)\n";
  290.                     cin >> answer;
  291.                         if (answer == "y") { // if you continue to shop you go back to the list and purchase again
  292.                             cout << "\n\n";
  293.                             purchase();
  294.                         }
  295.                         if (answer == "n") {
  296.                             cout << "Thank you for shopping"; // if you dont want to shop this prints and the program terminates
  297.                             exit(0);    
  298.                         }
  299.                 }
  300.         break;
  301.         case 10:
  302.             cout << "You have chosen a Hardrive.\n"; // case for hardrive
  303.             cout << "Price: $99.96 \n"; // price of hardrive
  304.             cout << "Sales tax: $7.00 \n"; // tax on item
  305.             cout << "Shipping Rate: $5.75\n"; // shipping of item
  306.             hardrive += (.07 * hardrive) + 5.75;
  307.             cout << "Total: $" << hardrive << endl;
  308.                 if (hardrive > bank) { // if you dont have enough money for the item this prints
  309.                     cout << "Sorry you can't afford this #BROKE";
  310.                     exit(0);
  311.                 }
  312.                 if (hardrive < bank) { // if you have enough money the math occurs and the balance prints
  313.                     randomid();
  314.                     bank -= hardrive;
  315.                     cout << "\n" << "Account Balance: $" << bank << endl;
  316.                     cout<< "Would you like to purchase anything else? (y for Yes - n for No)\n";
  317.                     cin >> answer;
  318.                         if (answer == "y") { // if you choose to continue shopping this happens
  319.                             cout << "\n\n";
  320.                             purchase();
  321.                         }
  322.                         if (answer == "n") { // if you choose not to continue shopping this happens
  323.                             cout << "Thank you for shopping";
  324.                             exit(0);    
  325.                         }
  326.                 }
  327.         break;
  328.         default: cout <<  "That choice is invalid.";
  329.     }
  330. }
  331. void trans_id() {
  332.     srand(time(0));
  333.     for(int z=0; z < 10; z++)
  334.     {
  335.         cout << genRandom();
  336.  
  337.     }
  338. }
  339. void inventory() // the inventory function with all the items and their prices
  340. {
  341. cout << endl << "Here is what we have in stock:\n";
  342. cout << " 1. Keyboard: $7.99\n" << " 2. Mouse: $2.99\n";
  343. cout << " 3. Moniter: $69.99\n" << " 4. Motherboard: $64.98\n" << " 5. CPU: $29.99\n";
  344. cout << " 6. Graphic Card: $344.99\n" << " 7. Windows Vista Operating System: $12.99\n";
  345. cout << " 8. Computer Case: $19.53\n" << " 9. Fan: $27.99\n" << " 10. Hardrive: $99.96\n";
  346. }
  347.  
  348. void store() // the storre function which pretty much starts the entire program
  349. {
  350. cout << "\n" << "Welcome to the SPP Computer store\n\n";
  351. purchase();
  352.  
  353. }
  354.  
  355. void randomid() // function that prints the random id
  356. {
  357.     cout << "Your transaction ID code: ";
  358.     trans_id();
  359. }
  360. void login()
  361. {
  362.  char username[5],password[5];
  363.  
  364.     const char* USERNAME = "ADMIN"; // Given username
  365.     const char* PASSWORD = "admin"; // Given password
  366.     cout << " Username: ";
  367.     cin >> username; // input username
  368.     cout << " Password: ";
  369.     cin >> password; // input password
  370.    
  371.     if (strcmp (username,USERNAME) ==0) // comparing the input username to given username to see if its the same (if works continue)
  372.     {
  373.         if (strcmp (password,PASSWORD) ==0) // checks if input password is the same as given password  (if work continue)
  374.         {
  375.             store();
  376.         }
  377.     }
  378. }
  379.  
  380. int main()
  381. {
  382. login();
  383. return 0;
  384. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement