Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.59 KB | None | 0 0
  1. //main.cpp file
  2.  
  3. #include"Problem1.h"
  4.  
  5. Item::Item()
  6. {
  7. title = "null";
  8. description = "null";
  9. price = 0.0;
  10. }
  11. Item::Item(std::string passTitle, std::string passDescription, double passPrice)
  12. {
  13. title = passTitle;
  14. description = passDescription;
  15. price = passPrice;
  16. }
  17. std::string Item::getTitle()
  18. {
  19. return title;
  20. }
  21. std::string Item::getDescription()
  22. {
  23. return description;
  24. }
  25. double Item::getPrice()
  26. {
  27. return price;
  28. }
  29. void Item::setTitle(std::string x)
  30. {
  31. title = x;
  32. }
  33. void Item::setDescription(std::string x)
  34. {
  35. description = x;
  36. }
  37. void Item::setPrice(double x)
  38. {
  39. price = x;
  40. }
  41.  
  42. Book::Book()
  43. {
  44. title = "null";
  45. description = "null";
  46. price = 0.0;
  47. pageCount = 0;
  48. }
  49. Book::Book(std::string passTitle, std::string passDescription, double passPrice, int passPageCount)
  50. {
  51. title = passTitle;
  52. description = passDescription;
  53. price = passPrice;
  54. pageCount = passPageCount;
  55. }
  56. int Book::getPageCount()
  57. {
  58. return pageCount;
  59. }
  60. void Book::setPagecount(int x)
  61. {
  62. pageCount = x;
  63. }
  64. void Book::print()
  65. {
  66. std::cout << "Book: " << title << " Price: $" << std::setprecision(2) << std::fixed << price << " " << description << " Pages: " << pageCount << std::endl;
  67. }
  68.  
  69. Movie::Movie()
  70. {
  71. title = "null";
  72. description = "null";
  73. price = 0.0;
  74. length = 0;
  75. }
  76. Movie::Movie(std::string passTitle, std::string passDescription, double passPrice, int passLength)
  77. {
  78. title = passTitle;
  79. description = passDescription;
  80. price = passPrice;
  81. length = passLength;
  82. }
  83. int Movie::getLength()
  84. {
  85. return length;
  86. }
  87. void Movie::setLength(int x)
  88. {
  89. length = x;
  90. }
  91. void Movie::print()
  92. {
  93. std::cout << "Movie: " << title << " Price: $" << std::setprecision(2) << std::fixed << price << " " << description << " Length: " << length << " minutes" << std::endl;
  94. }
  95.  
  96. CD::CD()
  97. {
  98. title = "null";
  99. description = "null";
  100. price = 0.0;
  101. trackCount = 0;
  102. }
  103. CD::CD(std::string passTitle, std::string passDescription, double passPrice, int passTrackCount)
  104. {
  105. title = passTitle;
  106. description = passDescription;
  107. price = passPrice;
  108. trackCount = passTrackCount;
  109. }
  110. int CD::getTrackCount()
  111. {
  112. return trackCount;
  113. }
  114. void CD::setTrackCount(int x)
  115. {
  116. trackCount = x;
  117. }
  118. void CD::print()
  119. {
  120. std::cout << "CD: " << title << " Price: $" << std::setprecision(2) << std::fixed << price << " " << description << " Track Count: " << trackCount << std::endl;
  121. }
  122.  
  123. ShoppingCart::ShoppingCart(int x)
  124. {
  125. numItemsInCart = x;
  126. Item ** itemArray = new Item*[numItemsInCart];
  127. }
  128. ShoppingCart::ShoppingCart()
  129. {
  130. numItemsInCart = 1;
  131. Item ** itemArray = new Item*[numItemsInCart];
  132. }
  133. ShoppingCart::~ShoppingCart()
  134. {
  135. delete []itemArray;
  136. }
  137. void ShoppingCart::addItems()
  138. {
  139. int iterator = 0;
  140. int userChoice = -1;
  141. while (iterator < numItemsInCart)
  142. {
  143. std::cout << "Enter 1 to add a book, 2 to add a movie, or 3 to add a CD: ";
  144. std::cin >> userChoice;
  145. std::string userEnteredTitle, userEnteredDescription;
  146. double userEnteredPrice;
  147. std::cout << "Please Enter a title: ";
  148. std::getline(std::cin, userEnteredTitle);
  149. std::cout << "Please Enter a description: ";
  150. std::getline(std::cin, userEnteredDescription);
  151. std::cout << "Please Enter a price: ";
  152. std::cin >> userEnteredPrice;
  153. if (userChoice == 1)
  154. {
  155. int UserEnteredPageCount;
  156. std::cout<<"Please Enter a page count: ";
  157. std::cin >> UserEnteredPageCount;
  158. itemArray[iterator] = new Book(userEnteredTitle, userEnteredDescription, userEnteredPrice, UserEnteredPageCount);
  159. iterator++;
  160. }
  161. else if (userChoice == 2)
  162. {
  163. int movieLength;
  164. std::cout << "Please Enter movie length: ";
  165. std::cin >> movieLength;
  166. itemArray[iterator] = new Movie(userEnteredTitle, userEnteredDescription, userEnteredPrice, movieLength);
  167. iterator++;
  168. }
  169. else if (userChoice == 3)
  170. {
  171. int userEnteredTrackCount;
  172. std::cout << "Please Enter the number of tracks: ";
  173. std::cin >> userEnteredTrackCount;
  174. itemArray[iterator] = new CD(userEnteredTitle, userEnteredDescription, userEnteredPrice, userEnteredTrackCount);
  175. iterator++;
  176. }
  177. else
  178. {
  179. std::cout << "Please Enter a valid choice, either 1, 2, or 3" << std::endl;
  180. }
  181. }
  182.  
  183. }
  184. void ShoppingCart::printItems()
  185. {
  186. //to be added
  187. }
  188.  
  189. Customer::Customer()
  190. {
  191. userID = 0000;
  192. firstName = "null";
  193. lastName = "null";
  194. customerShoppingCart = new ShoppingCart(1);
  195. }
  196. Customer::Customer(std::string uFirstName, std::string uLastName, int numItems)
  197. {
  198. firstName = uFirstName;
  199. lastName = uLastName;
  200. customerShoppingCart = new ShoppingCart[numItems];
  201. }
  202. Customer::~Customer()
  203. {
  204. delete customerShoppingCart;
  205. }
  206.  
  207. int main()
  208. {
  209.  
  210. system("pause");
  211. return 0;
  212. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement