PROGRAM – 7
a) Write a program to demonstrate the use of Multiple Inheritance.
INPUT –
#include<iostream>
using namespace std;
class A {protected: int a;}; // class A declaration
class B {protected: int b;}; // class B declaration
class C {protected: int c;}; // class C declaration
class D {protected: int d;}; // class D declaration
// class E: public A, public B, public C, public D
class E: public A,B,C,D // Multiple derivation
int e;
public:
void getdata(){
cout<<"Enter values of a,b,c & d & e:";
cin>>a>>b>>c>>d>>e;
void showdata(){
cout<<"\nValues of variables are displayed below:";
cout<<"\na="<<a<<" b="<<b<<" c="<<c<<" d="<<d<<" e="<<e;
};
int main(){
E x;
[Link](); // Reads data
[Link](); // Display data
return 0;
OUTPUT –
b) Write a program to demonstrate the use of Hybrid Inheritance.
INPUT-
#include<iostream>
using namespace std;
class PLAYER {
protected:
char name[15];
char gender[15];
int age;
};
class PHYSIQUE : public PLAYER{
protected:
float height;
float weight;
};
class LOCATION{
protected:
char city[10];
char pin[7];
};
class GAME:public PHYSIQUE, LOCATION{
protected:
char game[15];
public:
void getdata()
{
cout<<"Enter Following Information\n";
cout<<"Name:";cin>>name;
cout<<"Gender:";cin>>gender;
cout<<"Age:";cin>>age;
cout<<"Height:";cin>>height;
cout<<"Weight:";cin>>weight;
cout<<"City:";cin>>city;
cout<<"Pincode:";cin>>pin;
cout<<"Game:";cin>>game;
void show()
cout<<"\nEntered Information is:";
cout<<"\nName:";cout<<name;
cout<<"\nGender:";cout<<gender;
cout<<"\nAge:";cout<<age;
cout<<"\nHeight:";cout<<height;
cout<<"\nWeight:";cout<<weight;
cout<<"\nCity:";cout<<city;
cout<<"\nPincode:";cout<<pin;
cout<<"\nGame:";cout<<game;
};
int main(){
GAME G;
[Link]();
[Link]();
return 0;
OUTPUT –
c) Write a program to demonstrate the use of Hierarchical Inheritance.
INPUT –
#include<iostream>
using namespace std;
class A //single base class
public:
int x, y;
void getdata(){
cout<<"\nEnter value of x and y:\n";cin>>x>>y;
};
class B: public A //B id derived from class here
public:
void product(){
cout<<"\nProduct of x and y = " <<x*y;
};
class C: public A //C is also derived from class base
public:
void sum(){
cout<<"\nSum="<<x+y;
};
int main(){
B obj1; //object of derived class B
C obj2; //object of derived class C
[Link]();
[Link]();
[Link]();
[Link]();
return 0;
OUTPUT –
PROGRAM – 8
a) Write a program to demonstrate the use of virtual keyboard.
INPUT –
#include<iostream>
using namespace std;
class first
int b;
public:
first()
b=10;
virtual void display() {
cout<<"\nVlaue of b = " <<b;
};
class second: public first
int d;
public:
second()
d=20;
}
void display()
cout<<"\nValue of d = "<<d;
};
int main(){
first f,*p;
second s;
p=&f;
p->display();
p=&s;
p->display();
return 0;
OUTPUT –