-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperatoroverload.cpp
More file actions
74 lines (69 loc) · 1.36 KB
/
operatoroverload.cpp
File metadata and controls
74 lines (69 loc) · 1.36 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//Program that shows operator overloading of arithmetic operators
#include<iostream>
using namespace std;
class location
{
private :
float latitude;
float longitude;
public:
location operator -(location);
location operator=(location);
void operator ++();
void operator ++(int);
location();
location(float,float);
void display();
};
location::location()
{
latitude=0;
longitude=0;
}
location::location(float latitude,float longitude)
{
this->latitude= latitude;
this->longitude =longitude;
}
location location::operator-(location a)
{
location temp;
temp.latitude=latitude-a.latitude;
temp.longitude=longitude-a.longitude;
return temp;
}
location location::operator=(location b)
{
this->latitude=b.latitude;
this->longitude=b.longitude;
return *this;
}
void location::operator++()
{
this->latitude=++latitude;
this->longitude=++longitude;
}
void location::operator++(int x)
{
this->latitude=latitude++;
this->longitude=longitude++;
}
void location::display()
{
cout<<longitude;
cout<<latitude;
}
int main()
{
location loc1(2.3,4.5);
location loc2(7.4,5.6);
location temp;
loc1=loc1-loc2;
loc1.display();
loc1=loc2;
loc1.display();
++loc1;
loc1.display();
loc1++;
loc1.display();
}