C语言期末实验报告(学生成绩管理系统)源码

大学C语言期末综合实验报告源码

学生成绩管理系统

  1. 编译运行以下源码。
  2. 等待几秒显示出运行窗口界面。
    在这里插入图片描述
  3. 输入1然后回车,创建链表。依次输入学生人数,学号,姓名,各科成绩等。输入完成以后按任意键结束。如下图。
    在这里插入图片描述
  4. 输入3然后回车。保存文件。显示保存成功。按任意键结束。如下图
    在这里插入图片描述
  5. 输入2回车,查看数据。如下图。
    在这里插入图片描述
  6. 输入5回车,退出系统。
    在这里插入图片描述

源码如下

#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;   
	  }
   }
}

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yanbeide

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值