Jimmy’s Pizza Pie shop serves a variety of pizza types, sizes and toppings. Jimm
ID: 3675659 • Letter: J
Question
Jimmy’s Pizza Pie shop serves a variety of pizza types, sizes and toppings. Jimmy needs a program to quickly calculate the price of a pizza that has been ordered. You will use a Pizza object in the coding of this application.
Pizza class
The following UML diagram describes members of this class:
Pizza
- crusttype:char // stores P,D or H to indicate pan, deep dish or hand tossed crust
- size: char // stores S, M or L to indicate small, medium or large pizza
- pepperoni: int // stores number of pepperoni toppings for this pizza
- onlonPepper:int // stores number of onion& pepper toppings for this pizza
- cheese: bool // indicates if there is cheese on this pizza, default is True
+ Pizza( )
+ Pizza( char ctype)
+ Pizza( char ctype, char size)
+ Pizza( bool cheeseOpt, char size = ‘M’);
+ void setCrust(char ctype)
+ void setSize(char size)
+void setCheese()
+ void setPepperoni(int quantity)
+ void setOP(int quantity)
+ char getCrust() const
+ char getSize( ) const
+ void resetToppings()
+ void noCh()
+ double calcCost( ) const
- int totalToppings() const // note that this function is Private
+ void printToppings(ostream& out) const // prints toppings only
+ void printPizzaStats(ostream& out) const // prints crust, size, cheese, toppings
The Pizza constructor is overloaded, so that an application which is creating a new Pizza object can do so without all info initially available.
Any constructor which does is not provided with all data must use default values for the missing data. Defaults to be used:
Crusttype => ‘P’
Size => ‘M’
Pepperoni => 0
0
Cheese => true
The set and get functions either set or return the value of the indicated member variable. The resetToppings function should reset ALL topping to their default, including Cheese. The noCh() function should set the Cheese to false.
The function calcCost returns the current cost of the pizza. The pricing is as follows:
Pan crust : small 5 med 8 large 10
Deep crust: small 6 med 9 large 11
Hand tossed : small 7 med 10 large 12
Toppings: $ 2 each There is no change in cost if cheese is not included.
totalToppings returns the total number of toppings (cheese is not counted).
The print functions output the indicated information to the ostream object ‘out’.
The Application
Your application should:
ask the user for a crust and size
create a Pizza
ask the user for topping info (how much pepperoni, onionPepper, cheese)
print out the toppings which have been ordered
ask the user if he/she wishes to change any toppings
make changes if required
print the final PIZZA stats and cost
Pizza
- crusttype:char // stores P,D or H to indicate pan, deep dish or hand tossed crust
- size: char // stores S, M or L to indicate small, medium or large pizza
- pepperoni: int // stores number of pepperoni toppings for this pizza
- onlonPepper:int // stores number of onion& pepper toppings for this pizza
- cheese: bool // indicates if there is cheese on this pizza, default is True
+ Pizza( )
+ Pizza( char ctype)
+ Pizza( char ctype, char size)
+ Pizza( bool cheeseOpt, char size = ‘M’);
+ void setCrust(char ctype)
+ void setSize(char size)
+void setCheese()
+ void setPepperoni(int quantity)
+ void setOP(int quantity)
+ char getCrust() const
+ char getSize( ) const
+ void resetToppings()
+ void noCh()
+ double calcCost( ) const
- int totalToppings() const // note that this function is Private
+ void printToppings(ostream& out) const // prints toppings only
+ void printPizzaStats(ostream& out) const // prints crust, size, cheese, toppings
Explanation / Answer
Public Class Form1 Private Sub BtnCalc_Click(sender As System.Object, e As System.EventArgs) Handles BtnCalc.Click calculate() End Sub Private Sub calculate() Dim j As Integer Dim cost As Double Dim order As String = "" 'will say small, medium, or large Dim toppings As String = "" 'will contain list of toppings Dim crust As String = "" 'will say thin or thick 'Because the tag has the price, we can use the tag for the selected size as the base cost If RadSmall.Checked Then cost = RadSmall.Tag 'base price for a small pizza order = "small" ElseIf RadMedium.Checked Then cost = RadMedium.Tag 'base price for a medium pizza order = "medium" Else cost = RadLarge.Tag order = "large" 'base price for a large pizza End If If RadThick.Checked Then crust = " thick crust" Else crust = " thin crust" End If If ChkCheese.Checked Then cost += ChkCheese.Tag 'add cost of extra cheese cost += Me.CheckBoxToppings.CheckedItems.Count 'add $1 per topping or * cost per topping 'loop through all of the selected toppings to make list of toppings For j = 0 To Me.CheckBoxToppings.CheckedItems.Count - 1 toppings += CheckBoxToppings.CheckedItems.Item(j) & " " 'space between Next 'Notice how the display is built one phrase at a time Dim display As String = "You ordered a " & order & crust & " pizza" If ChkCheese.Checked Then display += " with extra cheese" If CheckBoxToppings.CheckedItems.Count = 1 Then display += " and 1 topping: " & toppings End If If CheckBoxToppings.CheckedItems.Count > 1 Then display += " and " & CheckBoxToppings.CheckedItems.Count & " toppings: " & toppings End If Me.RichTextBox1.Text = display 'chr(13) is the new line character. Me.RichTextBox1.AppendText(Chr(13) & "Your total is " & FormatCurrency(cost)) End Sub End Class
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.