学生成绩管理系统c语言vs2012
时间: 2023-12-19 20:31:56 浏览: 33
以下是使用C语言和VS2012实现学生成绩管理系统的步骤和代码示例:
1. 创建一个新的控制台应用程序项目。
2. 在项目中创建一个名为“student”的结构体,包含学生的姓名、学号和成绩等信息。
3. 创建一个数组来存储学生信息,可以使用动态内存分配来实现。
4. 实现录入学生信息的函数,可以使用scanf()函数来获取用户输入的信息。
5. 实现查询学生信息的函数,可以使用循环遍历数组来查找学生信息。
6. 实现修改学生信息的函数,可以使用指针来修改学生信息。
7. 实现删除学生信息的函数,可以使用指针来删除学生信息。
8. 实现计算学生平均分和总分的函数。
9. 实现展示学生信息的函数,可以使用循环遍历数组来展示学生信息。
10. 在main()函数中调用上述函数,实现学生成绩管理系统。
以下是示例代码:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct student {
char name[20];
char num[10];
int score;
} Student;
void input(Student *students, int n) {
for (int i = 0; i < n; i++) {
printf("请输入第%d个学生的姓名、学号和成绩:\n", i + 1);
scanf("%s%s%d", students[i].name, students[i].num, &students[i].score);
}
}
void query(Student *students, int n) {
char num[10];
printf("请输入要查询的学生学号:\n");
scanf("%s", num);
for (int i = 0; i < n; i++) {
if (strcmp(students[i].num, num) == 0) {
printf("姓名:%s 学号:%s 成绩:%d\n", students[i].name, students[i].num, students[i].score);
return;
}
}
printf("未找到该学生信息!\n");
}
void modify(Student *students, int n) {
char num[10];
printf("请输入要修改的学生学号:\n");
scanf("%s", num);
for (int i = 0; i < n; i++) {
if (strcmp(students[i].num, num) == 0) {
printf("请输入修改后的学生姓名、学号和成绩:\n");
scanf("%s%s%d", students[i].name, students[i].num, &students[i].score);
printf("修改成功!\n");
return;
}
}
printf("未找到该学生信息!\n");
}
void del(Student *students, int *n) {
char num[10];
printf("请输入要删除的学生学号:\n");
scanf("%s", num);
for (int i = 0; i < *n; i++) {
if (strcmp(students[i].num, num) == 0) {
for (int j = i; j < *n - 1; j++) {
students[j] = students[j + 1];
}
(*n)--;
printf("删除成功!\n");
return;
}
}
printf("未找到该学生信息!\n");
}
void calc(Student *students, int n) {
int sum = 0;
for (int i = 0; i < n; i++) {
sum += students[i].score;
}
printf("总分:%d 平均分:%d\n", sum, sum / n);
}
void show(Student *students, int n) {
for (int i = 0; i < n; i++) {
printf("姓名:%s 学号:%s 成绩:%d\n", students[i].name, students[i].num, students[i].score);
}
}
int main() {
int n;
printf("请输入学生人数:\n");
scanf("%d", &n);
Student *students = (Student *)malloc(n * sizeof(Student));
input(students, n);
while (1) {
printf("请选择操作:\n");
printf("1.查询学生信息\n");
printf("2.修改学生信息\n");
printf("3.删除学生信息\n");
printf("4.计算学生平均分和总分\n");
printf("5.展示学生信息\n");
printf("6.退出程序\n");
int choice;
scanf("%d", &choice);
switch (choice) {
case 1:
query(students, n);
break;
case 2:
modify(students, n);
break;
case 3:
del(students, &n);
break;
case 4:
calc(students, n);
break;
case 5:
show(students, n);
break;
case 6:
free(students);
return 0;
default:
printf("输入有误,请重新输入!\n");
}
}
return 0;
}
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)