差分
このページの2つのバージョン間の差分を表示します。
| 両方とも前のリビジョン前のリビジョン次のリビジョン | 前のリビジョン | ||
| fltk:example-app-bmi_calc [2025/05/26 16:48] – Divide into sections and add headers and CMakeLists.txt freemikan | fltk:example-app-bmi_calc [2025/06/12 11:46] (現在) – [スクリーンショット] Remove imagebox freemikan | ||
|---|---|---|---|
| 行 1: | 行 1: | ||
| - | ====== | + | ====== |
| - | {{: | + | [[fltk:|{{: |
| - | ===== 実行画面 | + | ===== スクリーンショット |
| {{ : | {{ : | ||
| + | |||
| + | ===== プロジェクトレイアウト ===== | ||
| + | |||
| + | bmi_calc/ | ||
| + | ├── CMakeLists.txt | ||
| + | └── main.cpp | ||
| 行 39: | 行 45: | ||
| #include < | #include < | ||
| + | #include < | ||
| #include < | #include < | ||
| + | #include < | ||
| #include < | #include < | ||
| - | Fl_Input *height_input; | + | Fl_Input *height_input_; |
| - | Fl_Input *weight_input; | + | Fl_Input *weight_input_; |
| - | Fl_Output *result_output; | + | Fl_Output *result_output_; |
| std:: | std:: | ||
| 行 55: | 行 63: | ||
| errno = 0; | errno = 0; | ||
| - | // NOTE: We also can use std::stod with std::string instead of std:: | + | // NOTE: We can also use std::stod with std::string instead of std:: |
| - | if (double value = std:: | + | if (double |
| *end_str == ' | *end_str == ' | ||
| return value; | return value; | ||
| 行 65: | 行 73: | ||
| void calc_button_cb(Fl_Widget *w, void *data) { | void calc_button_cb(Fl_Widget *w, void *data) { | ||
| - | auto h_cm = double_value(height_input); | + | auto h_cm = double_value(height_input_); |
| - | auto w_kg = double_value(weight_input); | + | auto w_kg = double_value(weight_input_); |
| if (h_cm.has_value() && w_kg.has_value()) { | if (h_cm.has_value() && w_kg.has_value()) { | ||
| - | double h_m = *h_cm / 100; | + | double |
| - | | + | |
| - | | + | // Avoid zero divisions |
| - | | + | if (double const h_m_2 = h_m * h_m; |
| - | } else { | + | h_m_2 > std:: |
| - | result_output-> | + | double const bmi = *w_kg / h_m_2; |
| - | | + | |
| + | | ||
| + | | ||
| + | | ||
| } | } | ||
| + | result_output_-> | ||
| + | result_output_-> | ||
| } | } | ||
| int main(int argc, char **argv) { | int main(int argc, char **argv) { | ||
| auto window = new Fl_Window(230, | auto window = new Fl_Window(230, | ||
| - | | + | |
| - | | + | |
| auto calc_button = new Fl_Return_Button(20, | auto calc_button = new Fl_Return_Button(20, | ||
| - | | + | |
| calc_button-> | calc_button-> | ||
