FY-4-a Easy C++ program to overload unary operator (-)

OOP program to overload unary operator (-)

Design the class Demo which will contain the following methods: readNo(),
factorial() for calculating the factorial of a number, reverseNo() will reverse the
given number, isPalindrome() will check the given number is palindrome,
isArmstrong() which will calculate the given number is armStrong or not.Where
readNo() will be private method.

Click here to get other OOP Practical

FYIT practical 4-a Unary Operator Overloading

#include<iostream>
using namespace std;
class Minus
{
int a,b;
public:
void get()
{
cout<<"Enter value for A and B : ";
cin>>a>>b;
}
void show()
{
cout<<endl<<"A="<<a<<endl<<"B="<<b;
}
void operator -()
{
a=-a;
b=-b;
}
};
int main()
{
Minus s;
s.get();
cout<<endl<<"Before overloading";
s.show();
-s;
cout<<endl<<"After overloading";
s.show();
return 0;
}

Output

unary-operator-overloading-itvoyagers

Check out more FYIT OOP Practical Program and other logic building programs in C++

We are aiming to explain all concepts of C++ and OOP in easiest terms as possible.
ITVoyagers-logo
ITVoyagers
Author

Leave a Comment