Computer Science, asked by fardinrocky, 6 months ago

Write a C++ program that can calculate the product of three decimal numbers using multiple inheritance.

Answers

Answered by sgtg011
1

Answer:

why should I write its ur work do it ur aelf

Answered by CEOSanjay
0

Answer:

C++ Multiple Inheritance Syntax

class A

{

..........

};

class B

{

...........

} ;

class C : acess_specifier A,access_specifier A // derived class from A and B

{

...........

} ;

C++ Multiple Inheritance Example

Here is a simple example illustrating the concept of C++ multiple inheritance.

// multiple inheritance.cpp

#include

using namespace std;

class A

{

public:

int x;

void getx()

{

cout << "enter value of x: "; cin >> x;

}

};

class B

{

public:

int y;

void gety()

{

cout << "enter value of y: "; cin >> y;

}

};

class C : public A, public B //C is derived from class A and class B

{

public:

void sum()

{

cout << "Sum = " << x + y;

}

};

int main()

{

C obj1; //object of derived class C

obj1.getx();

obj1.gety();

obj1.sum();

return 0;

} //end of program

Output

enter value of x: 5

enter value of y: 4

Sum = 9

Explanation

In the above program, there are two base class A and B from which class C is inherited. Therefore, derived class C inherits all the public members of A and B and retains their visibility. Here, we have created the object obj1 of derived class C.

Similar questions