1.
Write the
Cake structure, which has instance variables name, weight and member function has_icing function that returns a bool. Use the Cake object initialised below to invoke the has_icing function.
#include <iostream>
using namespace std;
// Write your code for the struct Cake here.
int main() {
Cake c = { "Choco lava", 3.5};
// Write your code to invoke the has_icing function here
}
Solution.
Below is one way to implement the program. We declare the
Cake struct and list the instance variables in order.
#include <iostream>
using namespace std;
struct Cake {
string name;
double weight;
bool has_icing;
};
int main() {
Cake c = { "Choco lava", 3.5};
cout << c.has_icing() << endl;
}
