-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass37.cpp
48 lines (45 loc) · 824 Bytes
/
class37.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
47
48
#include<iostream> //program to show the use of friend function and operator overloading
using namespace std;
class height
{
int feet;
float inch;
public:
height()
{
feet=inch=0;
}
height(int f,float i)
{
feet=f;
inch=i;
}
height(float t)
{
feet =(int)t;
inch=12*(t-feet);
}
void show()
{
cout<<"Feet="<<feet<<"\tInch="<<inch<<endl;
}
friend height operator+(height h1,height h2)
{
height temp;
temp.feet=h1.feet+h2.feet;
temp.inch=h1.inch=h2.inch;
if(temp.inch>=12)
{
temp.inch-=12;
temp.feet++;
}
return temp;
}
};
int main()
{
height h1(10,15),h2;
h2=15.5+h1;
h2.show();
return 0;
}