用c语言设计学生成绩管理系统,怎么写
时间: 2023-06-19 21:07:51 浏览: 143
设计学生成绩管理系统,需要考虑以下几个方面:
1. 数据结构:需要定义学生信息的结构体,包括学号、姓名、成绩等信息。
2. 数据存储:可以使用文件存储学生信息,也可以使用内存数据结构存储。
3. 功能实现:需要实现添加学生信息、删除学生信息、修改学生成绩、查询学生成绩等功能。
下面是一个简单的 C 语言学生成绩管理系统的实现代码:
```
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define Max 100
struct student
{
char name[20];
int num;
float score;
}stu[Max];
int n;
void add();
void del();
void modify();
void query();
void display();
int main()
{
int choice;
while(1)
{
printf("\n");
printf("|-----------------Student Grade Manage System-----------------|\n");
printf("| 1.Add a record |\n");
printf("| 2.Delete a record |\n");
printf("| 3.Modify a record |\n");
printf("| 4.Query a record |\n");
printf("| 5.Display all records |\n");
printf("| 6.Exit |\n");
printf("|------------------------------------------------------------|\n");
printf("Please enter your choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:
add();
break;
case 2:
del();
break;
case 3:
modify();
break;
case 4:
query();
break;
case 5:
display();
break;
case 6:
printf("You have exited the system!");
exit(0);
default:
printf("Invalid input!");
}
}
return 0;
}
void add() //添加学生记录
{
int i;
printf("Please enter the number of students to be added:");
scanf("%d",&n);
for(i=0; i<n; i++)
{
printf("Please enter the information of student %d:\n",i+1);
printf("Student name:");
scanf("%s",stu[i].name);
printf("Student number:");
scanf("%d",&stu[i].num);
printf("Student score:");
scanf("%f",&stu[i].score);
}
printf("Add successfully!\n");
}
void del() //删除学生记录
{
int i,j,num;
printf("Please enter the student number you want to delete:");
scanf("%d",&num);
for(i=0; i<n; i++)
{
if(stu[i].num==num)
{
for(j=i; j<n-1; j++)
{
stu[j]=stu[j+1];
}
n--;
printf("Delete successfully!\n");
return;
}
}
printf("The student is not in the record!\n");
}
void modify() //修改学生成绩
{
int i,num;
printf("Please enter the student number you want to modify:");
scanf("%d",&num);
for(i=0; i<n; i++)
{
if(stu[i].num==num)
{
printf("Please enter the new score:");
scanf("%f",&stu[i].score);
printf("Modify successfully!\n");
return;
}
}
printf("The student is not in the record!\n");
}
void query() //查询学生成绩
{
int i,num;
printf("Please enter the student number you want to query:");
scanf("%d",&num);
for(i=0; i<n; i++)
{
if(stu[i].num==num)
{
printf("Student name:%s\n",stu[i].name);
printf("Student number:%d\n",stu[i].num);
printf("Student score:%.2f\n",stu[i].score);
return;
}
}
printf("The student is not in the record!\n");
}
void display() //显示所有学生记录
{
int i;
printf("All student records are as follows:\n");
for(i=0; i<n; i++)
{
printf("Student name:%s ",stu[i].name);
printf("Student number:%d ",stu[i].num);
printf("Student score:%.2f\n",stu[i].score);
}
}
```
注意:这是一个简单的实现,数据存储使用内存数据结构,没有进行文件操作。实际应用中,需要根据具体需求进行修改。
阅读全文