1.
Write the
Cake structure, which has instance variables name, color, diameter, and has_icing.
Cake structure, which has instance variables name, color, diameter, and has_icing.
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 birthday name! Your cake is color, has a diameter inch diameter, and comes with/without icing.β Check the hint below for help with the construction of the code.
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 birthday name! Your cake is color, has a diameter inch diameter, and comes with/without icing.β Use the lines to construct the code, then go back to complete the Activecode.
makeCake function, which prompts the user for a name, color, diameter, and whether or not they want icing. The function then returns the cake.
Cake for the user, read in the userβs input using cin, and return the Cake.
#include <iostream>
using namespace std;
struct Cake {
string name;
string color;
double diameter;
bool has_icing;
};
void printCakeInfo(Cake c);
Cake makeCake() {
Cake input;
string name, color;
double diameter;
char icing;
cout << "Name: ";
cin >> name;
input.name = name;
cout << "Color: ";
cin >> color;
input.color = color;
cout << "Diameter: ";
cin >> diameter;
input.diameter = diameter;
cout << "Icing? (y/n) ";
cin >> icing;
if (icing == 'y') {
input.has_icing = true;
}
else {
input.has_icing = false;
}
return input;
}
int main() {
Cake input = makeCake();
printCakeInfo(input);
}
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. Check the hint below for help with the construction of the code.
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. Use the lines to construct the code, then go back to complete the Activecode.
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!
makeCake in editCake and then set the original cake equal to the new one.
#include <iostream>
using namespace std;
struct Cake {
string name;
string color;
double diameter;
bool has_icing;
};
void printCakeInfo(Cake c);
Cake makeCake();
void editCake(Cake& c) {
Cake newCake = makeCake();
c = newCake;
}
int main() {
Cake original = { "Oops", "orange", 185, true };
editCake(original);
printCakeInfo(original);
}
Pants structure, which has instance variables size and material.
Shirt, which has the instance variables color and size (in that order). Check the hint below for help with the construction of the code.
Outfit, which is a nested structure that has a Shirt, Pants, and has_hat (in that order). Check the hint below for help with the construction of the code.
printOutfit function, which prints out details of the outfit. The output below should be βShirt: blue and L; Pants: S and denim; has hatβ.
Cake struct and list the instance variables in order.
#include <iostream>
using namespace std;
struct Shirt {
string color;
char size;
};
struct Pants {
char size;
string material;
};
struct Outfit {
Shirt s;
Pants p;
bool has_hat;
}
void printOutfit(Outfit o) {
"Shirt: blue and L; Pants: S and denim; has hat"
cout << "Shirt: " << o.s.color << " and " << o.s.size << "; Pants:" << o.p.size << " and " << o.p.material << "; ";
if (o.has_hat) {
cout << "has hat" << endl;
}
else {
cout << "does not have hat" << endl;
}
}
int main() {
Shirt t = { "blue", 'L' };
Pants p = { 'S', "denim" };
Outfit o = { t, p, true };
printOutfit(o);
}
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. Check the hint below for help with the construction of the code.
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. Use the lines to construct the code, then go back to complete the Activecode.