-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
62 lines (47 loc) · 1.31 KB
/
main.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
#include "include/utils.h"
template<typename T>
void printSet(set<T> const &s) {
// for(auto i : s) makes a copy of each element of s
for (auto const &i: s) {
cout << i << " ";
}
cout << endl;
}
ostream &operator<<(ostream &os, const set<string> &s) {
for (auto const &i: s) {
os << i << " ";
}
os << "\n";
return os;
}
int main(void) {
cout << "---------Start of program----------\n\n\n";
set<string> valid_curr {};
fetchValidCurrency(valid_curr);
// Using template function
// printSet<string>(valid_curr);
// Using operator overloading
// cout << valid_curr;
string curr1, curr2;
curr1 = "USD";
curr2 = "INR";
takeInputsInUpper(curr1, curr2);
// Using lambda expression
auto validateCurrency = [valid_curr](const string curr) -> bool {
return valid_curr.find(curr) != valid_curr.end();
};
if (!validateCurrency(curr1) || !validateCurrency(curr2)) {
cout << "Please use valid currency code. Exiting.\n";
}
else {
double fx_rate = getFxRate(curr1, curr2);
cout << "Using FX rate: " << fx_rate << "\n\n";
cout << "Input amount in " << curr1 << ": ";
double amount;
cin >> amount;
cout << "Equivalent amount in " << curr2 << ": " <<
amount*fx_rate << "\n";
}
cout << "\n\n---------End of program----------\n";
return 0;
}