Saturday, January 25, 2014

C++ Program to Implement the Concept of Multiple Inheritance

with 0 Comment
MULTIPLE INHERITANCE
AIM:
  • To write a C++ program to implement the concept of multiple inheritance.
ALGORITHM:
1. Start the program
2. Include the suitable header file
3. create a base class M and N
4. Declare a variable m and void getm function in class M
5. Declare a variable n and void getn function in class N
6. Derive a class P from the base class M&N and declare a function void display
7. Define the function void getm ,void getn and void display outside their respective class
8. Get the value for the variable in getm and getn function
9. Call the display function for displaying the output
10. Stop the program

CODING:
#include<iostream.h>
class M
{
protected:
int m;
public:
void getm(int);
};
class N
{
protected:
int n;
public:
void getn(int);
};
class P:public M,public N
{
public:
void display(void);
};
void M::getm(int x)
{
m=x;
}
void N::getn(int y)
{
n=y;
}
void P::display(void)
{
cout<<"m="<<m<<"\n";
cout<<"n="<<n<<"\n";
cout<<"m*n="<<m*n<<"\n";
}
int main()
{
P p;
p.getm(10);
p.getn(20);
p.display();
return 0;
}

OUTPUT:
m=10
n=20
m*n=200

RESULT:
  • Thus to write a c++ program for multiple inheritance was successfully completed.

0 comments:

Post a Comment

Powered by Blogger.

Blog Archive