问题及代码:
/*
*Copyright (c)2014,烟台大学计算机与控制工程学院
*All rights reserved.
*文件名称:weight.cpp
*作 者:单昕昕
*完成日期:2014年12月18日
*版 本 号:v1.0
*
*问题描述:根据身高体重,计算体重是否合格。
*程序输入:姓名、性别、身高、体重。
*程序输出:判断结果。
*/
#include <iostream>
using namespace std;
struct People
{
char name[20];
char sex;
double height;
double weight;
};
int main()
{
int fs,ms,fss,mss;
People people;
cout<<"请分别输入您的姓名、性别(m||f)、身高(cm)、体重(kg):"<<endl;
cin>>people.name>>people.sex>>people.height>>people.weight;
fs=(people.height-70)*0.6;
ms=(people.height-70)*0.7;
if(people.sex=='m')
{
mss=(people.weight-ms)/ms*100;
if(mss<10&&mss>-10)
cout<<"您的体重很正常哦~请继续保持~"<<endl;
else if(mss>20)
cout<<"您太重了哦~赶紧想办法瘦瘦瘦~"<<endl;
else if(mss<-20)
cout<<"您太轻了哦~赶紧想办法吃吃吃~"<<endl;
else if(mss>=10&&mss<=20)
cout<<"您这是要发福的趋势哦~控制一下哦~"<<endl;
else
cout<<"您偏轻了~再加把劲~"<<endl;
}
if(people.sex=='f')
{
fss=(people.weight-fs)/fs*100;
if(fss<10&&fss>-10)
cout<<"您的体重很正常哦~请继续保持~"<<endl;
else if(fss>20)
cout<<"您太重了哦~赶紧想办法瘦瘦瘦~"<<endl;
else if(fss<-20)
cout<<"您太轻了哦~赶紧想办法吃吃吃~"<<endl;
else if(fss>=10&&fss<=20)
cout<<"您这是要发福的趋势哦~控制一下哦~"<<endl;
else
cout<<"您偏轻了~再加把劲~"<<endl;
}
return 0;
}
运行结果:
知识点总结:
结构体。
学习心得:
第一次用结构体,感觉还不错。
本文介绍了一个使用C++结构体实现的功能,该功能根据输入的姓名、性别、身高和体重来判断体重是否合格。通过计算并比较实际体重与理想范围内的偏差百分比,提供个性化的健康建议。
874

被折叠的 条评论
为什么被折叠?



