Object Oriented Programming Practical 19
Question 1
Overload the unary operator –(minus) using member function and friend function
unary.cpp
C
#include<iostream.h>
#include<conio.h>
class unary
{
float num;
public:
void accept()
{
cout<<"\nEnter number: ";
cin>>num;
}
void display()
{
cout<<"Number= "<<num<<endl;
}
unary operator--()
{
num=num-1;
}
};
void main()
{
clrscr();
unary u;
u.accept();
u--;
cout<<"\nAfter unary operation ";
u.display();
getch();
}
Output
