Answer the following true/false questions using the following code. And state why it is true or false . Code fragment 1: void light_candle(Candle &c) { if(match){ cout << "~~Lighting candle indoors~~"<
Answer the following true/false questions using the following code. And state why it is true or false .
Code fragment 1:
void light_candle(Candle &c)
{ if(match){
cout << "~~Lighting candle indoors~~"<<endl; c.on_off=true;
match=false;
} else{
cout <<"You don't have a match."<<endl; }
}
void light_candle(bool weather, Candle &c)
{
if(weather&&match) {
cout << "~~Lighting candle outdoors~~"<<endl; c.on_off=true;
match=false;
}
else{
cout << "Too hot to light candle."<<endl; }
}
-
We can tell for certain what type of variable match is.
-
We can tell that on_off is a function in the Candle class.
-
light_candle is an overridden function.
-
If we have a Candle object called can1, can1.match would be valid line of code.
5. We see two examples of polymorphism in this given code.
-
We can assume on_off will always have the value true when light_candle is called since we are passing in by reference.
-
We can assume that match is in the Candle class.
-
r.light_candle(true, can1); would be a possible valid line of code.
-
light_candle(true, can1); would be a possible valid line of code.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps