编写程序,输入若干学生(学生个数用宏定义)的学号、姓名和C++考试分数。该程序能输出每个学生的学号

编写程序,输入若干学生(学生个数用宏定义)的学号、姓名和C++考试分数。该程序能输出每个学生的学号、姓名和相应的考试成绩,同时能查询并输出最高分的学生的学号、姓名和考试分数。

实验要求:

1.要求使用结构体数组;

2.输出和查询功能用函数实现

//快点采纳!!!
#include<iostream>
#define N 5
using namespace std;
struct student
{
    int score;
    string number;
    string name;

} stu[N];
void Output()
{
    cout<<"以下为所有学生信息:"<<endl;
    for(int i=0; i<N; i++)
        cout<<stu[i].number<<" "<<stu[i].name<<" "<<stu[i].score<<endl;
}
void Putbest()
{
    int best=0,x;
    for(int i=0; i<N; i++)
        if(stu[i].score>best)
        {
            x=i;
            best=stu[i].score;
        }
        cout<<"成绩最好的学生的信息为:";
        cout<<stu[x].number<<" "<<stu[x].name<<" "<<stu[x].score<<endl;
}
int main()
{
    cout<<"请输入这"<<N<<"名学生的信息:"<<endl;
    for(int i=0; i<N; i++)
        cin>>stu[i].number>>stu[i].name>>stu[i].score;
    Output();
    Putbest();
}

温馨提示:答案为网友推荐,仅供参考
相似回答