Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Checkpoint 15.14 (page 951) #include using namespace std; class First { protected: int a; public: First(int x = 1) { a = x; } virtual

Checkpoint 15.14 (page 951)

#include using namespace std;

class First

{

protected: int a;

public:

First(int x = 1) { a = x; } virtual void twist() { a *= 2; } int getVal() { twist(); return a; }

}; class Second : public First

{

private: int b;

public: Second(int y = 5) { b = y; } virtual void twist() { b *= 10; }

};

1. int main()

2. {

3. First object1;

4. Second object2;

5.

6. cout << object1.getVal() << endl;

7. cout << object2.getVal() << endl;

8. return 0;

9. }

a) What is the output of this program?

b) At line 5, what are the member variable(s) of object1? What are their value(s)?

c) At line 5, what are the member variable(s) of object2? What are their value(s)?

d) At line6, which twist() function is called, First::twist() or Second::twist()?

e) At line6, which twist() function is called, First::twist() or Second::twist()?

Checkpoint 15.15 (page 952)

#include using namespace std; class Base

{

protected: int baseVar;

public: Base(int val = 2) { baseVar = val; } int getVar() { return baseVar; }

};

class Derived : public Base

{

private: int derivedVar; public: Derived(int val = 100) { derivedVar = val; } int getVar() { return derivedVar; }

};

int main()

{ Base *optr = nullptr; Derived object; optr = &object; cout << optr->getVar() << endl; return 0;

}

a) What is the output of this program?

b) What does this program demonstrate?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Explain the nature of human resource management.

Answered: 1 week ago

Question

Write a note on Quality circles.

Answered: 1 week ago