您好,欢迎访问一九零五行业门户网

C++程序用于读取一个人的身高,并打印出该人是高个子、矮个子还是平均身高的人

一个人的身高决定了他/她是高个子、侏儒还是中等身高的人。在世界不同地区,身高范围是不同的。我们正在考虑印度标准。在本文中,我们将介绍如何用 c++ 编写一个简单的程序来确定一个人是较高、矮子还是中等身高。
让我们首先定义高度范围和相应的分类,然后我们可以在算法和实现中使用它们。
身高(厘米) 类型
150 – 170 平均
170 – 195 高
低于150 矮人
还有什么吗 高度异常
现在让我们看看其算法和实现。
算法读取高度 h 。如果 h 在 150 到 170 之间,则。此人身高中等。否则当h在170到195之间时,则。这个人很高。否则当 h 低于 150 时,则。这个人是侏儒。对于其他一些情况,此人身高异常结束如果。示例#include <iostream>using namespace std;void solve( int h ) { if (h >= 150 && h <= 170 ) { cout << the person is of average height << endl; } else if (h >= 170 && h <= 195 ) { cout << the person is tall << endl; } else if (h < 150 ) { cout << the person is dwarf << endl; } else { cout << the person has abnormal height << endl; }}int main(){ cout << height of person a: 172 << endl; solve( 172 ); cout << height of person b: 130 << endl; solve( 130 ); cout << height of person c: 198 << endl; solve( 198 ); cout << height of person d: 160 << endl; solve( 160 );}
输出height of person a: 172the person is tallheight of person b: 130the person is dwarfheight of person c: 198the person has abnormal heightheight of person d: 160the person is of average height
结论使用高度进行分类是一个简单的问题,我们只是在某些条件下使用决策。在我们的实现中,显示了四个类别,即高、矮、平均和异常身高。上表中还定义了高度范围。通过简单的条件检查 if-else 解决方案,程序可以根据给定的身高值对人进行分类。
以上就是c++程序用于读取一个人的身高,并打印出该人是高个子、矮个子还是平均身高的人的详细内容。
其它类似信息

推荐信息