0% found this document useful (0 votes)
2 views9 pages

PROGRAM1

The document contains multiple C++ programs demonstrating different types of inheritance: Multiple Inheritance, Hybrid Inheritance, and Hierarchical Inheritance. Each program includes class definitions, member functions for data input and output, and a main function to execute the code. Additionally, it features a program showcasing the use of virtual functions with a base and derived class.

Uploaded by

jitiyeb566
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views9 pages

PROGRAM1

The document contains multiple C++ programs demonstrating different types of inheritance: Multiple Inheritance, Hybrid Inheritance, and Hierarchical Inheritance. Each program includes class definitions, member functions for data input and output, and a main function to execute the code. Additionally, it features a program showcasing the use of virtual functions with a base and derived class.

Uploaded by

jitiyeb566
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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 –

You might also like