问题描述:设学生信息包括:学号、姓名、期末成绩、平时成绩,对学生的学习成绩信息进行管理。 设计要求: 实现学生信息的录入、修改、插入、删除、查询、计算总评成绩、根据总评程序排序和划分等级、按学号查询学生成绩等。 (1)从文件输入学生的成绩信息,包含学号、姓名、期末成绩和平时成绩; (2)显示全部学生成绩信息; (3)更新某个学生的基本信息或课程成绩; (4)对成绩统计分析(总分、平均分、最高分、最低分、及格率等);(5)学号查找并显示某个学生的成绩;(6)按姓名查找并显示某个学生的成绩;(7)按总评成绩由高到低排序显示;(8)统计各分数段人数并显示; (9)设计一个菜单,具有上述规定的操作要求、退出系统等最基本的功能。(全部功能在devc++中一个程序实现)
时间: 2023-12-19 18:06:33 浏览: 142
这是一个典型的学生信息管理系统,可以使用C++语言实现。下面是一个简单的实现示例:
```
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
struct Student {
string id;
string name;
double final_score;
double regular_score;
double total_score;
char level;
};
vector<Student> students;
void load_data(string filename) {
ifstream fin(filename);
if (!fin.is_open()) {
cout << "Failed to open file " << filename << endl;
return;
}
students.clear();
while (!fin.eof()) {
Student s;
fin >> s.id >> s.name >> s.final_score >> s.regular_score;
s.total_score = s.final_score * 0.6 + s.regular_score * 0.4;
students.push_back(s);
}
fin.close();
}
void save_data(string filename) {
ofstream fout(filename);
if (!fout.is_open()) {
cout << "Failed to open file " << filename << endl;
return;
}
for (int i = 0; i < students.size(); i++) {
Student s = students[i];
fout << s.id << " " << s.name << " " << s.final_score << " " << s.regular_score << endl;
}
fout.close();
}
void display_all() {
cout << "ID\tName\tFinal\tRegular\tTotal\tLevel" << endl;
for (int i = 0; i < students.size(); i++) {
Student s = students[i];
cout << s.id << "\t" << s.name << "\t" << s.final_score << "\t" << s.regular_score << "\t"
<< s.total_score << "\t" << s.level << endl;
}
}
void update_student() {
string id;
cout << "Enter the student ID to update: ";
cin >> id;
for (int i = 0; i < students.size(); i++) {
if (students[i].id == id) {
cout << "Enter new name: ";
cin >> students[i].name;
cout << "Enter new final score: ";
cin >> students[i].final_score;
cout << "Enter new regular score: ";
cin >> students[i].regular_score;
students[i].total_score = students[i].final_score * 0.6 + students[i].regular_score * 0.4;
return;
}
}
cout << "No such student found." << endl;
}
void calculate_statistics() {
double total = 0, average = 0, max_score = 0, min_score = 100;
int pass_count = 0, fail_count = 0;
for (int i = 0; i < students.size(); i++) {
Student s = students[i];
total += s.total_score;
if (s.total_score >= 60) {
pass_count++;
} else {
fail_count++;
}
if (s.total_score > max_score) {
max_score = s.total_score;
}
if (s.total_score < min_score) {
min_score = s.total_score;
}
}
average = total / students.size();
cout << "Total: " << total << endl;
cout << "Average: " << average << endl;
cout << "Highest score: " << max_score << endl;
cout << "Lowest score: " << min_score << endl;
cout << "Pass count: " << pass_count << endl;
cout << "Fail count: " << fail_count << endl;
}
void find_by_id() {
string id;
cout << "Enter the student ID to search: ";
cin >> id;
for (int i = 0; i < students.size(); i++) {
if (students[i].id == id) {
Student s = students[i];
cout << "ID\tName\tFinal\tRegular\tTotal\tLevel" << endl;
cout << s.id << "\t" << s.name << "\t" << s.final_score << "\t" << s.regular_score << "\t"
<< s.total_score << "\t" << s.level << endl;
return;
}
}
cout << "No such student found." << endl;
}
void find_by_name() {
string name;
cout << "Enter the student name to search: ";
cin >> name;
for (int i = 0; i < students.size(); i++) {
if (students[i].name == name) {
Student s = students[i];
cout << "ID\tName\tFinal\tRegular\tTotal\tLevel" << endl;
cout << s.id << "\t" << s.name << "\t" << s.final_score << "\t" << s.regular_score << "\t"
<< s.total_score << "\t" << s.level << endl;
}
}
}
void sort_by_total_score() {
sort(students.begin(), students.end(), [](const Student &a, const Student &b) {
return a.total_score > b.total_score;
});
display_all();
}
void count_level() {
int level_A = 0, level_B = 0, level_C = 0, level_D = 0, level_E = 0;
for (int i = 0; i < students.size(); i++) {
if (students[i].total_score >= 90) {
level_A++;
students[i].level = 'A';
} else if (students[i].total_score >= 80) {
level_B++;
students[i].level = 'B';
} else if (students[i].total_score >= 70) {
level_C++;
students[i].level = 'C';
} else if (students[i].total_score >= 60) {
level_D++;
students[i].level = 'D';
} else {
level_E++;
students[i].level = 'E';
}
}
cout << "A: " << level_A << endl;
cout << "B: " << level_B << endl;
cout << "C: " << level_C << endl;
cout << "D: " << level_D << endl;
cout << "E: " << level_E << endl;
}
void menu() {
while (true) {
cout << "1. Load data" << endl;
cout << "2. Save data" << endl;
cout << "3. Display all data" << endl;
cout << "4. Update student information" << endl;
cout << "5. Calculate statistics" << endl;
cout << "6. Find student by ID" << endl;
cout << "7. Find student by name" << endl;
cout << "8. Sort by total score" << endl;
cout << "9. Count level" << endl;
cout << "0. Exit" << endl;
int option;
cin >> option;
switch (option) {
case 1:
load_data("students.txt");
break;
case 2:
save_data("students.txt");
break;
case 3:
display_all();
break;
case 4:
update_student();
break;
case 5:
calculate_statistics();
break;
case 6:
find_by_id();
break;
case 7:
find_by_name();
break;
case 8:
sort_by_total_score();
break;
case 9:
count_level();
break;
case 0:
return;
default:
cout << "Invalid option." << endl;
}
}
}
int main() {
menu();
return 0;
}
```
注意,这只是一个简单的实现示例,实际应用中可能需要更多的功能和更完善的错误处理。
阅读全文