-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdm db classes.cpp
More file actions
112 lines (85 loc) · 2.05 KB
/
dm db classes.cpp
File metadata and controls
112 lines (85 loc) · 2.05 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <iostream>
#include <math.h>
using namespace std;
class DB;
class DM{
private:
double m, cm;
public:
void setDistance();
friend void add(DM dm, DB db);
};
class DB{
private:
int feet, inch;
public:
void setDistance();
friend void add(DM dm, DB db);
};
int main() {
DM dm;
DB db;
dm.setDistance();
cout<<endl;
db.setDistance();
cout<<endl;
add(dm, db);
return 0;
}
void DM :: setDistance(){
cout<<"You are required to enter distance in metres and centimetres"<<endl;
do{
cout<<"\nEnter number of metres: ";
cin>>m;
} while (fmod(m,1) !=0);
cout<<"Enter number of centimetres: ";
cin>>cm;
double tempm;
m = tempm;
while (cm >= 100 || tempm > 0){
if(cm >=100){
cm = cm - 100;
m = m + 1;
}
if(tempm > 0){
tempm = tempm - 1;
if (tempm <= 0){
m = m - tempm;
cm = tempm*100;
}
}
}
cout<<"Distance: "<<m<<" metres and "<<cm<<" centimetres"<<endl;
}
void DB :: setDistance(){
cout<<"You are required to enter distance in feet and inches"<<endl;
cout<<"\nEnter number of feet: ";
cin>>feet;
cout<<"Enter number of inches: ";
cin>>inch;
while (inch >= 12){
inch = inch - 12;
feet = feet + 1;
}
cout<<"Distance: "<<feet<<" feet and "<<inch<<" inches"<<endl;
}
void add(DM dm, DB db){
double distancem, distancecm, distancef, distancein, m, cm, feet, inch;
m = db.feet/3.28;
cm = db.inch*2.54;
while (cm >= 100){
cm = cm - 1;
m = m + 1;
}
feet = dm.m*3.28;
inch = dm.cm/2.54;
while (inch >= 12){
inch = inch - 12;
feet = feet + 1;
}
distancem = m + dm.m;
distancecm = cm + dm.cm;
distancef = feet + db.feet;
distancein = inch + db.inch;
cout<<"Total distance in metres and centimetres: "<<distancem<<" metres and "<<cm<<" centimetres"<<endl;
}