请写一个成绩管理系统,用链表实现
时间: 2023-06-23 21:09:03 浏览: 68
好的,以下是一个简单的成绩管理系统,使用链表实现:
```c++
#include<iostream>
#include<string>
using namespace std;
// 定义学生结构体
struct Student{
string name; // 学生名字
int score; // 学生成绩
Student* next; // 指向下一个学生的指针
};
// 插入学生节点
void insert(Student* head, string name, int score){
Student* p = head;
while(p->next != NULL){
p = p->next;
}
Student* newStudent = new Student;
newStudent->name = name;
newStudent->score = score;
newStudent->next = NULL;
p->next = newStudent;
}
// 显示学生信息
void display(Student* head){
Student* p = head->next;
while(p != NULL){
cout << "name: " << p->name << ", score: " << p->score << endl;
p = p->next;
}
}
int main(){
// 创建头节点
Student* head = new Student;
head->next = NULL;
// 插入学生信息
insert(head, "张三", 90);
insert(head, "李四", 80);
insert(head, "王五", 70);
// 显示学生信息
display(head);
return 0;
}
```
在这个程序中,我们定义了一个 `Student` 结构体,它包含了学生的名字、成绩和指向下一个学生的指针。我们使用 `insert()` 函数插入学生节点,使用 `display()` 函数显示学生信息。在 `main()` 函数中,我们创建了一个头节点,并插入了三个学生的信息。然后,我们调用 `display()` 函数显示学生信息。