|
Home ► Lab Exercise ► Object Oriented Programming Lab Exercise Programs ► CPP Program to Implement Operator Overloading Including Unary and Binary Operators▼
CPP Program to Implement Operator Overloading Including Unary and Binary Operators |
Alogarithm steps:
- Start the program
- Create the class
- Write the function to implement unary +, - and =
- Write the function to implement binary +
- Create the instance and pass the value for the function
- Call the overloaded function and equate it to another object
- Compile and run the program
CPP Program to Implement Operator Overloading Including Unary and Binary Operators
#include
class myclass
{
int a, b;
public:
void init(int i, int j);
{
a = i;
b = j;
}
void show();
{
cout<<”a=”<
SAMPLE INPUT AND OUTPUT:
x =10
y =20
x =5
y =30
x =11
y =21
x =12
y =22
x =90
y =90
x =90
y =90
|
|
⇓ Student Projects ⇓
⇑ Student Projects ⇑
|