Last active
August 29, 2015 14:07
-
-
Save kazmura11/6e086d08cadc7b8660ee to your computer and use it in GitHub Desktop.
dll sample Bmi.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "Bmi.h" | |
| #include <stdexcept> | |
| namespace MyUtil | |
| { | |
| Bmi::Bmi(const std::string name, const double height, const double weight) | |
| :name_(name), height_(height), weight_(weight), bmi_(0.0) | |
| { | |
| } | |
| std::string Bmi::calc() | |
| { | |
| std::string message; | |
| if (height_ == 0.0) std::invalid_argument("Cannot devide by zero!"); | |
| bmi_ = weight_ / (height_ * height_); | |
| if (bmi_ < BmiBoundLow) | |
| { | |
| message = "低体重"; | |
| } | |
| else if (bmi_ < BmiBoundNormal) | |
| { | |
| message = "普通体重"; | |
| } | |
| else if (bmi_ < BmiBoundHighLv1) | |
| { | |
| message = "肥満(1度)"; | |
| } | |
| else if (bmi_ < BmiBoundHighLv2) | |
| { | |
| message = "肥満(2度)"; | |
| } | |
| else if (bmi_ < BmiBoundHighLv3) | |
| { | |
| message = "肥満(3度)"; | |
| } | |
| else | |
| { | |
| message = "肥満(4度)"; | |
| } | |
| return message; | |
| } | |
| std::string Bmi::getName() | |
| { | |
| return name_; | |
| } | |
| double Bmi::getBmi() | |
| { | |
| return bmi_; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment