Lab 8
Lab 8
Consider the following access specifiers in C++: public, protected, and private. Fill in the
visibility table below to indicate whether the members of the base class are accessible in
the derived class based on the type of inheritance.
Private
Protected
Public
Requirements:
• In each derived class, attempt to access and call each of the base class's members
(public, protected, and private).
• Create instances of your derived classes in the main function to test member
visibility from outside the derived classes.
• Provide comments in your code explaining the expected visibility results for each
member type and any errors encountered.
o Create a base class A with an integer member data and a method display().
o Same as above, but make class C inherit from A with virtual inheritance.
You have a base class Shape that has a member function to calculate the area. You also have
two derived classes: Circle and Rectangle. Each derived class implements its own method to
calculate the area specific to its shape.
a) Write a program to demonstrate how you can access the member functions of the
Shape class using a base class pointer.
b) Show that you cannot access the specific member functions of the Circle and
Rectangle classes using the base class pointer.
c) Demonstrate how to access these specific member functions using derived class
pointers.
class Base {
public:
// Virtual function in the base class
virtual ReturnType FunctionName(ParameterType1 param1, ParameterType2
param2) {
// Base class implementation
}
};