Advertisement
davidsv

Untitled

Nov 23rd, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4. using namespace std;
  5.  
  6. struct Item
  7. {
  8. string name;
  9. double price;
  10. int quantity;
  11. };
  12.  
  13. void addItem(Item* shoppingCart);
  14. void listItems(Item* shoppingCart);
  15. void sumPrices(Item* shoppingCart);
  16.  
  17. int main()
  18. {
  19. char choice;
  20. Item* shoppingCart = new Item[100];
  21.  
  22. cout << "Shopping Cart is now available for use. \n";
  23. cout << "Please choose between the following choices: \n\n";
  24. cout << "1. Add Item: for adding new items to the cart\n";
  25. cout << "2. List Shopping Cart Contents: see what you have!\n";
  26. cout << "3. Total Price: how much does it add up to?\n";
  27. cout << "4. Quit: You're done here.\n";
  28.  
  29. cout << "Please enter your choice now: \n";
  30. cin >> choice;
  31.  
  32. switch (choice)
  33. {
  34. case '1': addItem(shoppingCart);
  35. break;
  36. case '2': listItems(shoppingCart);
  37. break;
  38. case '3': sumPrices(shoppingCart);
  39. break;
  40. case '4': cout << "Goodbye!\n";
  41. break;
  42. default: cout << "You did not enter a valid choice! \n";
  43. }
  44.  
  45.  
  46. return 0;
  47. }
  48.  
  49. /************************************************
  50. * This is the addItem function *
  51. ************************************************/
  52. void addItem(struct Item* shoppingCart)
  53. {
  54.  
  55. for(int i = 0; i < 100; i++)
  56. {
  57. cout << "Please enter the new item Name: \n";
  58. cin.ignore();
  59. getline(cin, shoppingCart[i].name);
  60. cout << "Please enter the new item Price: \n";
  61. cin >> shoppingCart[i].price;
  62. cout << "Please enter the new item Quantity: \n";
  63. cin >> shoppingCart[i].quantity;
  64.  
  65. while(shoppingCart[i].name != " ");
  66. }
  67.  
  68. return;
  69. }
  70.  
  71. /************************************************
  72. * This is the listItems function *
  73. ************************************************/
  74. void listItems(struct Item* shoppingCart)
  75. {
  76. cout << fixed << showpoint << setprecision(2) << "\n";
  77. for(int i = 0; i < 100; i++)
  78. {
  79. cout << "Item " << i << " name: " << shoppingCart[i].name << ".\n";
  80. cout << "Item " << i << " price: " << shoppingCart[i].price << ".\n";
  81. cout << "Item " << i << " quantity: " << shoppingCart[i].quantity << ".\n";
  82. while (shoppingCart[i].name != " ");
  83. }
  84.  
  85. return;
  86. }
  87.  
  88. /************************************************
  89. * This is the sumPrices function *
  90. ************************************************/
  91. void sumPrices(struct Item* shoppingCart)
  92. {
  93. cout << fixed << showpoint << setprecision(2) << "\n";
  94. double sumTotal = 0.00;
  95.  
  96. for(int i = 0; i < 100; i++)
  97. {
  98. sumTotal += (shoppingCart[i].quantity)*(shoppingcart[i].price);
  99.  
  100. while(shoppingCart[i].name != " ");
  101. }
  102.  
  103.  
  104.  
  105. cout << "Your total is: $" << sumTotal << " for items currently in your cart.\n";
  106.  
  107. return;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement