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

Checkpoint 15.12 (page 950) #include <iostream.> using namespace std; class Firs

ID: 3887228 • Letter: C

Question

Checkpoint 15.12 (page 950)

#include <iostream.>
using namespace std;

class First

{

protected:
    int a;

public:
    First(int x = 1)
       { a = x; }

int getVal()
       { return a; }

};

class Second : public First

{

private:
    int b;
public:
    Second(int y = 5)
       { b = y; }
    int getVal()
       { return b; }

};

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 getVal() function is called, First::getVal() or Second::getVal()?

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

Checkpoint 15.13 (Page 950)

#include <iostream>
using namespace std;

class First

{

protected:
    int a;

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

};

class Second : public First

{

private:
    int b;

public:
    Second(int y = 5)
       { b = y; }
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()?

Explanation / Answer

CHEGG POLICY: ONLY ONE QUESTION PER POST IS ALLOWED , PLEASE ABIDE BY THE POLICY,

Post your next questions accordingly

15.12) a) Output of the program

1

5

b) the member variable of object1 is a and it's value is 1

c) the member variable of object2 is b and it's value is 5

d) At line 6, First::getVal() gets called

e) At line 7,Second::getVal() gets called

PLEASE RATE !!

Thanks !

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