SHARE
TWEET

Untitled

a guest Oct 24th, 2019 101 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "ShoppingCart.h"
  2. //string customerName;
  3. // string currentDate;
  4. // vector <ItemToPurchase> cartItems;
  5. // Default constructor
  6. // Parameterized constructor which takes the customer name and date as parameters (1 pt)
  7. // Private data members
  8. // string customerName - Initialized in default constructor to "none"
  9. // string currentDate - Initialized in default constructor to "January 1, 2016"
  10. // vector < ItemToPurchase > cartItems
  11. // Public member functions
  12. // GetCustomerName() accessor (1 pt)
  13. // GetDate() accessor (1 pt)
  14. // AddItem()
  15. // Adds an item to cartItems vector. Has parameter ItemToPurchase. Does not return anything.
  16. // RemoveItem()
  17. // Removes item from cartItems vector. Has a string (an item's name) parameter. Does not return anything.
  18. // If item name cannot be found, output this message: Item not found in cart. Nothing removed.
  19. // ModifyItem()
  20. // Modifies an item's description, price, and/or quantity. Has parameter ItemToPurchase. Does not return anything.
  21. // If item can be found (by name) in cart, check if parameter has default values for description, price, and quantity. If not, modify item in cart.
  22. // If item cannot be found (by name) in cart, output this message: Item not found in cart. Nothing modified.
  23. // GetNumItemsInCart() (2 pts)
  24. // Returns quantity of all items in cart. Has no parameters.
  25. // GetCostOfCart() (2 pts)
  26. // Determines and returns the total cost of items in cart. Has no parameters.
  27. // PrintTotal()
  28. // Outputs total of objects in cart.
  29. // If cart is empty, output this message: SHOPPING CART IS EMPTY
  30. // PrintDescriptions()
  31. // Outputs each item's description.
  32.  
  33. ShoppingCart::ShoppingCart() {
  34.     customerName = "none";
  35.     currentDate = "January 1, 2016";
  36. }
  37.  
  38. ShoppingCart::ShoppingCart(string name, string date) {
  39.     customerName = name;
  40.     currentDate = date;
  41. }
  42.  
  43. string ShoppingCart::GetCustomerName() {
  44.     return customerName;
  45. }
  46.  
  47. string ShoppingCart::GetDate() {
  48.     return currentDate;
  49. }
  50.    
  51. void ShoppingCart::AddItem(ItemToPurchase newItem) {
  52.     cartItems.push_back(newItem);
  53. }
  54.  
  55. void ShoppingCart::RemoveItem(string itemName) {
  56.     bool found = false;
  57.     for (unsigned int i = 0; i < cartItems.size(); i++) {
  58.         if (cartItems.at(i).GetName() == itemName) {
  59.             cartItems.erase(cartItems.begin() + i);
  60.             found = true;
  61.         }
  62.     }
  63.     if (!found)
  64.         cout << "Item not found in cart. Nothing removed." << endl;
  65.        
  66. }
  67. void ShoppingCart::ModifyItem(ItemToPurchase item) {
  68.     cout << "FIXME" << endl;
  69. }
  70.  
  71. int ShoppingCart::GetNumItemsInCart() {
  72.     int total = 0;
  73.     for (unsigned int i = 0; i < cartItems.size(); i++) {
  74.         total = total + cartItems.at(i).GetQuantity();
  75.     }
  76.     return total;
  77. }
  78.  
  79. void ShoppingCart::PrintTotal() {
  80.     if (cartItems.size() == 0) {
  81.         cout << "SHOPPING CART IS EMPTY" << endl;
  82.     } else
  83.         cout << cartItems.size() << endl;
  84. }
  85.  
  86. void ShoppingCart::PrintDescriptions() {
  87.     for (unsigned int i = 0; i < cartItems.size(); i++) {
  88.         cartItems.at(i).PrintItemDescription();
  89.     }
  90. }
  91.  
  92. void ShoppingCart::PrintItemCost() {
  93.     for (unsigned int i = 0; i < cartItems.size(); i++) {
  94.         cartItems.at(i).PrintItemCost();
  95.     }
  96. }
  97.  
  98. void ShoppingCart::PrintTotalCost() {
  99.     int totalCost = 0;
  100.     for (unsigned int i = 0; i < cartItems.size(); i++) {
  101.        totalCost = totalCost + cartItems.at(i).GetPrice();
  102.     }
  103.     cout << "Total: $" << totalCost << endl;
  104. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top