Starting from:

$35

Homework 2 Solution


The goal of this homework is to help you to learn the accessibility of public, protected, and private specifier by designing multiple classes that demonstrate the accessibility of different information hiding levels.


Your programs should satisfy the following 7 requirements:

    1. Show for public inheritance, for the public data and functions in the base class, they can be accessed by the derived class, and also they can be accessed like public data and functions of the derived class by both the clients of the derived class and further derived classes.

    2. Show for public inheritance, for protected data and functions in the base class, they can be accessed by the derived class, and they can also be accessed like protected data and functions of the derived class by further derived classes.

    3. Show for public inheritance, for private data and functions in the base class, they cannot be accessed by the derived class.

    4. Show for protected inheritance, for public and protected data and functions in the base class, they can be accessed by the derived class, and also they can be accessed like protected data and functions of the derived class by further derived classes.

    5. Show for protected inheritance, for private data and functions in the base class, they cannot be accessed by the derived class.

    6. Show for private inheritance, for public and protected data and functions in the base class, they can be accessed by the derived class, but they cannot be accessed by the clients of the derived class, and they cannot be accessed by further derived classes.

    7. Show for private inheritance, for private data and functions in the base class, they cannot be accessed by the derived class.

To show something cannot be accessed, you need to write the code that tries to access, compile your code, get the compilation error, and then comment off that line of code. Include the compilation error message in the commented code. Example:

//cout<<objC.publicDataInA<<endl; //error: 'int A::publicDataInA' is inaccessible



You need to write a Word document explaining in detail how your program demonstrates each of the above 7 points. You need to include screen shots of compilation errors. Example:









Due: January 15th, 11:59PM, 2019.

Turn in one file via handin: the zip file of two things: (1) your whole NetBean directory, (2) the word document explaining in detail how your program demonstrates each of the above 7 points. The name of your zip file should be: LastName_FirstName. For example, if your name is John Smith, you file name should be Smith_John.

More products