C语言实现了学生成绩管理系统,可以进行学生成绩的增加,删除,修改,查询,计算平均成绩和展示。
开发语言:C语言
开发工具:Dev c++
开发者:呵呵up
- 创建学生成绩信息

2. 插入学生信息

3. 删除学生成绩信息

4. 显示学生成绩信息

5. 修改学生信息

6. 查询学生成绩信息

7. 计算平均成绩信息

8. 退出程序

代码如下:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
typedef struct stu
{int num;char name[10];float score;
}STU;
typedef struct node
{STU data;struct node *next;
}Node;
Node *listcreate(Node *head,int people) //创建链表,创建学生信息
{int i;Node *p=NULL,*q=NULL;p=head;for(i=1;i<=people;i++){printf("\n请输入第%d个学生的信息:\n",i);q=(Node *)malloc(sizeof(Node));printf("请输入学生信息:\n");printf("学号:");scanf("%d",&q->data.num);printf("姓名:");scanf("%s",q->data.name);printf("成绩:");scanf("%f",&q->data.score);q->next=NULL;p->next=q;p=q;}p->next=NULL;return head;
}
Node *listinsert(Node *head,int i) //插入学生信息
{int j=-1;Node *p=head,*q;q=(Node *)malloc(sizeof(Node));q->next=NULL;printf("请输入学生信息:\n");printf("学号:");scanf("%d",&q->data.num);printf("姓名:");scanf("%s",q->data.name);printf("成绩:");scanf("%f",&q->data.score);while(p!=NULL){j++;if(j==i-1){break;}p=p->next;}q->next=p->next;p->next=q;return head;
}
Node *listreplace(Node *head,int i) //根据学号修改学生成绩
{Node *p=head->next;while(p!=NULL){if(p->data.num==i){printf("请输入修改后的学生信息:\n");printf("请输入学号:");scanf("%d",&p->data.num);printf("请输入姓名:");scanf("%s",p->data.name);printf("请输入成绩:");scanf("%f",&p->data.score);}p=p->next; }return head;
}
Node *listseek(Node *head,int i) //根据学号查询某个学生信息
{Node *p=head->next;while(p!=NULL){if(p->data.num==i){printf("查询成功\n");printf("学号为%d的学生信息如下:\n",p->data.num);printf("学号为:%d\n",p->data.num);printf("姓名为:%s\n",p->data.name);printf("成绩为:%.2f\n",p->data.score);}p=p->next;} return head;
}
Node *listaverage(Node *head) //计算学生的平均成绩信息
{int i;float sum=0,ave;Node *p;p=head->next;for(i=0;p!=NULL;i++){sum+=p->data.score; p=p->next;}ave=sum/i;printf("学生的平均成绩信息为:%.2f\n",ave);return head;
}
Node *listdelete(Node *head,int i) //删除学生信息
{int j=-1;Node *p=head,*q;q=(Node *)malloc(sizeof(Node));q->next=NULL;while(p!=NULL){j++;if(j==i-1){break;}p=p->next; }q=p->next;p->next=q->next;free(q);return head;
}
Node *listplay(Node *head) //显示学生信息
{Node *p;p=head->next;printf("班级学生信息如下:\n");printf(" 学号 姓名 成绩\n");while(p!=NULL){printf("%10d%10s%10.2f\n",p->data.num,p->data.name,p->data.score);p=p->next;}
}
void showmenu() //界面菜单函数
{printf("******欢迎使用学生成绩管理系统******\n");printf("\t1,创建学生信息\n");printf("\t2,插入学生信息\n");printf("\t3,删除学生信息\n");printf("\t4,显示学生信息\n");printf("\t5,修改学生信息\n");printf("\t6,查询学生信息\n");printf("\t7,计算平均成绩信息\n"); printf("\t8,退出程序\n");
}
void main() //主函数
{Node *head=NULL;int i,stu,pos;head=(Node *)malloc(sizeof(Node));head->next=NULL;while(1){showmenu();printf(" 请输入你的选择:");scanf("%d",&i);switch(i){case 1: printf("请输入班级学生人数:");scanf("%d",&stu);head=listcreate(head,stu);system("cls");showmenu();listplay(head);printf("班级初始化已完成,按任意键继续。。。");getch();system("cls");break;case 2: printf("插入班级前的学生信息:\n");listplay(head);printf("请输入需要插入的位置:\n");scanf("%d",&pos);head=listinsert(head,pos);printf("插入后班级信息:\n");listplay(head);printf("插入已完成,按任意键继续。。。。\n");getch();system("cls"); break;case 3: printf("删除前的学生信息:\n");listplay(head);printf("请输入需要删除的位置:\n");scanf("%d",&pos);head=listdelete(head,pos);printf("删除班级信息:\n");listplay(head);printf("删除已完成,按任意键继续。。。。\n");getch();system("cls"); break;case 4: listplay(head);printf("显示信息如上所示,按任意键继续。。。\n");getch();system("cls");break;case 5: listplay(head);printf("请输入需要修改的学生信息学号:\n");scanf("%d",&pos);head=listreplace(head,pos);printf("修改后班级信息:\n");listplay(head);printf("修改已完成,按任意键继续。。。\n");getch();system("cls");break; case 6: printf("请输入需要查询的学生信息学号:\n");scanf("%d",&pos);head=listseek(head,pos);printf("查询信息已完成,按任意键继续。。。\n");getch();system("cls");break;case 7: head=listaverage(head);printf("计算学生平均成绩信息已完成,按任意键继续。。。\n");getch();system("cls");break;case 8: return;}}
}















