Advertisement
Guest User

p order. pizza cpp

a guest
Apr 25th, 2019
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. #include <iostream>
  2. #include "pizza.h"
  3.  
  4. using namespace std;
  5.  
  6. //========================
  7. // Pizza
  8. // The constructor sets the default pizza
  9. // to a small, deep dish, with only cheese.
  10. //========================
  11. Pizza::Pizza()
  12. {
  13. size = SMALL;
  14. type = DEEPDISH;
  15. pepperoniToppings = 0;
  16. cheeseToppings = 1;
  17. }
  18.  
  19.  
  20. //==================================
  21. // Accessors and Mutators Follow
  22. //==================================
  23.  
  24. // --------------------------------
  25. // ----- ENTER YOUR CODE HERE -----
  26. // --------------------------------
  27.  
  28. int Pizza::getPepperoniToppings()
  29. {
  30. return pepperoniToppings;
  31. }
  32.  
  33. void Pizza::setPepperoniToppings(int numPepperoni)
  34. {
  35. pepperoniToppings = numPepperoni;
  36. }
  37.  
  38. int Pizza::getCheeseToppings()
  39. {
  40. return cheeseToppings;
  41. }
  42.  
  43. void Pizza::setCheeseToppings(int numCheese)
  44. {
  45. cheeseToppings = numCheese;
  46. }
  47.  
  48. int Pizza::getSize()
  49. {
  50. return size;
  51. }
  52.  
  53. void Pizza::setSize(int newSize)
  54. {
  55. size = newSize;
  56. }
  57.  
  58. int Pizza::getType()
  59. {
  60. return size;
  61. }
  62.  
  63. void Pizza::setType(int newType)
  64. {
  65. type = newType;
  66. }
  67.  
  68. //==================================
  69. // outputDescription
  70. // Prints a textual description of the contents of the pizza.
  71. //==================================
  72. void Pizza::outputDescription()
  73. {
  74. cout << "This pizza is: ";
  75. switch (size)
  76. {
  77. case SMALL: cout << "Small, ";
  78. break;
  79. case MEDIUM: cout << "Medium, ";
  80. break;
  81. case LARGE: cout << "Large, ";
  82. break;
  83. default: cout << "Unknown size, ";
  84. }
  85. switch (type)
  86. {
  87. case DEEPDISH: cout << "Deep dish, ";
  88. break;
  89. case HANDTOSSED: cout << "Hand tossed, ";
  90. break;
  91. case PAN: cout << "Pan, ";
  92. break;
  93. default: cout << "Uknown type, ";
  94. }
  95. cout << "with " << pepperoniToppings << " pepperoni toppings " <<
  96. "and " << cheeseToppings << " cheese toppings." << endl;
  97. }
  98.  
  99. //==================================
  100. // computePrice
  101. // Returns:
  102. // Price of a pizza using the formula:
  103. // Small = $10 + $2 per topping
  104. // Medium = $14 + $2 per topping
  105. // Large = $17 + $2 per topping
  106. //==================================
  107. double Pizza::computePrice()
  108. {
  109. double price = 0;
  110. switch (size)
  111. {
  112. case SMALL: price = 10; break;
  113. case MEDIUM: price = 14; break;
  114. case LARGE: price = 17; break;
  115. default: cout << "Error, invalid size." << endl;
  116. return -1;
  117. }
  118. price += (pepperoniToppings + cheeseToppings) * 2;
  119. return price;
  120. }
  121.  
  122. // --------------------------------
  123. // --------- END USER CODE --------
  124. // --------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement