大学C语言期末综合实验报告源码
学生成绩管理系统
- 编译运行以下源码。
- 等待几秒显示出运行窗口界面。
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/8a5502e160804bfc74c2ab6e0bc4b345.png#pic_center)
- 输入1然后回车,创建链表。依次输入学生人数,学号,姓名,各科成绩等。输入完成以后按任意键结束。如下图。
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/35844be7b077a7c28826f774ad492805.png#pic_center)
- 输入3然后回车。保存文件。显示保存成功。按任意键结束。如下图
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/14c280eeeafb0e02b69cfae3acfb6d05.png#pic_center)
- 输入2回车,查看数据。如下图。
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/4e5480bae5d2b7ab05bcc38be4d5b37d.png#pic_center)
- 输入5回车,退出系统。
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/9e5cc8d7f08fe0bc78a8ae2ab929bcd6.png#pic_center)
源码如下
#include "stdio.h"
#include "stdlib.h"
#include "conio.h"
int num;
struct xs
{
int xh;
char xm[20];
int gs,yy,wl;
double pj;
struct xs *next;
};
struct xs *create()
{
int i;
struct xs *p=NULL,*hd=(struct xs *)malloc(sizeof(struct xs));
hd->next=NULL;
printf("请输入学生人数:");
scanf("%d",&num);
for(i=1;i<=num;i++)
{
p=(struct xs *)malloc(sizeof(struct xs));
printf("请输入第%d个学生%d-%d\n",i,num,i);
printf("学号:");
scanf("%d",&p->xh);
printf("姓名:");
scanf("%s",p->xm);
printf("高数:");
scanf("%d",&p->gs);
printf("英语:");
scanf("%d",&p->yy);
printf("物理:");
scanf("%d",&p->wl);
p->pj=(p->gs+p->yy+p->wl)/3.0;
p->next=hd->next;
hd->next=p;
}
printf("创建结束,请按任意键结束!\n");
getch();
return hd;
}
void print(struct xs *hd)
{
if(hd==NULL)
{
printf("链表为空,请先创建链表或读取文件,按任意键继续!\n");
getch();
}
else
{
struct xs *p=hd->next;
printf("*********************************************************\n");
printf(" 学号 姓名 高数 英语 物理 平均 \n");
printf("*********************************************************\n");
while(p!=NULL)
{
printf("%4d %-6s %5d %5d %5d %5.2f\n",p->xh,p->xm,p->gs,p->yy,p->wl,p->pj);
p=p->next;
}
printf("*********************************************************\n");
printf("显示结束,请按任意键继续!\n");
getch();
}
}
void sf(struct xs *hd)
{
if(hd!=NULL)
{
struct xs *p=hd->next;
while(p!=NULL)
{
hd->next=p->next;
free(p);
p=hd->next;
}
free(hd);
}
}
void save(struct xs *hd)
{
if(hd==NULL)
{
printf("链表为空,不能保存文件,请按任意键继续!\n");
getch();
}
else
{
FILE *fp=fopen("1.txt","w");
struct xs *p=hd->next;
fprintf(fp,"%d\n",num);
while(p!=NULL)
{
fprintf(fp,"%d %s %d %d %d %lf\n",p->xh,p->xm,p->gs,p->yy,p->wl,p->pj);
p=p->next;
}
fclose(fp);
printf("链表保存结束,请按任意键继续!\n");
getch();
}
}
struct xs *read()
{
FILE *fp=fopen("1.txt","r");
if(fp!=NULL)
{
int rs,i;
struct xs *p=NULL,*hd=(struct xs *)malloc(sizeof(struct xs));
hd->next=NULL;
fscanf(fp,"%d\n",&rs);
for(i=1;i<=rs;i++)
{
p=(struct xs *)malloc(sizeof(struct xs));
fscanf(fp,"%d %s %d %d %d %lf\n",&p->xh,p->xm,&p->gs,&p->yy,&p->wl,&p->pj);
p->next=hd->next;
hd->next=p;
}
fclose(fp);
printf("文件读取结束,请按任意键继续!\n");
getch();
return hd;
}
else
{
printf("没有数据文件,请先保存文件,按任意键继续!\n");
getch();
return NULL;
}
}
void menu()
{
system("cls");
printf("*****************************************\n");
printf("* 学生管理系统(1.0) *\n");
printf("*****************************************\n");
printf("* *\n");
printf("*****************************************\n");
printf("** 1-创建链表 **\n");
printf("** 2-数据显示 **\n");
printf("** 3-保存文件 **\n");
printf("** 4-读取文件 **\n");
printf("** 5-系统退出 **\n");
printf("*****************************************\n");
printf("** 请选择操作(1-5) **\n");
printf("*****************************************\n");
}
void main()
{
struct xs *head=NULL;
int xz=0;
while(xz!=5)
{
menu();
scanf("%d",&xz);
switch(xz)
{
case 1:sf(head);head=create();break;
case 2:print(head);break;
case 3:save(head);break;
case 4:sf(head);head=read();break;
case 5:sf(head);break;
}
}
}