Answer to Question #214003 in C++ for Rafaih

Question #214003

Consider the following inheritance hierarchy: (4) class A{ protected: int x, y; public: int z; }; class B: private A{ private: int a, b, c; public: }; Int main(){ Aobja; void set(int x, int y, int z, int a, int b, int c); B objb; } a) How many data members does B have? Write their names. b) How many of B’s data members are visible in B? Write down their names. c) Which members of B are accessible in main()? How will they be accessed? d) If the protected Access specifier in A is changed to public, then how many members of B will be accessed in main() and how? e) Define the function set() without changing its signature as given above. f) Write a default constructor for the class B that does not have an empty parameter list. g) If the data members of A become private, then how they be initialized? h) Add a static data member in class B. Can we use this pointer with static members? If yes how?


1
Expert's answer
2021-07-05T13:29:45-0400

a) B has four data members, that is, a, b, c, and z from the class A.

b) B data members visible in B are four: a,b,c, and z.

c) None

d) None


#include <iostream>


using namespace std;


class A{ 
    protected: 
        int x, y; 
    public: int z; 
    
};


class B: private A{ 
    private: 
        int a, b, c; 
    public: 
        B(int m,int n,int r){
            a=m;
            b=n;
            c=r;
        }
};
void set(int x, int y, int z, int a, int b, int c){
    x=3;
    y=7;
    z=5;
    a=32;
    b=53;
    c=43;
}
int main(){ 
    //Aobja; 
    void set(int x, int y, int z, int a, int b, int c); 
    B objb; 
    
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS