You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <iostream>
#include <vector>
#include <string>
using namespace std;
struct Student {
string name;
int id;
float score;
};
vector<Student> students;
void inputData() {
Student student;
cout << "请输入学生姓名:";
cin >> student.name;
cout << "请输入学生学号:";
cin >> student.id;
cout << "请输入学生成绩:";
cin >> student.score;
students.push_back(student);
cout << "录入成功!" << endl;
}
void modifyOrDeleteData() {
int id;
cout << "请输入要修改/删除的学生学号:";
cin >> id;
for (auto it = students.begin(); it != students.end(); ++it) {
if (it->id == id) {
cout << "学生姓名:" << it->name << ",学号:" << it->id << ",成绩:" << it->score << endl;
cout << "请输入新的成绩(输入-1表示删除该学生信息";
float newScore;
cin >> newScore;
if (newScore == -1) {
students.erase(it);
cout << "删除成功!" << endl;
} else {
it->score = newScore;
cout << "修改成功!" << endl;
}
return;
}
}
cout << "未找到该学生信息!" << endl;
}
void viewStatistics() {
float totalScore = 0;
for (const auto& student : students) {
totalScore += student.score;
}
float averageScore = students.empty() ? 0 : totalScore / students.size();
cout << "学生人数:" << students.size() << ",总成绩:" << totalScore << ",平均成绩:" << averageScore << endl;
}
int main() {
while (true) {
cout << "学生成绩信息管理系统菜单:" << endl;
cout << "1. 数据录入" << endl;
cout << "2. 数据修改/删除" << endl;
cout << "3. 统计查看" << endl;
cout << "4. 退出系统" << endl;
cout << "请选择功能编号:";
int choice;
cin >> choice;
switch (choice) {
case 1:
inputData();
break;
case 2:
modifyOrDeleteData();
break;
case 3:
viewStatistics();
break;
case 4:
cout << "感谢使用!" << endl;
return 0;
default:
cout << "无效的功能编号!" << endl;
}
}
return 0;
}