Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 16

OOPS PRACTICAL

Practical No-6 (A)

Aim :- overload the operator unary(-)for demonstrating operator overloading.

Program:-

#include <iostream>

using namespace std;

class unary

int x,y ;

public:

void get()

cout<<"enter 2 no:\n";

cin>>x>>y;

void operator -();

void show()

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

};

AKASH DINKAR BHOSALE


212414
Batch A1
OOPS PRACTICAL

void unary ::operator-()

x=-x;

y=-y;

int main()

unary ob;

ob.get();

-ob;

ob.show();

return 0;

Output:-

AKASH DINKAR BHOSALE


212414
Batch A1
OOPS PRACTICAL

Practical No-6(B)

Aim:-overload the operator+ for adding the time of two clocks,and also pass object
as an argument

Program:-

#include <iostream>

using namespace std;

class Time

int h,m,s;

public:

void get()

cout<<"Enter timing in hours,minutes and seconds:";

cin>>h>>m>>s;

void operator +(Time);

};

void Time::operator +(Time ob)

Time t3;

t3.s=s+ob.s;

t3.m=t3.s/60;
AKASH DINKAR BHOSALE
212414
Batch A1
OOPS PRACTICAL

t3.s=t3.s%60;

t3.m=t3.m+m+ob.m;

t3.h=t3.m/60;

t3.m=t3.m%60;

t3.h=t3.h+h+ob.h;

cout<<"h:"<<t3.h<<" m:"<<t3.m<<" s:"<<t3.s;

int main()

Time t1,t2;

t1.get();

t2.get();

t1+t2;

Output:-

AKASH DINKAR BHOSALE


212414
Batch A1
OOPS PRACTICAL

Practical No-6(C)

Aim:-overload the+for concatenating the two strings.foe e.g”py”+”thon”=python

Program:-

#include <iostream>

#include<string.h>

using namespace std;

class A

char s[20];

public:

void get()

cout<<"enter string:";

cin>>s;

void operator + (A);

};

void A::operator + (A ob)

cout<< strcat(s,ob.s);

AKASH DINKAR BHOSALE


212414
Batch A1
OOPS PRACTICAL

int main()

A s1,s2;

s1.get();

s2.get();

s1+s2;

Output:-

AKASH DINKAR BHOSALE


212414
Batch A1
OOPS PRACTICAL

Practical No-4(A)

Aim:- Design a class for single level inheritance using public and private type
derivation.

Program:-

#include<iostream>

using namespace std;

class square

public:

int x;

};

class A:public square

public:

void input ()

cout<< "Enter a number: ";

cin>> x;

cout<< "square is = " << x * x;

};

int main ()
AKASH DINKAR BHOSALE
212414
Batch A1
OOPS PRACTICAL

Aob;

ob.input ();

Output:-

AKASH DINKAR BHOSALE


212414
Batch A1
OOPS PRACTICAL

Practical No-4(B)

Aim:- Design a class Complex for Adding the two complex numbers and also
show the use of constructor.

Program:-

#include <iostream>

using namespace std;

class A

public:

int a;

void in()

cout<< "Enter a number:";

cin>>a;

};

class B:private A

public:

void cu()

AKASH DINKAR BHOSALE


212414
Batch A1
OOPS PRACTICAL

in();

cout<< "\nCube of number: " << a*a*a;

};

int main()

B ob;

ob.cu();

Output:-

AKASH DINKAR BHOSALE


212414
Batch A1
OOPS PRACTICAL

Practical No-4(C)

Aim:- Design a class for multiple inheritance.

Program:-

#include <iostream>

using namespace std;

class parent1

public:

int w;

voidget_w()

cout<<"Enter Width=";

cin>>w;

};

class parent2

public:

int l;

voidget_l()

AKASH DINKAR BHOSALE


212414
Batch A1
OOPS PRACTICAL

cout<<"Enter Length=";

cin>>l;

};

classchild:public parent1, public parent2

public:

voidcal()

cout<<"Area Of Rectangel="<<l*w;

};

int main()

child c;

c.get_w();

c.get_l();

c.cal();

AKASH DINKAR BHOSALE


212414
Batch A1
OOPS PRACTICAL

Output:-

AKASH DINKAR BHOSALE


212414
Batch A1
OOPS PRACTICAL

Practical No-4(D)

Aim:- Implement the hierarchical inheritance.

Program:-

#include <iostream>

using namespace std;

class A

public:

int r;

void get()

cout<<"Enter radius=";

cin>>r;

};

class B: public A

public:

void area()

cout<<"Area Of Circle="<<3.14*r*r<<"\n";

AKASH DINKAR BHOSALE


212414
Batch A1
OOPS PRACTICAL

};

class C: public A

public:

voidcircum()

cout<<"Circumfarence of Circle="<<2*3.14*r;

};

int main()

B ob;

ob.get();

ob.area();

C ob1;

ob1.get();

ob1.circum();

AKASH DINKAR BHOSALE


212414
Batch A1
OOPS PRACTICAL

Output:-

AKASH DINKAR BHOSALE


212414
Batch A1

You might also like