#include #include #include using namespace std; struct Student { string name; int id; float score; }; vector 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; }