学生成绩管理系统c++
时间: 2023-07-27 17:06:35 浏览: 35
下面是一个简单的学生成绩管理系统的C++代码示例:
cpp
Copy code
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct Student {
string name;
int score;
};
void addStudent(vector<Student>& students) {
string name;
int score;
cout << "Enter student name: ";
cin >> name;
cout << "Enter student score: ";
cin >> score;
Student student = { name, score };
students.push_back(student);
cout << "Student added successfully!\n";
}
void displayStudents(const vector<Student>& students) {
cout << "Student List:\n";
for (const auto& student : students) {
cout << "Name: " << student.name << ", Score: " << student.score << endl;
}
}
int main() {
vector<Student> students;
int choice;
while (true) {
cout << "1. Add Student\n";
cout << "2. Display Students\n";
cout << "3. Exit\n";
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case 1:
addStudent(students);
break;
case 2:
displayStudents(students);
break;
case 3:
cout << "Exiting the program. Goodbye!\n";
return 0;
default:
cout << "Invalid choice. Please try again.\n";
break;
}
}
return 0;
}
这段代码实现了一个简单的学生成绩管理系统。它使用struct定义了一个Student结构体,包含学生的姓名和分数。在主函数中,使用一个无限循环来提供菜单选项,用户可以选择添加学生或显示学生列表。使用vector容器来存储学生信息。
在添加学生函数addStudent中,用户可以输入学生的姓名和分数,然后创建一个Student对象并将其添加到学生列表中。
在显示学生列表函数displayStudents中,遍历学生列表并打印每个学生的姓名和分数。
请注意,这只是一个简单的示例代码,可能需要根据具体需求进行扩展和改进,如添加成绩计算、搜索功能等。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![dll](https://img-home.csdnimg.cn/images/20210720083646.png)
![md](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)