目标:设计一款小软件,能够预测身高、判定体型。
1、青少年身高测算器
编程从键盘输入用户的性别,父母身高,是否喜欢体育锻炼,
是否有良好的饮食习惯,利用给定的公式和身高预测方法,
对用户的身高进行预测。
男性成人时身高=(faHeight+moHeight)*0.54 cm
女性成人时身高=(faHeight*0.923+moHeight)/2 cm
如果喜欢体育锻炼,身高增加2%;
如果有良好的饮食习惯,身高增加1.5%。
2、体型判定软件
编程从键盘输入用户的身高和体重,利用给定的公式计算体质指数BMI,
再根据BMI指数判定体型。
体质指数(BMI)=体重(kg)/(身高(m)*身高(m))
#include<iostream.h>
double nan(double,double);
double nv(double,double);
double bmi(double,double);
void main()
{
cout<<"***************************"<<endl<<"欢迎进入升高体型判断系统"<<endl<<"****************************"<<endl<<"****************************"<<endl
<<"请输入您的选择"<<endl<<"1、身高预测系统"<<endl<<"2、体型判断系统"<<endl<<"3、退出系统"<<endl<<"****************************"<<endl;
double choice=0,shenggao;
cin>>choice;
if(choice==3)
;
else
{
if(choice==1)
{
cout<<"欢迎来到身高预测系统";
int father,mother;
cout<<"请输入爸爸和妈妈的身高(cm),例如:170,160"<<endl;
cin>>father>>mother;
cout<<"请输入孩子的性别(m:男,f:女)"<<endl;
char zifu,men='m',women='f';
cin>>zifu;
if(zifu=='m')
shenggao=nan(father,mother);
else
shenggao=nv(father,mother);
cout<<"是否喜欢体育锻炼(y:是的,n:不是)"<<endl;
char dl;
cin>>dl;
if(dl=='y')
shenggao=1.02*shenggao;
cout<<"是否有良好的饮食习惯(y:是的,n:)"<<endl;
char ys;
cin>>ys;
if(ys=='y')
shenggao=1.015*shenggao;
cout<<"孩子身高是:"<<shenggao<<endl;
}
else
{
double shenggao,tizhong,zishu;
if(choice==2)
{
cout<<"欢迎进入体型判断系统!"<<endl<<"请输入身高(m)和体重(kg),例如1.72,60"<<endl;
cin>>shenggao>>tizhong;
zishu=bmi(shenggao,tizhong);
cout<<"您的BMI指数为"<<zishu<<endl;
if(zishu<=18.4)
cout<<"偏瘦"<<endl;
else
if(zishu>18.5&&zishu<23.9)
cout<<"正常"<<endl;
else
if(zishu>24.0&&zishu<27.9)
cout<<"过重"<<endl;
else
if(zishu>=28.0)
cout<<"肥胖"<<endl;
}
}
}
}
double nan(double a,double b) //身高计算子函数
{
double c;
c=(a+b)*0.54;
return c;
}
double nv(double a,double b)
{
double c;
c=(a/0.923+b)/2;
return c;
}
double bmi(double a,double b)
{
double c;
c=b/(a*a);
return c;
}