0% found this document useful (0 votes)
24 views14 pages

Oops 6 8 9 Sudha

The document contains multiple C++ programs demonstrating various concepts of operator overloading and inheritance. It includes examples of unary and binary operator overloading, virtual inheritance, multiple inheritance, hybrid inheritance, and hierarchical inheritance. Each program is accompanied by a brief explanation and expected output.

Uploaded by

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

Oops 6 8 9 Sudha

The document contains multiple C++ programs demonstrating various concepts of operator overloading and inheritance. It includes examples of unary and binary operator overloading, virtual inheritance, multiple inheritance, hybrid inheritance, and hierarchical inheritance. Each program is accompanied by a brief explanation and expected output.

Uploaded by

pranav jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

PROGRAM- 6

6.(a) WAP to demonstrate unary operator overloading.

#include<iostream>

using namespace std;

class num

private:

int a,b,c,d;

public:

num(int j,int k,int m,int l)

a=j;

b=k;

c=m;

d=l;

void show(void);

void operator++();

};

void num:: show()

cout<<a<<"\n"<<b<<"\n"<<c<<"\n"<<d;

}
void num::operator ++()

++a;++b;++c;++d;

int main()

num X(3,2,5,7);

cout<<"\n before imcrement:";

X.show();

++X;

cout<<"\n after increment:";

X.show();

return 0;

OUTPUT
(b).Write a program to demonstrate binary operator.

#include<iostream>

using namespace std;

class number

public:

int x;

int y;

number() {}

number (int j,int k)

x=j;

y=k;

number operator +( number D)

number T;

T.x=x+D.x;

T.y=y+D.y;

return T;

void show()
{

cout<<x<<"\n"<<y;

};

int main()

number a(2,3),b(4,5),c;

a.show();

b.show();

c=a+b;

c.show();

OUTPUT
PROGRAM-9

9.WAP to demonstrate the use of virtual keyboard.

#include<iostream>

using namespace std;

class A1

protected:

int a1;

};

class A2: public virtual A1

protected:

int a2;

};

class A3: public virtual A1

protected:

int a3;

};

class A4: public A2,A3

int a4;

public:
void get()

cout<<"enter value of a1,a2,a3 and a4:";

cin>>a1>>a2>>a3>>a4;

void put()

cout<<"a1="<<a1<<"a2="<<a2<<"a3="<<a3<<"a4="<<a4;

};

int main()

A4 a;

a.get();

a.put();

OUTPUT
PROGRAM-8

8. WAP to understand the concept of various inheritance.

8(a). WAP to demonstrate multiple inheritance.

#include<iostream>

using namespace std;

class A

protected:

int a;

};

class B

protected:

int b;

};

class C

protected:

int c;

};

class D

protected:
int d;

};

class E: public A,B,C,D

int e;

public:

void getdata()

cout<<"enter a,b,c,d,e ";

cin>>a>>b>>c>>d>>e;

void show()

cout<<a<<b<<c<<d<<e;

}};

int main()

E x;

x.getdata();

x.show();

}
OUTPUT
8(b).WAP to demonstrate hybrid inheritance.

#include<iostream>

using namespace std;

class aa {

protected:

int a, a1;

};

class bb : public aa {

protected:

int b;

public:

void show() {

cout << "Enter value of a and b: ";

cin >> a >> b;

};

class cc : public aa {

protected:

int c;
public:

void show2() {

cout << "Enter values of a1 and c: ";

cin >> a1 >> c;

};

int main() {

bb ob1;

ob1.show();

cc ob2;

ob2.show2();

return 0;

OUTPUT
8(c). WAP to show hierarchical inheritance.

#include<iostream>

using namespace std;

class Red {

public:

Red() {

cout << "Red";

};

class Yellow {

public:

Yellow() {

cout << " Yellow";

};

class Blue {

public:

Blue() {

cout << "Blue";

};
class Orange : public Red, public Yellow {

public:

Orange() {

cout << "=orange";

};

class Green : public Blue, public Yellow {

public:

Green() {

cout << " =green";

};

class Violet {

public:

Violet() {

cout << "=violet";

};

int main() {

Violet v;

endl(cout);
Green g;

endl(cout);

Orange o;

endl(cout);

return 0;

OUTPUT

You might also like