9.14. Coding Practice

Write the Cake structure, which has instance variables name, color, diameter, and has_icing.

Below is one way to implement the program. We declare the Cake struct and list the instance variables in order.

Write the function printCakeInfo, which prints the cake’s information in the format “This is a color, diameter inch diameter cake with/without icing.” If name does not have the value “n/a”, printCakeInfo prints out “Happy birthdday name! Your cake is color, has a diameter inch diameter, and comes with/without icing.”

Write the makeCake function, which prompts the user for a name, color, diameter, and whether or not they want icing. The function then returns the cake.

Below is one way to implement the program. We create a Cake for the user, read in the user’s input using cin, and return the Cake.

Write the function changeCakeDiameter, which takes a Cake and a double as a parameter. changeCakeDiameter then multiplies the original diameter by the double and modifies the cake to have this new diameter.

Write the editCake function, which prompts the user for a new name, color, diameter, and whether or not they want icing. The function modifies the original cake that is passed in as a parameter. Use the makeCake function in your implementation to avoid duplicate code!

Below is one way to implement the program. We call makeCake in editCake and then set the original cake equal to the new one.

Write the struct Shirt, which has the instance variables color and size.

Write the Pants structure, which has instance variables size and material.

Below is one way to implement the program. We declare the Pants struct and list the instance variables in order.

Write the struct Outfit, which is a nested structure that has a Shirt, Pants, and has_hat.

Write the printOutfit function, which prints out details of the outfit. The output below should be “Shirt: blue and L; Pants: S and denim; has hat”.

Below is one way to implement the program.

Write the changeShirts and changePants functions, which both take an Outfit as a parameter. changeShirts also takes a Shirt as a parameter and changePants also takes a Pants as a parameter. Each function modifies the Outfit and changes the shirt or pants to the new input.

If you did Q9, then feel free to copy the printOutfit function from there into this program.

You have attempted of activities on this page