Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Checkpoint 15.4 (page 917). Trace the program and answer following questions. #i

ID: 3887237 • Letter: C

Question

Checkpoint 15.4 (page 917). Trace the program and answer following questions.

#include <iostream>
using namespace std;

class Sky

{

public:
    Sky()
       { cout << "Entering the sky. "; }
    ~Sky()
       { cout << "Leaving the sky. "; }

};

class Ground : public Sky

{

public:
    Ground()
       { cout << "Entering the Ground. "; }
    ~Ground()
       { cout << "Leaving the Ground. "; }

};

int main()

{
    Ground object;
    return 0;

}

a. What is the output of the program?

b. Which is base class? Which is derived class?

c. Are constructors executed? Which constructor is called, and in what order are they executed?

d. Are destructors executed? Which destructor is called, and in what order are they executed?

Checkpoint 15.8 (page 918). Trace the program and answer following questions.

#include <iostream>
using namespace std;

class Sky

{

public:
    Sky()
       { cout << "Entering the sky. "; }
    Sky(string color)
       { cout << "The sky is " << color << endl; }
    ~Sky()
       { cout << "Leaving the sky. "; }

};
class Ground : public Sky

{

public:
    Ground()
       { cout << "Entering the Ground. "; }
    Ground(string c1, string c2) : Sky(c1)
       { cout << "The ground is " << c2 << endl; }
    ~Ground()
       { cout << "Leaving the Ground. "; }

};

int main()

{
    Ground object;
   return 0;

}     

a. What is the output of this program?

b. Which is base class? Which is derived class?

c. Are constructors executed? Which constructor is called, and in what order are they executed?

d. Are destructors executed? Which destructor is called, and in what order are they executed?

Explanation / Answer

a)What is the output of the program?
The ooutput of above program is that:
Entering the sky.
Entering the Ground.
Leaving the Ground.
Leaving the sky.

b. Which is base class? Which is derived class?
In thhe given program, base class is --> Sky()
derived class---> Ground()
The syntax for derived class is that:
class derived-class: access-specifier base-class

c. Are constructors executed? Which constructor is called, and in what order are they executed?
No.

d.Are destructors executed? Which destructor is called, and in what order are they executed?
Ans: yes, ~Sky() is destructed first, hence "Leaving the Ground" was printed first.

a) The ooutput of above program is that:
Entering the sky.
Entering the Ground.
Leaving the Ground.
Leaving the sky.

b)In thhe given program, base class is --> Sky()
derived class---> Ground()
The syntax for derived class is that:
class derived-class: access-specifier base-class


c) yes, Sky(string color) is executed first and after that Ground(string c1, string c2) : Sky(c1) is executed.

d) yes, ~Sky() is destructed first, hence "Leaving the Ground" was printed first.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote