Question: 1 . Create a Cake class with these attributes: Variables: type # an integer size # a character weight # a float name # a
Create a Cake class with these attributes:
Variables:
type# an integer
size# a character
weight# a float
name# a string, eg "Chocolate"
recipe # a dictionary
ingrdlist # a list
Requirements related to ingrdlist :
It should be a nesteddimensional list which includes: a sublist of the ingredient labels; a sublist of the ingredient weights, like this:
Flour "Sugar",
calcingrd has to be called from within init to build ingrdlist.
Then, when the objected is to be printed, upon calling str the sublist of ingredient labels will be iterated and each label can be used directly for printing. Hint: formulate the for loop header as something like this: for ingrdlabel, ingrdwt in zip ingrdlist ingrdlist :
Methods:
initselftype,size # for object instantiation; it should also set the values for weight and name
strself # returns cakestring as the textual listing of the ingredient weights; with this you Don't need the function printingrd as in Lab
calcingrdself weight, recipe # to be called from within init; it doesn't need to return anything but save values to the member variables directly.
Write test code to instantiate cake objects, one for each type and size total.
egmylrglemoncake CakeL# instantiate a cake object
printmylrglemoncake # test the str method
After printmylrglemoncake has been called, the ingredients list should be printed out in this format:
Ingredient Quantities for Large Lemon Cake
Sugar: Oz
Egg: Oz
Buttermilk: Oz
Vanilla Extract: Oz
Butter: Oz
Sifted Self Rising Flour: Oz
Filling Egg Yolk: Oz
Filling Sugar: Oz
Filling Butter: Oz
Filling Lemon Zest: Oz
You can remove the ordering interface part the sentinel while loop from Lab and just create and test individual cake objects as shown above. If we want to include the ordering interface, we need to create a composition class, Cakeorder, for a list of Cake objects. You can do your own research to find out how to do that, if you are interested; it is beyond the scope of this course; the code you need to write to test it will be more involved too.
You can use this block of test code for your program:
Create and print cake objects
regchocolatecake CakeR
lrgchocolatecake CakeL
regredvelvetcake CakeR
lrgredvelvetcake CakeL
reglemoncake CakeR
lrglemoncake CakeL
printregchocolatecake
printlrgchocolatecake
printregredvelvetcake
printlrgredvelvetcake
printreglemoncake
printlrglemoncake
Checkpoints:
Implement the Cake class with major attributes: member variables specified above, initselftype,sizestrself and calcingrdself weight, recipe
Define the recipe dictionaries either as global above the program or inside init
Write test code to createinstantiateconstruct different cake objects regular and large for chocolate, red velvet and lemon cakes. And, print them display the ingredient list tables.
Paste the record of execution and output data at the bottom of the source file.
All the Documentation Requirements stated in previous lab assignments still apply; eg doctrings for the file header and Class and all member functions.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
