The input.txt is:
CHF 1.0365
EUR 1.1860
JPY 0.0091
DEM 0.6064
SGD 0.7369
CAD 0.8068
meaning:
1 CHF = 1.0365 USD
1 EUR = 1.1860 USD
....
1 CAD = 0.8068 USD
void Currency_converter_window::fill_map(std::istream &is)
{
std::string rate_id;
double rate = 0;
for ()
{
}
const int map_size = 56;
for (int i = 0; i < map_size; ++i)
{
}
}
int main()
{
using namespace std;
constexpr int win_width = 640, win_height = 440;
try
{
cout << "Enter name of file: ";
string file_name;
cin >> file_name;
Currency_converter_window win{ Point{100, 100}, win_width, win_height, "Currency Converter" };
ifstream ifs{ file_name };
win.fill_map(ifs);
return gui_main();
}
catch (const runtime_error &e)
{
Currency_converter_window win{ Point{ 100, 100 }, win_width, win_height, "Currency Converter" };
Text err_msg_start{ Point{(win_width / 2) - 100, win_height / 2}, "Runtime error: " };
Text err_msg{ Point{(win_width / 2) - 100 + err_msg_start.label().length(), win_height / 2}, e.what() };
err_msg_start.set_color(Color::black);
err_msg.set_color(Color::black);
win.attach(err_msg_start);
win.attach(err_msg);
return gui_main();
}
catch (const exception &e)
{
Currency_converter_window win{ Point{ 100, 100 }, win_width, win_height, "Currency Converter" };
Text err_msg_start{ Point{ (win_width / 2) - 100, win_height / 2 }, "Exception: " };
Text err_msg{ Point{ (win_width / 2) - 100 + err_msg_start.label().length(), win_height / 2 }, e.what() };
err_msg_start.set_color(Color::black);
err_msg.set_color(Color::black);
win.attach(err_msg_start);
win.attach(err_msg);
return gui_main();
}
catch (...)
{
Currency_converter_window win{ Point{ 100, 100 }, win_width, win_height, "Currency Converter" };
Text err_msg{ Point{ (win_width / 2) - 100, win_height / 2 }, "An unknown exception occurred" };
err_msg.set_color(Color::black);
win.attach(err_msg);
return gui_main();
}
}
void Currency_converter_window::fill_map(std::istream &is)
{
std::string file_data;
std::vector<std::string> rate_ids;
std::vector<double> rates;
int i = 0;
while (getline(is, file_data))
{
if (file_data[i] != ';' && isdigit(file_data[i]))
{
}
}
const int map_size = 56;
for (int i = 0; i < map_size; ++i)
{
}
}
void Currency_converter_window::cb_callback(Address p_widget, Address addr)
{
if (std::strncmp(reference_to<Currency_converter_window>(static_cast<Fl_Widget *>(p_widget)).label(), "Convert From", 13) == 0)
{
reference_to<Currency_converter_window>(addr).from_menu_button_pressed();
if (std::strncmp(reference_to<Currency_converter_window>(static_cast<Fl_Widget *>(p_widget)).label(), "USD", 4) == 0)
{
reference_to<Currency_converter_window>(addr).from_usd_button_pressed();
}
else if (std::strncmp(reference_to<Currency_converter_window>(static_cast<Fl_Widget *>(p_widget)).label(), "CAD", 4) == 0)
{
reference_to<Currency_converter_window>(addr).from_cad_button_pressed();
}
else if (std::strncmp(reference_to<Currency_converter_window>(static_cast<Fl_Widget *>(p_widget)).label(), "AUD", 4) == 0)
{
reference_to<Currency_converter_window>(addr).from_aud_button_pressed();
}
else if (std::strncmp(reference_to<Currency_converter_window>(static_cast<Fl_Widget *>(p_widget)).label(), "EUR", 4) == 0)
{
reference_to<Currency_converter_window>(addr).from_eur_button_pressed();
}
else if (std::strncmp(reference_to<Currency_converter_window>(static_cast<Fl_Widget *>(p_widget)).label(), "CNY", 4) == 0)
{
reference_to<Currency_converter_window>(addr).from_cny_button_pressed();
}
else if (std::strncmp(reference_to<Currency_converter_window>(static_cast<Fl_Widget *>(p_widget)).label(), "JPY", 4) == 0)
{
reference_to<Currency_converter_window>(addr).from_jpy_button_pressed();
}
else if (std::strncmp(reference_to<Currency_converter_window>(static_cast<Fl_Widget *>(p_widget)).label(), "DKK", 4) == 0)
{
reference_to<Currency_converter_window>(addr).from_dkk_button_pressed();
}
else if (std::strncmp(reference_to<Currency_converter_window>(static_cast<Fl_Widget *>(p_widget)).label(), "EGP", 4) == 0)
{
reference_to<Currency_converter_window>(addr).from_egp_button_pressed();
}
}
else if (std::strncmp(reference_to<Currency_converter_window>(static_cast<Fl_Widget *>(p_widget)).label(), "Convert To", 11) == 0)
{
reference_to<Currency_converter_window>(addr).to_menu_button_pressed();
if (std::strncmp(reference_to<Currency_converter_window>(static_cast<Fl_Widget *>(p_widget)).label(), "USD", 4) == 0)
{
reference_to<Currency_converter_window>(addr).to_usd_button_pressed();
}
else if (std::strncmp(reference_to<Currency_converter_window>(static_cast<Fl_Widget *>(p_widget)).label(), "CAD", 4) == 0)
{
reference_to<Currency_converter_window>(addr).to_cad_button_pressed();
}
else if (std::strncmp(reference_to<Currency_converter_window>(static_cast<Fl_Widget *>(p_widget)).label(), "AUD", 4) == 0)
{
reference_to<Currency_converter_window>(addr).to_aud_button_pressed();
}
else if (std::strncmp(reference_to<Currency_converter_window>(static_cast<Fl_Widget *>(p_widget)).label(), "EUR", 4) == 0)
{
reference_to<Currency_converter_window>(addr).to_eur_button_pressed();
}
else if (std::strncmp(reference_to<Currency_converter_window>(static_cast<Fl_Widget *>(p_widget)).label(), "CNY", 4) == 0)
{
reference_to<Currency_converter_window>(addr).to_cny_button_pressed();
}
else if (std::strncmp(reference_to<Currency_converter_window>(static_cast<Fl_Widget *>(p_widget)).label(), "JPY", 4) == 0)
{
reference_to<Currency_converter_window>(addr).to_jpy_button_pressed();
}
else if (std::strncmp(reference_to<Currency_converter_window>(static_cast<Fl_Widget *>(p_widget)).label(), "DKK", 4) == 0)
{
reference_to<Currency_converter_window>(addr).to_dkk_button_pressed();
}
else if (std::strncmp(reference_to<Currency_converter_window>(static_cast<Fl_Widget *>(p_widget)).label(), "EGP", 4) == 0)
{
reference_to<Currency_converter_window>(addr).to_egp_button_pressed();
}
}
else if (std::strncmp(reference_to<Currency_converter_window>(static_cast<Fl_Widget *>(p_widget)).label(), "OK", 3) == 0)
{
reference_to<Currency_converter_window>(addr).ok_button_pressed();
}
}
void Out_box::put(double d)
{
Fl_Output& po = reference_to<Fl_Output>(pw);
std::stringstream ss;
ss << d;
po.value(ss.str().c_str());
}
double In_box::get_double()
{
Fl_Input& pi = reference_to<Fl_Input>(pw);
const char* p = pi.value();
if (!isdigit(p[0])) return -999999;
return static_cast<double>(atof(p));
}