The program defines four classes, A, B, C, and D. Class A has a protected data member a and a public method get_a() that prompts the user to enter a value for a. Class B publicly inherits from A and has a protected data member b and a public method get_b() that prompts the user to enter a value for b. Class C has a protected data member c and a public method get_c() that prompts the user to enter a value for c.
Class D publicly inherits from both B and C and has a protected data member d. It also defines a public method mul() that calls the get_a(), get_b(), and get_c() methods to prompt the user for values for a, b, and c. It then calculates and prints the product of a, b, and c. In the main() function, an object of class D is created and its mul() method is called to perform the multiplication operation.
#include<iostream> using namespace std; class A { protected: int a; public: void get_a() { std::cout<<"Enter the value of 'a' : "<<std::endl; cin>>a; } }; class B : public A { protected: int b; public: void get_b() { std::cout<<"Enter the value of 'b' : "<<std::endl; cin>>b; } }; class C { protected: int c; public: void get_c() { std::cout<<"Enter the value of c is : "<<std::endl; cin>>c; } }; class D : public B, public C { protected: int d; public: void mul() { get_a(); get_b(); get_c(); std::cout<<"Multiplication of a,b,c is : "<<a*b*c<<std::endl; } }; int main() { D d; d.mul(); return 0; }To download raw file Click Here
Enter the value of 'a' : 20 Enter the value of 'b' : 30 Enter the value of c is : 20 Multiplication of a,b,c is : 12000
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions