write a program in multilevel
Answers
PLEASE MARK BRAINLIST
C++ multilevel inheritance program
Output:
Enter value of a = 15
Enter value of b = 10
Enter value of c = 25
Product = 3750
Explanation:
The following are the program in the C++ programming language.
//set header file
#include <iostream>
//using namespace
using namespace std;
//define base class
class base //define base class
{
//set public access modifier
public:
//declare variable
int a;
//define a method
void getd()
{
//get input from the user
cout << "Enter value of a = ";
cin >> a;
}
};
class derived : public base // define derived class from base class
{
//set public access modifier
public:
//declare variable
int b;
//define a method
void read()
{
//get input from the user
cout << "\nEnter value of b = ";
cin >> b;
}
};
class derived2 : public derived //define derived from class derived
{
//set private access modifier
private:
//declare variable
int c;
//set public access modifier
public:
//define a method
void indata()
{
//get input from the user
cout << "\nEnter value of c = ";
cin >> c;
}
//define a method
void product()
{
//perform and print the product
cout << "\nProduct = " << a * b * c;
}
};
//define a main method
int main()
{
//create the class object
derived2 obj;
//call all methods through derived class object
obj.getd();
obj.read();
obj.indata();
obj.product();
return 0;
}
The following are the program that shows the multilevel inheritance in which we assume there are three class the second class inherit the property of the first class and the third class inherit the property of the second class, also the second is the base or super class for the third one.
So, according to the following scenario the following program is the multilevel inheritance.
Learn More:
https://brainly.in/question/11842669