17周课后自主-项目三-胖子伤不起
2014-12-22 10:26
302 查看
//show the status of your weight #include<iostream> #include<string> #include<cmath> using namespace std; enum status{thin_much,thin,normal,fat,fat_much};//枚举五种状态 struct person //定义结构体 { string name; string sex; double height; double weight; }; void printinfo(person*); int main() { person ap; cin>>ap.name>>ap.sex>>ap.height>>ap.weight; printinfo(&ap); return 0; } //打印信息 void printinfo(person* p) { string r; status s; double std_weight; if(p->sex == "man") { std_weight = (p->height - 80) * 0.7; }else if(p->sex == "woman") { std_weight = (p->height - 70) * 0.6; } double t = abs(p->weight - std_weight)/std_weight; if(p->weight > std_weight) { if(t <= 0.1) { s = normal; }else if(t > 0.1 && t <= 0.2) { s = fat; }else if(t > 0.2) { s = fat_much; } }else if(p->weight < std_weight) { if(t <= 0.1) { s = normal; }else if(t > 0.1 && t <= 0.2) { s = thin; }else if(t > 0.2) { s= thin_much; } } switch(s) { case normal: cout<<"Congratulations,your are in good healthy and your heavy is normal!";break; case thin_much: cout<<"I am so sorry to tell you that you are too thin.";break; case thin: cout<<"Ohh...It's a little thin for you.";break; case fat: cout<<"I am sorry that you are a little fat and you should exercise more.";break; case fat_much: cout<<"Oh my god!I think you should eat vegetables more and take much exercise!";break; } cout<<endl; }
运行结果
相关文章推荐
- 17周课后自主-项目二-引用作形参
- 17周课后自主-项目四-2-计算两个日期之间差了多少天
- 17周课后自主-项目一-体会函数参数传递
- 17周课后自主-项目四-1计算某年第几天
- 17周项目3--胖子伤不起
- 17周课后自主-项目6-1-输入学生信息输出
- 14周课后自主-项目3-版本2-记录成绩(含名字)
- 13周课后自主-项目一-(2)数组输出
- 第一周 项目2 胖子伤不起
- 项目2 - 胖子伤不起
- 14周课后自主-项目二-带姓名的成绩单(文件操作)
- 第4讲课后自主测验项目三(3)
- 13周课后自主-项目一-(1) 数组大折腾
- 第一周项目2-胖子伤不起
- 13周课后自主-项目4-(1)冒泡算法
- 14周课后自主-项目一 折腾二维数组
- 13周课后自主-项目一-(3)还是基本的数组
- 第一周项目2 胖子伤不起
- 第一周上机实践项目——胖子伤不起
- 2013级C++第1周(春)项目【项目2 - 胖子伤不起】