Closed roberthsu2003 closed 9 months ago
#include <iostream>
#include <math.h>
class BMI{
public:
int heigth;
int weigth;
BMI(double h, double w){
heigth = h;
weigth = w;
}
double gteBmi(){
return weigth/(pow(heigth, 2)) *10000;
}
void print(){
std::cout << "您的身高是:" << heigth << std::endl;
std::cout << "您的體重是:" << weigth << std::endl;
std::cout << "您的BMI是:" << gteBmi() << std::endl;
if(gteBmi() < 18.5){
std::cout << "過輕";
}else if(gteBmi() < 24){
std::cout << "正常";
}else if(gteBmi() < 27){
std::cout << "過重";
}else if(gteBmi() < 30){
std::cout << "輕度肥胖";
}else if(gteBmi() < 35){
std::cout << "中度肥胖";
}else{
std::cout << "重度肥胖";
}
}
};
using namespace std;
int main() {
double h;
double w;
cout << "請輸入您的身高及體重";
cin >> h >> w;
BMI pro1(h, w);
pro1.print();
}
#include <iostream>
#include <math.h>
#define SQUARE(x) pow((x),2)
namespace bodyBMI{
class BMI{
public:
//定義field
double weight;
double height;
double BMIdata;
//自訂建構式
BMI(double w, double h){
weight = w;
height = h;
}
//定義method
double BMI_compute(){
return BMIdata=weight/SQUARE(height);
}
double BMI_judge(){
if (BMIdata < 18.5){
std::cout << "體重過輕" << std::endl;
}
else if (BMIdata >= 18.5 && BMIdata < 24){
std::cout << "體重正常" << std::endl;
}
else if (BMIdata >= 24 && BMIdata < 27){
std::cout << "體重過重" << std::endl;
}
else if (BMIdata >= 27 && BMIdata < 30){
std::cout << "輕度肥胖" << std::endl;
}
else if (BMIdata >= 30 && BMIdata < 35){
std::cout << "中度肥胖" << std::endl;
}
else {
std::cout << "重度肥胖" << std::endl;
}
return BMIdata;
}
void print(){
std::cout << weight << std::endl;
std::cout << height << std::endl;
std::cout << "你的BMI值:" << BMI_compute() << "\n";
std::cout << "你的BMI範圍在:" << BMI_judge() << "\n";
}
};
};
using namespace std;
using namespace bodyBMI;
int main() {
double w,h;
cout << "請輸入你的體重(公斤)、身高(公分):";
cin >> w >> h ;
BMI yourBMI(w,h);
yourBMI.weight = w;
yourBMI.height = h/100;
yourBMI.print();
}
#include <iostream>
class BMI{
public:
int height;
int weight;
BMI(int h,int w){
height = h;
weight = w;
}
double getBMI(){
return weight / ((double)height * height / 10000);
}
void print(){
std::cout << "您的身高是" << height << "公分" << std::endl;
std::cout << "您的體重是" << weight << "公斤" << std::endl;
std::cout << "您的BMI值是" << getBMI() << std::endl;
if(18.5 >= getBMI() && getBMI() <= 24.0){
std::cout << "您的BMI值正常" << std::endl;
}
else{
std::cout << "您的BMI值異常" << std::endl;
}
}
};
using namespace std;
int main() {
int h,w;
cout << "請輸入身高(公分):";
cin >> h;
cout << "請輸入體重(公斤):";
cin >> w;
BMI formula(h,w);
formula.print();
}