一、 简易 学生成绩 管理 要求 用 C++语言 设计程序 设计实现 学生成绩管理系统的 应用程序 程序 具 体要求 如下: 通过二维数组构建学生的成绩单 学号 语文 数学 英语 物理 化学 生物 101 96 79 88 77 76 83 102 79 82 86 82 67 91 103 83 98 95 92 93 88 104 92 82 78 89 81 79 105 87 95 91 85 87 75 程序包含的功能: 1、 输入 学号和 科目名称 (如语文、数学等)查询所有同学该科门科目的平 均成绩以及该生该门科目的排名。 2、 输入 学号 ,输出所有 同学根据总成绩的排名,并输出该学号的排名。 3、 输入学号、科目名称、修改的成绩分数对成绩单中成绩进行修改。 4、程序在最开始可以选择想执行的业务选项。 其它要求: 除程序能够正确运行外,还要求程序具有友好的用户交互界面, 能够对错误输入进行处理 (比如对输入金额验证,输入 id的唯一性验证,输入 超长字符的验证) 具备良好的性能, 程序要求具有良好的注释和代码美观性。
时间: 2023-12-06 09:41:10 浏览: 54
下面是一个简单的学生成绩管理系统的 C++ 程序:
```cpp
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
const int MAX_STUDENTS = 5;
const int MAX_SUBJECTS = 6;
string subject_names[MAX_SUBJECTS] = {"语文", "数学", "英语", "物理", "化学", "生物"};
int scores[MAX_STUDENTS][MAX_SUBJECTS] = {
{101, 96, 79, 88, 77, 76, 83},
{102, 79, 82, 86, 82, 67, 91},
{103, 83, 98, 95, 92, 93, 88},
{104, 92, 82, 78, 89, 81, 79},
{105, 87, 95, 91, 85, 87, 75}
};
void print_menu() {
cout << "请选择要执行的业务选项:" << endl;
cout << "1. 输入学号和科目名称查询平均成绩和排名" << endl;
cout << "2. 输入学号查询总成绩排名" << endl;
cout << "3. 输入学号、科目名称和修改的成绩分数修改成绩" << endl;
cout << "4. 退出程序" << endl;
}
int get_student_index(int student_id) {
for (int i = 0; i < MAX_STUDENTS; i++) {
if (scores[i][0] == student_id) {
return i;
}
}
return -1;
}
int get_subject_index(string subject_name) {
for (int i = 0; i < MAX_SUBJECTS; i++) {
if (subject_names[i] == subject_name) {
return i;
}
}
return -1;
}
double get_average_score(int student_index, int subject_index) {
double sum = 0;
for (int i = 1; i < MAX_SUBJECTS; i++) {
sum += scores[student_index][i];
}
return sum / (MAX_SUBJECTS - 1);
}
int get_rank(int student_index) {
int rank = 1;
for (int i = 0; i < MAX_STUDENTS; i++) {
if (i != student_index && scores[i][MAX_SUBJECTS-1] > scores[student_index][MAX_SUBJECTS-1]) {
rank++;
}
}
return rank;
}
int main() {
int choice;
do {
print_menu();
cin >> choice;
switch (choice) {
case 1: {
int student_id;
string subject_name;
cout << "请输入学号和科目名称(中间用空格隔开):";
cin >> student_id >> subject_name;
int student_index = get_student_index(student_id);
int subject_index = get_subject_index(subject_name);
if (student_index == -1 || subject_index == -1) {
cout << "输入有误,请重新输入!" << endl;
break;
}
double avg_score = get_average_score(student_index, subject_index);
int rank = 1;
for (int i = 0; i < MAX_STUDENTS; i++) {
if (i != student_index && scores[i][subject_index] > scores[student_index][subject_index]) {
rank++;
}
}
cout << student_id << "的" << subject_name << "平均成绩为:" << fixed << setprecision(2) << avg_score << endl;
cout << student_id << "的" << subject_name << "排名为:" << rank << endl;
break;
}
case 2: {
int student_id;
cout << "请输入学号:";
cin >> student_id;
int student_index = get_student_index(student_id);
if (student_index == -1) {
cout << "输入有误,请重新输入!" << endl;
break;
}
int rank = get_rank(student_index);
cout << student_id << "的总成绩排名为:" << rank << endl;
break;
}
case 3: {
int student_id, subject_score;
string subject_name;
cout << "请输入学号、科目名称和修改的成绩分数(中间用空格隔开):";
cin >> student_id >> subject_name >> subject_score;
int student_index = get_student_index(student_id);
int subject_index = get_subject_index(subject_name);
if (student_index == -1 || subject_index == -1) {
cout << "输入有误,请重新输入!" << endl;
break;
}
scores[student_index][subject_index] = subject_score;
cout << "修改成功!" << endl;
break;
}
case 4: {
cout << "谢谢使用!" << endl;
break;
}
default: {
cout << "输入有误,请重新输入!" << endl;
break;
}
}
} while (choice != 4);
return 0;
}
```
这个程序使用二维数组存储学生成绩单,其中第一列是学号,后面的列是各科成绩。程序提供了三个功能:输入学号和科目名称查询平均成绩和排名、输入学号查询总成绩排名、输入学号、科目名称和修改的成绩分数修改成绩。程序采用了友好的用户交互界面,并对错误输入进行了处理。