-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlab3_q4.cpp
More file actions
68 lines (62 loc) · 1.57 KB
/
lab3_q4.cpp
File metadata and controls
68 lines (62 loc) · 1.57 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
/*
4. A class representing distance is measured in the unit of feet and inches. Write a
program to do conversion from meter unit to objects of class type and objects of class type
to meter.
*/
#include <iostream>
using namespace std;
class Distance{
int feet,inches;
double METERS_PER_FOOT = 0.3048;
double INCHES_PER_FOOT = 12.0;
public:
Distance(){feet=0;inches=0;}
Distance(int f,int i){
feet=f;
inches=i;
}
Distance(double m){
double heightInMeters = m;
double heightInFeet = heightInMeters / METERS_PER_FOOT;
feet = (int)heightInFeet;
inches = (int)((heightInFeet - feet) * INCHES_PER_FOOT + 0.5);
}
operator double(){
return((feet*METERS_PER_FOOT)+(inches*METERS_PER_FOOT/INCHES_PER_FOOT));
}
void outData(){
cout<<"Distance in \nfeet = "<<feet<<"\ninches = "<<inches<<endl;
}
};
int main(){
double m;
int x=1,f,i,l;
cout<<"---CONVERSION---"<<endl;
while(x!=0){
cout<<"\nSELECT \n1. METER -> feet and inches \n2. feet and inches -> METER \n0. Exit"<<endl;
cin>>x;
switch(x){
case 1:{
cout<<"Enter the Distance in meter unit\n";
cin >>m;
Distance d;
d=m;
d.outData();
}
break;
case 2:{
cout<<"Enter the Distance in feet and inches units\n";
cin >>f>>i;
Distance d(f,i);
m=d;
cout<<"Distance in meter = "<<m<<endl;
}
break;
case 0: cout<<"EXIT \n";
break;
default:cout<<"Invalid input\n";
break;
}
}
return 0;
}