-
Notifications
You must be signed in to change notification settings - Fork 0
/
Converter.cpp
94 lines (84 loc) · 2.01 KB
/
Converter.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
88
89
90
91
92
93
94
#include<iostream>
using namespace std;
class Converter {
protected:
double val1, val2;
double getinit() {
return val1;
}
double getconv() {
return val2;
}
public:
virtual void compute() = 0;
};
class KMtoM : public Converter {
double temp;
public:
void compute() {
cout << "\n=> Kilometer to meter converter";
cout << "\nEnter the kilometer value: ";
cin >> val1;
cout << "\nKilometer value: " << getinit();
val2 = val1 * 1000;
cout << "\nMeter value: " << getconv();
}
};
class CMtoIN : public Converter {
double temp;
public:
void compute() {
cout << "\n=> Centimeter to inch converter";
cout << "\nEnter the centimeter value: ";
cin >> val1;
cout << "\nCentimeter value: " << getinit();
val2 = val1 / 2.54;
cout << "\nInch value: " << getconv();
}
};
class CLtoF : public Converter {
double temp;
public:
void compute() {
cout << "\n=> Celsius to fahrenheit converter";
cout << "\nEnter the celsius value: ";
cin >> val1;
cout << "\nCelsius value: " << getinit();
val2 = val1 * 1.8 + 32;
cout << "\nFahrenheit value: " << getconv();
}
};
int main() {
int choice;
Converter *c;
KMtoM km;
CMtoIN ci;
CLtoF cf;
x:
cout << "\n==========================MENU==========================\n";
cout << "\n1.Kilometer to meter\n2.Centimeter to inches\n3.Celsius to fahrenheit";
cout << "\n\tEnter your choice: ";
cin >> choice;
switch (choice) {
case 1:
c = &km;
c->compute();
break;
case 2:
c = &ci;
c->compute();
break;
case 3:
c = &cf;
c->compute();
break;
default:
cout << "\nWrong choice.";
}
char ch;
cout << "\nDo you want to continue? (y/n): ";
cin >> ch;
if (ch == 'Y' || ch == 'y')
goto x;
return 0;
}