Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // SPP COMPUTER STORE - Created by Adam Chester and George Dawoud
- #include <stdio.h>
- #include <iostream>
- #include <string.h>
- #include <stdlib.h>
- #include <cmath>
- #include <vector>
- using namespace std;
- void login(); //login here
- void store(); // main store
- void purchase(); // purchase item
- void inventory(); // displays list of inventory
- void randomid(); //generates random ID for each item purchased
- void checkout(); //function to checkout
- void trans_id(); //transaction id
- static const char transid[] = // letters and numbers for the transaction id
- "0123456789"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- int stringLength = sizeof(transid) - 1; // the size of the string of the transaction id
- char genRandom() {
- return transid[rand() % stringLength];
- }
- double bank = 1000; // maximum dollars to spend
- void purchase() // function for purchasing each item
- {
- cout << "What would you like to buy?";
- inventory();
- checkout();
- }
- void checkout() // prices of items and checkout function.
- {
- int choice;
- string answer;
- double keyboard = 7.99;
- double mouse = 2.99;
- double moniter = 69.99;
- double fan =27.99;
- double motherboard = 64.98;
- double cpu = 29.99;
- double graphic_card =344.99;
- double operating_system =12.99;
- double pc_case =19.53;
- double hardrive =99.96;
- cin >> choice;
- switch (choice)
- {
- case 1:
- cout << "You have chosen a Keyboard.\n"; // case for keyboard
- cout << "Price: $7.99 \n"; // price of item
- cout << "Sales tax: $0.56\n"; // tax on item
- cout << "Shipping Rate: $2.00 \n"; // shipping on item
- keyboard += (.07 * keyboard) + 2;
- cout << "Total: $" << keyboard << endl;
- if (keyboard > bank) {
- cout << "Sorry you can't afford this #BROKE"; // if you do not have enough money for the item
- exit(0);
- }
- if (keyboard < bank) { // transaction if you buy
- randomid();
- bank -= keyboard;
- cout << "\n" << "Account Balance: $" << bank << endl; // the amount of money in the bank before and after expenses
- cout << "Would you like to purchase anything else? (y for Yes - n for No)\n";
- cin >> answer;
- if (answer == "y") { // continue function if you continue shopping
- cout << "\n\n";
- purchase();
- }
- if (answer == "n") { // if you chose not to continur shopping
- cout << "Thank you for shopping";
- exit(0);
- }
- }
- break;
- case 2:
- cout << "You have chosen a Mouse.\n"; // case for mouse
- cout << "Price: $2.99 \n"; // price of mouse
- cout << "Sales tax: $0.20 \n"; // tax on mouse
- cout << "Shipping Rate: $1.50 \n"; // shipping on item
- mouse += (.07 * mouse) + 1.5;
- cout << "Total: $" << mouse << endl;
- if (mouse > bank) { // if you do not have enough money for the item this is the statement that appears.
- cout << "Sorry you can't afford this #BROKE";
- exit(0);
- }
- if (mouse < bank) { // if you choose to buy the item
- randomid();
- bank -= mouse;
- cout << "\n" << "Account Balance: $" << bank << endl;
- cout<< "Would you like to purchase anything else? (y for Yes - n for No)\n";
- cin >> answer;
- if (answer == "y") { // if you continue shoppig
- cout << "\n\n";
- purchase();
- }
- if (answer == "n") { // if you stop shopping
- cout << "Thank you for shopping";
- exit(0);
- }
- }
- break;
- case 3:
- cout << "You have chosen a Moniter.\n"; // case for item
- cout << "Price: $69.99 \n"; // price of item
- cout << "Sales tax: $4.90 \n"; // amound of tax
- cout << "Shipping Rate: $9.00 \n"; // price of shipping on item
- moniter += (.07 * moniter) + 9.00;
- cout << "Total: $" << moniter << endl;
- if (moniter > bank) { // if you dont have enough money for the item this statement appears
- cout << "Sorry you can't afford this #BROKE";
- exit(0);
- }
- if (moniter < bank) { // if you have enough money buy the item this function occurs
- randomid();
- bank -= moniter;
- cout << "\n" << "Account Balance: $" << bank << endl;
- cout<< "Would you like to purchase anything else? (y for Yes - n for No)\n"; // to choose whether or not to continue shopping
- cin >> answer;
- if (answer == "y") { // if yes continue shopping
- cout << "\n\n";
- purchase();
- }
- if (answer == "n") { // if no it exits
- cout << "Thank you for shopping";
- exit(0);
- }
- }
- break;
- case 4:
- cout << "You have chosen a Motherboard.\n"; // case of motherboard
- cout << "Price: $64.98 \n"; // price of item
- cout << "Sales tax: $4.55\n"; // tax on item
- cout << "Shipping Rate: $6.50 \n"; // shipping on item
- motherboard += (.07 * motherboard) + 6.5;
- cout << "Total: $" << motherboard << endl;
- if (motherboard > bank) { // if you cant buy the item this prints
- cout << "Sorry you can't afford this #BROKE";
- exit(0);
- }
- if (motherboard < bank) { // math of subtracting item from total money
- randomid();
- bank -= motherboard;
- cout << "\n" << "Account Balance: $" << bank << endl;
- cout<< "Would you like to purchase anything else? (y for Yes - n for No)\n";
- cin >> answer;
- if (answer == "y") { // if you continue to shop re run function and buy again
- cout << "\n\n";
- purchase();
- }
- if (answer == "n") { // if choose not to continue shopping exit code
- cout << "Thank you for shopping";
- exit(0);
- }
- }
- break;
- case 5:
- cout << "You have chosen a CPU.\n"; // case of cpu
- cout << "Price: $29.99 \n"; // price of item
- cout << "Sales tax: $2.09\n"; // tax on item
- cout << "Shipping Rate: $3.00 \n"; // shipping on item
- cpu += (.07 * cpu) + 3.00;
- cout << "Total: $" << cpu << endl;
- if (cpu > bank) { // if you cant afford the item this prints
- cout << "Sorry you can't afford this #BROKE";
- exit(0);
- }
- if (cpu < bank) { // if you have enough money to buy and choose too the math occurs here
- randomid();
- bank -= cpu;
- cout << "\n" << "Account Balance: $" << bank << endl;
- cout<< "Would you like to purchase anything else? (y for Yes - n for No)\n";
- cin >> answer;
- if (answer == "y") { // if you choose to continue shopping you re run the purchase function
- cout << "\n\n";
- purchase();
- }
- if (answer == "n") { // if not to continue shopping you exit the program
- cout << "Thank you for shopping";
- exit(0);
- }
- }
- break;
- case 6:
- cout << "You have chosen a Graphic Card.\n"; // case of graphic card
- cout << "Price: $344.99 \n"; // price of item
- cout << "Sales tax: $24.15\n"; // tax on item
- cout << "Shipping Rate: $11.00 \n"; // shipping on item
- graphic_card += (.07 * graphic_card) + 11.00;
- cout << "Total: $" << graphic_card << endl;
- if (graphic_card > bank) { // if you cant afford the item this prints
- cout << "Sorry you can't afford this #BROKE";
- exit(0);
- }
- if (graphic_card < bank) { // if you have enough money the transaction goes through and you choose to continue or stop shopping
- randomid();
- bank -= graphic_card;
- cout << "\n" << "Account Balance: $" << bank << endl;
- cout<< "Would you like to purchase anything else? (y for Yes - n for No)\n";
- cin >> answer;
- if (answer == "y") { // if you choose to shop re run the purchase function
- cout << "\n\n";
- purchase();
- }
- if (answer == "n") { // if you choose to stop shopping exit program
- cout << "Thank you for shopping";
- exit(0);
- }
- }
- break;
- case 7:
- cout << "You have chosen Windows Vista Operating System.\n"; // case of operating system
- cout << "Price: $12.99 \n"; // price of item
- cout << "Sales tax: $0.91 \n"; // tax on item
- cout << "Shipping Rate: $4.00 \n"; // shipping on item
- operating_system += (.07 * operating_system) + 4;
- cout << "Total: $" << operating_system << endl;
- if (operating_system > bank) { // if you dont have enough money for the item this prints
- cout << "Sorry you can't afford this #BROKE";
- exit(0);
- }
- if (operating_system < bank) { // if you have enough the transaction goes through and you choose whether or not to buy
- randomid();
- bank -= operating_system;
- cout << "\n" << "Account Balance: $" << bank << endl;
- cout<< "Would you like to purchase anything else? (y for Yes - n for No)\n";
- cin >> answer;
- if (answer == "y") { // if you choose to continue shopping purchase function re runs
- cout << "\n\n";
- purchase();
- }
- if (answer == "n") { // if choose to stop shopping exit program
- cout << "Thank you for shopping";
- exit(0);
- }
- }
- break;
- case 8:
- cout << "You have chosen the computer case.\n"; // case for pc case
- cout << "Price: $19.53 \n"; // price of item
- cout << "Sales tax: $1.37\n"; // tax on item
- cout << "Shipping Rate: $0.50\n"; // shipping on item
- pc_case += (.07 * pc_case) +.5;
- cout << "Total: $" << pc_case << endl;
- if (pc_case > bank) { // if you dont have enough money for the item this prints
- cout << "Sorry you can't afford this #BROKE";
- exit(0);
- }
- if (pc_case < bank) {
- randomid();
- bank -= pc_case; // if you have enough money the math is here
- cout << "\n" << "Account Balance: $" << bank << endl;
- cout<< "Would you like to purchase anything else? (y for Yes - n for No)\n";
- cin >> answer;
- if (answer == "y") { // if you continue to shop the purchase function runs again
- cout << "\n\n";
- purchase();
- }
- if (answer == "n") { // code exits if choose not to continue shopping
- cout << "Thank you for shopping";
- exit(0);
- }
- }
- break;
- case 9:
- cout << "You have chosen a Fan.\n"; // case for fan
- cout << "Price: $27.99 \n"; // price of fan
- cout << "Sales tax: $1.96\n"; // tax on item
- cout << "Shipping Rate: $2.25\n"; // shipping on item
- fan += (.07 * fan) + 2.25;
- cout << "Total: $" << fan << endl;
- if (fan > bank){
- cout << "Sorry you can't afford this #BROKE"; // if you dont have enough money this prints out
- exit(0);
- }
- 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
- randomid();
- bank -= fan;
- cout << "\n" << "Account Balance: $" << bank << endl;
- cout<< "Would you like to purchase anything else? (y for Yes - n for No)\n";
- cin >> answer;
- if (answer == "y") { // if you continue to shop you go back to the list and purchase again
- cout << "\n\n";
- purchase();
- }
- if (answer == "n") {
- cout << "Thank you for shopping"; // if you dont want to shop this prints and the program terminates
- exit(0);
- }
- }
- break;
- case 10:
- cout << "You have chosen a Hardrive.\n"; // case for hardrive
- cout << "Price: $99.96 \n"; // price of hardrive
- cout << "Sales tax: $7.00 \n"; // tax on item
- cout << "Shipping Rate: $5.75\n"; // shipping of item
- hardrive += (.07 * hardrive) + 5.75;
- cout << "Total: $" << hardrive << endl;
- if (hardrive > bank) { // if you dont have enough money for the item this prints
- cout << "Sorry you can't afford this #BROKE";
- exit(0);
- }
- if (hardrive < bank) { // if you have enough money the math occurs and the balance prints
- randomid();
- bank -= hardrive;
- cout << "\n" << "Account Balance: $" << bank << endl;
- cout<< "Would you like to purchase anything else? (y for Yes - n for No)\n";
- cin >> answer;
- if (answer == "y") { // if you choose to continue shopping this happens
- cout << "\n\n";
- purchase();
- }
- if (answer == "n") { // if you choose not to continue shopping this happens
- cout << "Thank you for shopping";
- exit(0);
- }
- }
- break;
- default: cout << "That choice is invalid.";
- }
- }
- void trans_id() {
- srand(time(0));
- for(int z=0; z < 10; z++)
- {
- cout << genRandom();
- }
- }
- void inventory() // the inventory function with all the items and their prices
- {
- cout << endl << "Here is what we have in stock:\n";
- cout << " 1. Keyboard: $7.99\n" << " 2. Mouse: $2.99\n";
- cout << " 3. Moniter: $69.99\n" << " 4. Motherboard: $64.98\n" << " 5. CPU: $29.99\n";
- cout << " 6. Graphic Card: $344.99\n" << " 7. Windows Vista Operating System: $12.99\n";
- cout << " 8. Computer Case: $19.53\n" << " 9. Fan: $27.99\n" << " 10. Hardrive: $99.96\n";
- }
- void store() // the storre function which pretty much starts the entire program
- {
- cout << "\n" << "Welcome to the SPP Computer store\n\n";
- purchase();
- }
- void randomid() // function that prints the random id
- {
- cout << "Your transaction ID code: ";
- trans_id();
- }
- void login()
- {
- char username[5],password[5];
- const char* USERNAME = "ADMIN"; // Given username
- const char* PASSWORD = "admin"; // Given password
- cout << " Username: ";
- cin >> username; // input username
- cout << " Password: ";
- cin >> password; // input password
- if (strcmp (username,USERNAME) ==0) // comparing the input username to given username to see if its the same (if works continue)
- {
- if (strcmp (password,PASSWORD) ==0) // checks if input password is the same as given password (if work continue)
- {
- store();
- }
- }
- }
- int main()
- {
- login();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement