-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path13_length.cpp
executable file
·87 lines (65 loc) · 971 Bytes
/
13_length.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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <iostream>
using namespace std;
class DM;
class DB{
int feet;
float inch;
public:
void getl();
void show();
friend DM add(DB, DM);
};
class DM{
int m;
float cm;
public:
void getl();
void show();
friend DM add(DB, DM);
};
int main(){
DB x;
DM y, z;
x.getl();
y.getl();
z = add(x, y);
z.show();
return 0;
}
DM add(DB a, DM b){
DM temp;
temp.cm = (a.feet * 12 + a.inch) * 2.54;
temp.cm += b.cm;
temp.m = (int)(temp.cm / 100);
temp.cm -= temp.m * 100;
temp.m += b.m;
return temp;
}
// DB
void DB::show(){
cout<<feet<<" feet "<<inch<<" inches\n";
}
void DB::getl(){
int t;
cout<<"Enter length in feet and inches : ";
cin>>feet>>inch;
if(inch >= 12){
t = inch / 12;
feet += t;
inch -= t * 12;
}
}
// DM
void DM::show(){
cout<<m<<" m "<<cm<<" cm\n";
}
void DM::getl(){
int t;
cout<<"Enter length in meter and cm : ";
cin>>m>>cm;
if(cm >= 100){
t = cm / 100;
m += t;
cm -= t * 100;
}
}