Files
Data_Structure/Chapter1/app1-4.cpp

33 lines
881 B
C++

#include<iostream>//cout,cin
using namespace std;
struct stu
{
int xh; // 学号
float height; //身高
};
int MaxH; // 最高身高
//算法1.1
int maxHeight(stu student[], int n)
{
MaxH = 1; // 1. 设第1个学生身高最高
for (int i = 2; i <= n; i++) // 2. 从第2个学生起依次与最高身比
{
if (student[i - 1].height > student[MaxH - 1].height) // 2.1 大于最高身高
MaxH = i; // 2.2为新最高身高
}
return student[MaxH - 1].xh; // 3.返回最高身高学生学学号
}
int main()
{
cout << "获取数据" << endl;
int n = 6; //学生数
int xh;
stu student[6] = { {1703001,176},{1703002,180},{1703003,175},{1703004,182.5},{1703005,158.5},{1703005,173.8} };
xh = maxHeight(student, n);
cout << "身高最高者是:" << xh << endl;
return 1;
}