编写学生管理系统,其中学生的信息有姓名(汉语拼音,最多20个字符),性别(男/女,用1表示男,2表示女)、
生日(19850101(年月日))、身高(以m为单位),还需要处理C语言、微积分两门课的成绩,请编写程序实现功能:
输入学生的人数和每个学生的信息;输出每门课程的总平均成绩、最高分和最低分,以及获得最高分的学生的信息。
需要注意的是某门课程最高分的学生可能不只一人。
输入输出格式要求:
身高输出时保留两位小数,请按照例子中进行输出,请勿输出其他字符
例如:
输入:3 zhangsan 1 19910101 1.85 85 90 lisi 1 19920202 1.56 89 88 wangwu 2 19910303 1.6 89 90回车
输出:
C_average:87回车
C_max:89回车
lisi 1 19920202 1.56 89 88回车
wangwu 2 19910303 1.60 89 90回车
C_min:85回车
Calculus_average:89回车
Calculus_max:90回车
zhangsan 1 19910101 1.85 85 90回车
wangwu 2 19910303 1.60 89 90回车
Calculus_min:88回车
可以创建一个结构体,有需要时可以输出。平均分可以调用结构体,相加再除,最高分和最低分可以比较,最后输出。这是结构体
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct Student {
string name;
int gender;
string birthday;
double height;
int cScore;
int calculusScore;
};
void printStudentInfo(const Student& student) {
cout << student.name << " " << student.gender << " " << student.birthday << " " << fixed << setprecision(2) << student.height << " " << student.cScore << " " << student.calculusScore << endl;
}
int main() {
int numStudents;
cin >> numStudents;
vector<Student> students(numStudents);
for (int i = 0; i < numStudents; i++) {
cin >> students[i].name >> students[i].gender >> students[i].birthday >> students[i].height >> students[i].cScore >> students[i].calculusScore;
}
int cSum = 0;
int cMax = -1;
int cMin = INT_MAX;
int calculusSum = 0;
int calculusMax = -1;
int calculusMin = INT_MAX;
for (const Student& student : students) {
cSum += student.cScore;
calculusSum += student.calculusScore;
if (student.cScore > cMax) {
cMax = student.cScore;
}
if (student.cScore < cMin) {
cMin = student.cScore;
}
if (student.calculusScore > calculusMax) {
calculusMax = student.calculusScore;
}
if (student.calculusScore < calculusMin) {
calculusMin = student.calculusScore;
}
}
double cAverage = static_cast<double>(cSum) / numStudents;
double calculusAverage = static_cast<double>(calculusSum) / numStudents;
cout << "C_average:" << cAverage << endl;
cout << "C_max:" << cMax << endl;
for (const Student& student : students) {
if (student.cScore == cMax) {
printStudentInfo(student);
}
}
cout << "C_min:" << cMin << endl;
cout << "Calculus_average:" << calculusAverage << endl;
cout << "Calculus_max:" << calculusMax << endl;
for (const Student& student : students) {
if (student.calculusScore == calculusMax) {
printStudentInfo(student);
}
}
cout << "Calculus_min:" << calculusMin << endl;
return 0;
}
这个程序重要的是要会调用结构体,会函数
可以去技能树学习