学生成绩管理系统链表版C代码包含所有功能适合初学者借鉴.docx
- 文档编号:236734
- 上传时间:2022-10-07
- 格式:DOCX
- 页数:15
- 大小:14.81KB
学生成绩管理系统链表版C代码包含所有功能适合初学者借鉴.docx
《学生成绩管理系统链表版C代码包含所有功能适合初学者借鉴.docx》由会员分享,可在线阅读,更多相关《学生成绩管理系统链表版C代码包含所有功能适合初学者借鉴.docx(15页珍藏版)》请在冰豆网上搜索。
#include"stdio.h"
#include"time.h"
#include"string.h"
#include"stdlib.h"
#include"conio.h"
#defineNULL0
typedefstructLstu{
intcla,ID;
longnum;
charname[20];
charsex[20];
floatchinese,math,english;
floatsum,ave;
Lstu*next;
}Lstu;
Lstu*head;
voidCreate(intn){//创建链表
Lstu*p,*s;
inti;
for(i=0;i if(i==0){ p=(Lstu*)malloc(sizeof(Lstu)); printf("请输入第%d个人的信息\n",i+1); printf("请输入班级: ");scanf("%d",&p->cla); printf("请输入学号: ");scanf("%ld",&p->num); printf("请输入姓名: ");scanf("%s",p->name); printf("请输入性别: ");scanf("%s",p->sex); printf("请输入语文成绩: ");scanf("%f",&p->chinese); printf("请输入数学成绩: ");scanf("%f",&p->math); printf("请输入英语成绩: ");scanf("%f",&p->english); p->sum=p->chinese+p->math+p->english; p->ave=p->sum/3; head=p; if(n==1){ p->next=NULL;}} else{ s=(Lstu*)malloc(sizeof(Lstu)); printf("请输入第%d个人的信息\n",i+1); printf("请输入班级: ");scanf("%d",&s->cla); printf("请输入学号: ");scanf("%ld",&s->num); printf("请输入姓名: ");scanf("%s",s->name); printf("请输入性别: ");scanf("%s",s->sex); printf("请输入语文成绩: ");scanf("%f",&s->chinese); printf("请输入数学成绩: ");scanf("%f",&s->math); printf("请输入英语成绩: ");scanf("%f",&s->english); s->sum=s->chinese+s->math+s->english; s->ave=s->sum/3; p->next=s; p=s; s->next=NULL;} } } voidList(){//输出链表内容 Lstu*p; inti=0; p=head; if(p==NULL){ printf("Sorry,It'saEmptyList\n");} else{ printf("\n\n\t------------------------------------------------------------------\n"); printf("\t%-5s%-5s%-10s%-8s%-7s%-10s%-10s%-10s\n","序号","班级","学号","姓名","性别","语文成绩","数学成绩","英语成绩"); printf("\t------------------------------------------------------------------\n"); while(p){i++;p->ID=i; printf("\t%-4d%-5d%-7d%-8s%-7s%-10.2f%-10.2f%-10.2f\n",p->ID,p->cla,p->num,p->name,p->sex,p->chinese,p->math,p->english); printf("\t------------------------------------------------------------------\n"); p=p->next; } } } voidlist(){//输出链表所有内容 Lstu*p; inti=0; p=head; if(p==NULL){ printf("Sorry,It'saEmptyList\n");} else{ printf("\n----------------------------------------------------------------------------------\n"); printf("%-5s%-5s%-7s%-8s%-7s%-10s%-10s%-10s%-8s%-8s\n","序号","班级","学号","姓名","性别","语文成绩","数学成绩", "英语成绩","总分","平均分"); printf("----------------------------------------------------------------------------------\n"); while(p){i++;p->ID=i; printf("%-4d%-6d%-12d%-8s%-7s%-10.2f%-10.2f%-10.2f%-8.2f%-8.2f\n",p->ID,p->cla,p->num,p->name,p->sex, p->chinese,p->math,p->english,p->sum,p->ave); printf("----------------------------------------------------------------------------------\n"); p=p->next; } } } voidsave(){//文件保存 FILE*fp; Lstu*p; p=head; if((fp=fopen("初始值二进制.txt","wb"))==NULL) { printf("Cannotopenthefile"); exit(0); } while(p){ fwrite(p,sizeof(Lstu),1,fp); p=p->next;} fclose(fp); } voidsave1(){//文件保存 FILE*fp; Lstu*p; p=head; if((fp=fopen("初始值二进制备用.txt","wb"))==NULL) { printf("Cannotopenthefile"); exit(0); } while(p){ fwrite(p,sizeof(Lstu),1,fp); p=p->next;} fclose(fp); } voidread(){//文件读取 FILE*fp; Lstu*p,*p1; if((fp=fopen("初始值二进制.txt","rb"))==NULL) { printf("Cannotopenthefile\n"); exit(0); }head=(Lstu*)malloc(sizeof(Lstu)); p1=head; while(! feof(fp)){ p=(Lstu*)malloc(sizeof(Lstu)); if(fread(p,sizeof(Lstu),1,fp)==1) { p1->next=p; p1=p1->next; } }head=head->next;fclose(fp); } voidread1(){//文件读取 FILE*fp; Lstu*p,*p1; if((fp=fopen("初始值二进制备用.txt","rb"))==NULL) { printf("Cannotopenthefile\n"); exit(0); }head=(Lstu*)malloc(sizeof(Lstu)); p1=head; while(! feof(fp)){ p=(Lstu*)malloc(sizeof(Lstu)); if(fread(p,sizeof(Lstu),1,fp)==1) { p1->next=p; p1=p1->next; } }head=head->next;fclose(fp); } voidSAVE(){//保存到可浏览文件 FILE*fp; Lstu*p;inti=0; p=head; if((fp=fopen("初始值可浏览文件.txt","w+"))==NULL) { printf("Cannotopenthefile"); exit(0); } fprintf(fp,"\n\n\t------------------------------------------------------------------\n"); fprintf(fp,"\t%-5s%-5s%-10s%-8s%-7s%-10s%-10s%-10s\n","序号","班级","学号","姓名","性别","语文成绩","数学成绩","英语成绩"); fprintf(fp,"\t------------------------------------------------------------------\n\n"); while(p){ i++;p->ID=i; fprintf(fp,"\t%-4d%-5d%-7d%-8s%-7s%-10.2f%-10.2f%-10.2f\n",p->ID,p->cla,p->num,p->name, p->sex,p->chinese,p->math,p->english); fprintf(fp,"\t---------------------------------
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 学生 成绩管理系统 链表版 代码 包含 所有 功能 适合 初学者 借鉴