int main() { Student cs[N]; cs[0].input_lesson_ids();// 用一个学生对象对静态数组成员赋值 for(int i=0; i<N; i++) cs[i].input_info(); //求出最高平均成绩并按要求格式输出相关语句 float max_ave() //求出最低平均成绩并按要求格式输出相关语句 //按照平均成绩的高低对学生数组进行排序 for(int i=0; i<N; i++)//输出排序后的结果 cs[i].show_info(); return 0; }补全c++
时间: 2024-03-17 19:45:46 浏览: 69
代码如下:
```c++
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
const int N = 100;
class Student {
public:
string name;
int lesson_ids[5];
int scores[5];
float average_score;
void input_lesson_ids() {
for (int i = 0; i < 5; i++) {
cin >> lesson_ids[i];
}
}
void input_info() {
cin >> name;
for (int i = 0; i < 5; i++) {
cin >> scores[i];
average_score += scores[i];
}
average_score /= 5;
}
void show_info() {
cout << name << " ";
printf("%.2f", average_score);
cout << endl;
}
bool operator < (const Student& other) const {
return average_score > other.average_score;
}
};
int main() {
Student cs[N];
cs[0].input_lesson_ids();
for (int i = 0; i < N; i++) cs[i].input_info();
float max_ave = 0, min_ave = 101;
for (int i = 0; i < N; i++) {
max_ave = max(max_ave, cs[i].average_score);
min_ave = min(min_ave, cs[i].average_score);
}
cout << "the highest average score = ";
printf("%.2f", max_ave);
cout << endl;
cout << "the lowest average score = ";
printf("%.2f", min_ave);
cout << endl;
sort(cs, cs + N);
for (int i = 0; i < N; i++) cs[i].show_info();
return 0;
}
```
这段代码实现了一个学生信息管理系统,可以输入一些学生的姓名和五门课的成绩,计算并显示每个学生的平均成绩,并按照平均成绩的高低对学生数组进行排序,最后输出排序后的结果。
阅读全文