-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path67.cpp
46 lines (44 loc) · 814 Bytes
/
67.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Write a Program to Overload Unary + and Unary - Operator.
#include<iostream>
using namespace std;
class IncreDecre
{
int a,b;
public:
void accept()
{
cout<< "Enter Two Numbers: " << endl;
//cout<< " ";
cin>> a;
//cout<< " ";
cin>> b;
}
void operator--() //Overload Unary Decrement
{
a--;
b--;
}
void operator++() //Overload Unary Increment
{
a++;
b++;
}
void display()
{
cout<< "\nA: " <<a;
cout<< "\nB: " <<b;
}
};
int main()
{
IncreDecre id;
id.accept();
--id;
cout<< "\nAfter Decrementing: ";
id.display();
++id;
++id;
cout<< "\n\nAfter Incrementing: ";
id.display();
return 0;
}