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~~"<

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter8: Arrays And Strings
Section: Chapter Questions
Problem 10PE
icon
Related questions
Question

 

 

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; }

}

  1. We can tell for certain what type of variable match is.

  2. We can tell that on_off is a function in the Candle class.

  3. light_candle is an overridden function.

  4. 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.

  1. We can assume on_off will always have the value true when light_candle is called since we are passing in by reference.

  2. We can assume that match is in the Candle class.

  3. r.light_candle(true, can1); would be a possible valid line of code.

  4. light_candle(true, can1); would be a possible valid line of code.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,