forked from rituburman/hacktoberfest2020
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOverloading.cpp
More file actions
49 lines (41 loc) · 673 Bytes
/
Overloading.cpp
File metadata and controls
49 lines (41 loc) · 673 Bytes
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
47
48
49
//C++ program for operator overloading
#include<iostream>
#include<conio.h>
using namespace std;
class overloading
{
int value;
public:
void setValue(int temp)
{
value = temp;
}
overloading operator+(overloading& ob)
{
overloading t;
t.value=value+ob.value;
return(t);
}
void display()
{
cout<<value<<endl;
}
};
//Main Functions
int main()
{
overloading obj1,obj2,result;
int a,b;
cout<<"Enter the values a,b:";
cin>>a>>b;
obj1.setValue(a);
obj2.setValue(b);
result = obj1+obj2;
cout<<"Input Values:\n";
obj1.display();
obj2.display();
cout<<"Result:";
result.display();
getch();
return 0;
}