Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.87 KB | None | 0 0
  1. #ifndef HEADER_H
  2. #define HEADER_H
  3.  
  4. #include <string>
  5. #include <iostream>
  6. #include <iomanip>
  7.  
  8. using namespace std;
  9.  
  10. class CreditCard
  11. {
  12.     string cCard;
  13.     int pin;
  14.     double balance;
  15. public:
  16.     CreditCard()
  17.     {
  18.         string creditC = "";
  19.         int pinNum = 0;
  20.         double balanceCC = 0;
  21.     }
  22.     CreditCard(string creditC, int pinNum, double balanceCC)
  23.     {
  24.         cCard = creditC;
  25.         pin = pinNum;
  26.         balance = balanceCC;
  27.     }
  28.     void SetCCard(string creditC)
  29.     {
  30.         cCard = creditC;
  31.     }
  32.     void SetPin(int pinNum)
  33.     {
  34.         pin = pinNum;
  35.     }
  36.     void SetBalance(double balanceCC)
  37.     {
  38.         balance = balanceCC;
  39.     }
  40.     string GetCCard()
  41.     {
  42.         return cCard;
  43.     }
  44.     int GetPin()
  45.     {
  46.         return pin;
  47.     }
  48.     double GetBalance()
  49.     {
  50.         return balance;
  51.     }
  52.     ~CreditCard()
  53.     {}
  54. };
  55.  
  56. class Human
  57. {
  58.     string firstName;
  59.     string lastName;
  60.     string address;
  61.     string city;
  62.     string state;
  63.     int zipCode;
  64.     string id;
  65.     string password;
  66.     CreditCard creditCard;
  67. public:
  68.     Human()
  69.     {
  70.         string fn = "";
  71.         string ln = "";
  72.         string add = "";
  73.         string c = "";
  74.         string st = "";
  75.         int zip = 0;
  76.         string tempId = "";
  77.         string pass = "";
  78.     }
  79.     Human(string fn, string ln, string add, string c, string st, int zip, string tempId, string pass)
  80.     {
  81.         firstName = fn;
  82.         lastName = ln;
  83.         address = add;
  84.         city = c;
  85.         state = st;
  86.         zipCode = zip;
  87.         id = tempId;
  88.         password = pass;
  89.     }
  90.     void SetFirstName(string fn)
  91.     {
  92.         firstName = fn;
  93.     }
  94.     void SetLastName(string ln)
  95.     {
  96.         lastName = ln;
  97.     }
  98.     void SetAddress(string add)
  99.     {
  100.         address = add;
  101.     }
  102.     void SetCity(string c)
  103.     {
  104.         city = c;
  105.     }
  106.     void SetState(string st)
  107.     {
  108.         state = st;
  109.     }
  110.     void SetZipCode(int zip)
  111.     {
  112.         zipCode = zip;
  113.     }
  114.     void SetId(string tempId)
  115.     {
  116.         id = tempId;
  117.     }
  118.     void SetPassword(string pass)
  119.     {
  120.         password = pass;
  121.     }
  122.     string GetFirstName()
  123.     {
  124.         return firstName;
  125.     }
  126.     string GetLastName()
  127.     {
  128.         return lastName;
  129.     }
  130.     string GetAddress()
  131.     {
  132.         return address;
  133.     }
  134.     string GetCity()
  135.     {
  136.         return city;
  137.     }
  138.     string GetState()
  139.     {
  140.         return state;
  141.     }
  142.     int GetZipCode()
  143.     {
  144.         return zipCode;
  145.     }
  146.     string GetId()
  147.     {
  148.         return id;
  149.     }
  150.     string GetPassword()
  151.     {
  152.         return password;
  153.     }
  154.     void SetCreditCard(string cCard, int pin, double balance)
  155.     {
  156.         creditCard.SetCCard(cCard);
  157.         creditCard.SetPin(pin);
  158.         creditCard.SetBalance(balance);
  159.     }
  160.     string GetCCard()
  161.     {
  162.         return creditCard.GetCCard();
  163.     }
  164.     int GetPin()
  165.     {
  166.         return creditCard.GetPin();
  167.     }
  168.     double GetBalance()
  169.     {
  170.         return creditCard.GetBalance();
  171.     }
  172.     virtual void Talk()
  173.     {
  174.     }
  175.     ~Human()
  176.     {}
  177. };
  178. //abstract customer class
  179. class Customer : public Human
  180. {
  181. public:
  182.     Customer()
  183.     {
  184.         string fn = "";
  185.         string ln = "";
  186.         string add = "";
  187.         string c = "";
  188.         string st = "";
  189.         int zip = 0;
  190.     }
  191.     Customer(string fn, string ln, string add, string c, string st, int zip)
  192.     {
  193.     }
  194.     ~Customer()
  195.     {}
  196. };
  197.  
  198. //abstract Matre'd class
  199. class MatreD : public Human
  200. {
  201.     Customer *customerDB;
  202.     int customerIndex;
  203.     int i;
  204. public:
  205.     MatreD()
  206.     {}
  207.     void SetCustomerDB(Customer *db)
  208.     {
  209.         customerDB = db;
  210.     }
  211.     void SetCustomerIndex()
  212.     {
  213.         customerIndex = i;
  214.     }
  215.     int GetCustomerIndex()
  216.     {
  217.         return customerIndex;
  218.     }
  219.     void Talk()
  220.     {
  221.         string userFirst, userLast;
  222.         cout << "Welcome to Gooms' Reastaurant, my name is " << GetFirstName() << " " << GetLastName() << "." << endl;
  223.         cout << "Before I can seat you, I must verify that you are in our database." << endl;
  224.  
  225.         //do-while loop to check if name entered by user is in the database
  226.         bool foundName = false;
  227.         do
  228.         {
  229.             cout << "May I please have your first name? ";
  230.             cin >> userFirst;
  231.             cout << "May I please have your last name? ";
  232.             cin >> userLast;
  233.             // Lookup name
  234.             for(int i = 0; i < 10000; i++)
  235.             {
  236.                 if(userFirst == customerDB[i].GetFirstName() && userLast == customerDB[i].GetLastName())
  237.                 {
  238.                     foundName = true;
  239.                     customerIndex = i;
  240.                     break;
  241.                 }
  242.             }
  243.         }while(foundName == false);
  244.     }
  245.     ~MatreD()
  246.     {}
  247. };
  248.  
  249.  
  250.  
  251. //Menu class
  252. class MenuItem
  253. {
  254.     string itemName;
  255.     string itemDescription;
  256.     double itemPrice;
  257.     int qtyPurchased;
  258. public:
  259.     MenuItem()
  260.     {
  261.         itemName = "";
  262.         itemDescription = "";
  263.         itemPrice = 0;
  264.         qtyPurchased = 0;
  265.     }
  266.     MenuItem(string name, string desc, double price)
  267.     {
  268.         itemName = name;
  269.         itemDescription = desc;
  270.         itemPrice = price;
  271.         qtyPurchased = 0;
  272.     }
  273.     void SetItemName(string name)
  274.     {
  275.         itemName = name;
  276.     }
  277.     void SetItemDescription(string desc)
  278.     {
  279.         itemDescription = desc;
  280.     }
  281.     void SetItemPrice(double price)
  282.     {
  283.         itemPrice = price;
  284.     }
  285.     void SetQtyPurchased(int qty)
  286.     {
  287.         qtyPurchased = qty;
  288.     }
  289.     string GetItemName()
  290.     {
  291.         return itemName;
  292.     }
  293.     string GetItemDescription()
  294.     {
  295.         return itemDescription;
  296.     }
  297.     double GetItemPrice()
  298.     {
  299.         return itemPrice;
  300.     }
  301.     int GetQtyPurchased()
  302.     {
  303.         return qtyPurchased;
  304.     }
  305.    
  306. };
  307. //abstrast Server class
  308. class Server : public Human
  309. {
  310.     Customer *customerDB;
  311.     int customerIndex;
  312.     MenuItem *menuDB;
  313. public:
  314.     Server()
  315.     {}
  316.     void SetCustomerDB(Customer *cust)
  317.     {
  318.         customerDB = cust;
  319.     }
  320.     void SetCustomerIndex(int i)
  321.     {
  322.         customerIndex = i;
  323.     }
  324.     void SetMenuDB(MenuItem *menu)
  325.     {
  326.         menuDB = menu;
  327.     }
  328.     double ComputeTotal()
  329.     {
  330.         double runningTotal = 0;
  331.         for(int j = 0; j < 10; j++)
  332.         {
  333.             runningTotal += menuDB[j].GetItemPrice() * menuDB[j].GetQtyPurchased();
  334.         }
  335.         return runningTotal * 1.10 * 1.20;
  336.     }
  337.     //prints the customer info
  338.     void PrintCustomerInfo()
  339.     {
  340.         cout << "************************" << endl;
  341.         cout << "  Customer Information  " << endl;
  342.         cout << "************************" << endl;
  343.         cout << customerDB[customerIndex].GetFirstName() << " ";
  344.         cout << customerDB[customerIndex].GetLastName() << endl;
  345.         cout << customerDB[customerIndex].GetAddress() << endl;
  346.         cout << customerDB[customerIndex].GetCity() << ", ";
  347.         cout << customerDB[customerIndex].GetState() << " ";
  348.         cout << customerDB[customerIndex].GetZipCode() << endl;
  349.     }
  350.     //prints the menu for ordering
  351.     void PrintMenu()
  352.     {
  353.         cout << "Gooms' Restaurant Menu" << endl;
  354.         cout << "----------------------" << endl;
  355.         for(int k = 0; k < 10; k++)
  356.         {
  357.             cout << k << ". " << menuDB[k].GetItemName() << " $" << menuDB[k].GetItemPrice() << "     " <<menuDB[k].GetItemDescription() << endl;
  358.         }
  359.     }
  360.  
  361.     void Talk()
  362.     {
  363.         //Greet customer and get ready to verify info
  364.         string custFirstName = customerDB[customerIndex].GetFirstName();
  365.         string custLastName = customerDB[customerIndex].GetLastName();
  366.         cout << "Hello " << custFirstName << " " << custLastName << endl;
  367.         cout << "My name is " << GetFirstName() << " " << GetLastName() << "." << endl;
  368.         cout << "I have a few questions for you to verify your information in our database." << endl;
  369.         //verifies the customers id number
  370.         string tempId;
  371.         bool isCorrect;
  372.         do
  373.         {
  374.             cout << "What is your id number?" << endl;
  375.             cin >> tempId;
  376.             isCorrect = (tempId == customerDB[customerIndex].GetId());
  377.             if(isCorrect == false)
  378.             {
  379.                 cout << "The id number entered doesn't match our records, please enter your id again." << endl;
  380.             }
  381.         }while(!isCorrect);
  382.         //verifies the customers password
  383.         string tempPassword;
  384.         do
  385.         {
  386.             cout << "What is your password?" << endl;
  387.             cin >> tempPassword;
  388.             isCorrect = (tempPassword == customerDB[customerIndex].GetPassword());
  389.             if(isCorrect == false)
  390.             {
  391.                 cout << "The password entered doesn't match our records, please enter your password again." << endl;
  392.             }
  393.         }while(!isCorrect);
  394.         //verifies the customers credit card number
  395.         string tempCCard;
  396.         do
  397.         {
  398.             cout << "What is your credit card number?" << endl;
  399.             cin >> tempCCard;
  400.             isCorrect = (tempCCard == customerDB[customerIndex].GetCCard());
  401.             if(isCorrect == false)
  402.             {
  403.                 cout << "The credit card number entered doesn't match our records, please enter your credit card again." << endl;
  404.             }
  405.         }while(!isCorrect);
  406.         //verifies the customers pin number
  407.         int tempPin;
  408.         do
  409.         {
  410.             cout << "What is your pin number?" << endl;
  411.             cin >> tempPin;
  412.             isCorrect = (tempPin == customerDB[customerIndex].GetPin());
  413.             if(isCorrect == false)
  414.             {
  415.                 cout << "The pin number entered doesn't match our records, please enter your pin again." << endl;
  416.             }
  417.         }while(!isCorrect);
  418.         //info verified and print the main customer info for them to see
  419.         cout << "Thank you your information has been verified by our database." << endl;
  420.         //print customer info after verifying
  421.         PrintCustomerInfo();
  422.         char response;
  423.         while(true)
  424.         {
  425.             // Get user order
  426.             cout << endl;
  427.             cout << "Here is our Menu, please make a selection between 0 and 9 or press Q to quit." << endl;
  428.             PrintMenu();
  429.             cin >> response;
  430.             cin.ignore(100,'\n');
  431.  
  432.             // Quit if requested
  433.             if(toupper(response) == 'Q')
  434.                 break;
  435.  
  436.             // Convert response to integer and verify it's valid
  437.             int itemNumber = response - '0';
  438.             if(itemNumber < 0 || itemNumber > 9)
  439.             {
  440.                 cout << "Invalid selection" << endl;
  441.                 continue;
  442.             }
  443.  
  444.             // Add the item
  445.             menuDB[itemNumber].SetQtyPurchased(menuDB[itemNumber].GetQtyPurchased() + 1);
  446.             if(ComputeTotal() > customerDB[customerIndex].GetBalance())
  447.             {
  448.                 menuDB[itemNumber].SetQtyPurchased(menuDB[itemNumber].GetQtyPurchased() - 1);
  449.                 cout << "Not enought money on your credit card balance." << endl;
  450.             }
  451.         };
  452.         //prints the total price of their meal and thanks them for coming
  453.         cout << endl;
  454.         PrintCustomerInfo();
  455.         cout.setf(ios::fixed);
  456.         cout << "Your total with 10% tax and 20% gratuity is " << "$" << setprecision(2) << ComputeTotal() << endl;
  457.         double finalBalance;
  458.         finalBalance = customerDB[customerIndex].GetBalance() - ComputeTotal();
  459.         cout << "Your remaining balance on your Credit Card is $" << setprecision(2) << finalBalance << endl;
  460.         //customerDB[customerIndex].SetCreditCard = finalBalance;
  461.         cout << "Thank you for visiting Gooms' Restaurant, please come again." << endl;
  462.  
  463.         // Reset MenuDB Qty Purchased
  464.         for(int i = 0; i < 10; i++)
  465.         {
  466.             menuDB[i].SetQtyPurchased(0);
  467.         }
  468.     }//end of talk function
  469.         {}
  470. };
  471. #endIf;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement