大一c语言学生成绩管理系统代码
时间: 2023-12-25 18:30:35 浏览: 130
很高兴为您介绍大一C语言学生成绩管理系统的代码。根据引用内容,该系统主要使用了循环语句、函数、结构体和链表存储数据,并实现了学生信息录入、学生单个信息查询、查询全部学生信息、修改学生信息、删除学生信息和退出系统等功能。
以下是一个简单的示例代码:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// 定义学生结构体
typedef struct {
char name[20];
int id;
float score;
} Student;
// 定义链表节点结构体
typedef struct Node {
Student data;
struct Node* next;
} Node;
// 全局变量,指向链表头节点
Node* head = NULL;
// 添加学生信息
void addStudent() {
Node* newNode = (Node*)malloc(sizeof(Node));
printf("请输入学生姓名:");
scanf("%s", newNode->data.name);
printf("请输入学生学号:");
scanf("%d", &(newNode->data.id));
printf("请输入学生成绩:");
scanf("%f", &(newNode->data.score));
newNode->next = NULL;
if (head == NULL) {
head = newNode;
} else {
Node* temp = head;
while (temp->next != NULL) {
temp = temp->next;
}
temp->next = newNode;
}
printf("学生信息添加成功!\n");
}
// 查询单个学生信息
void searchStudent() {
int id;
printf("请输入要查询的学生学号:");
scanf("%d", &id);
Node* temp = head;
while (temp != NULL) {
if (temp->data.id == id) {
printf("学生姓名:%s\n", temp->data.name);
printf("学生学号:%d\n", temp->data.id);
printf("学生成绩:%.2f\n", temp->data.score);
return;
}
temp = temp->next;
}
printf("未找到该学生信息!\n");
}
// 查询全部学生信息
void searchAllStudents() {
if (head == NULL) {
printf("暂无学生信息!\n");
return;
}
Node* temp = head;
while (temp != NULL) {
printf("学生姓名:%s\n", temp->data.name);
printf("学生学号:%d\n", temp->data.id);
printf("学生成绩:%.2f\n", temp->data.score);
printf("--\n");
temp = temp->next;
}
}
// 修改学生信息
void modifyStudent() {
int id;
printf("请输入要修改的学生学号:");
scanf("%d", &id);
Node* temp = head;
while (temp != NULL) {
if (temp->data.id == id) {
printf("请输入学生姓名:");
scanf("%s", temp->data.name);
printf("请输入学生成绩:");
scanf("%f", &(temp->data.score));
printf("学生信息修改成功!\n");
return;
}
temp = temp->next;
}
printf("未找到该学生信息!\n");
}
// 删除学生信息
void deleteStudent() {
int id;
printf("请输入要删除的学生学号:");
scanf("%d", &id);
if (head == NULL) {
printf("暂无学生信息!\n");
return;
}
Node* temp = head;
Node* prev = NULL;
while (temp != NULL) {
if (temp->data.id == id) {
if (prev == NULL) {
head = temp->next;
} else {
prev->next = temp->next;
}
free(temp);
printf("学生信息删除成功!\n");
return;
}
prev = temp;
temp = temp->next;
}
printf("未找到该学生信息!\n");
}
// 释放链表内存
void freeList() {
Node* temp = head;
while (temp != NULL) {
Node* nextNode = temp->next;
free(temp);
temp = nextNode;
}
}
int main() {
int choice;
while (1) {
printf("学生成绩管理系统\n");
printf("1. 添加学生信息\n");
printf("2. 查询单个学生信息\n");
printf("3. 查询全部学生信息\n");
printf("4. 修改学生信息\n");
printf("5. 删除学生信息\n");
printf("6. 退出系统\n");
printf("请输入您的选择:");
scanf("%d", &choice);
switch (choice) {
case 1:
addStudent();
break;
case 2:
searchStudent();
break;
case 3:
searchAllStudents();
break;
case 4:
modifyStudent();
break;
case 5:
deleteStudent();
break;
case 6:
freeList();
printf("感谢使用学生成绩管理系统,再见!\n");
return 0;
default:
printf("无效的选择,请重新输入!\n");
break;
}
}
return 0;
}
```
请注意,这只是一个简单的示例代码,可能还有其他功能和优化的空间。您可以根据自己的需求进行修改和扩展。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)