-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathoperator_over_3.cpp
More file actions
53 lines (49 loc) · 1.28 KB
/
Copy pathoperator_over_3.cpp
File metadata and controls
53 lines (49 loc) · 1.28 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
// In the following C++ program, two classes representing
// geographical coordinates (longitude and latitude) are defined.
// The program uses operator overloading to add two coordinate objects together.
// What will be the output of the program when executed?
// Identify and correct any errors in the code, if present.
// Explain how operator overloading is implemented in this code.
#include<iostream>
using namespace std;
class sample
{
int lon,lat;
public: sample()
{
lon=lat=0;
}
sample(int a,int b)
{
lon=a;
lat=b;
}
void print()
{
cout<<"latitude : "<<lat<<"\n"<<"longitude : "<<lon<<endl;
}
// operator overloading function
sample operator+(sample &c)
{
sample t;
t.lon=lon+c.lon;
t.lat=lat+c.lat;
return t;
}
};
sample operator+(sample &c)
{
sample t;
t.lon=lon+c.lon;
t.lat=lat+c.lat;
return t;
}
int main()
{
sample c1(2,4);
sample c2(2,3);
sample c3;
c3=c1+c2;
c3.print();
return 0;
}