资源描述:
《C语言大作业(全).pdf》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#include"stdafx.h"#include"stdio.h"#include"stdlib.h"#include"string.h"#include"malloc.h"#defineLENsizeof(structstudent)#defineNULL0intn,m;intk=1;structstudent{charnum[20];charname[20];intage;charprofession[50];intmaths;intenglish;intC_program;floatave;structstudent*next;
2、};floatave(structstudent*p1){floatave;ave=(float)(p1->maths+p1->english+p1->C_program)/3;returnave;}voidsave(structstudent*head){structstudent*p1=head;FILE*outFile;outFile=fopen("stu.bin","wb");if(outFile==NULL){printf("Fileerror.");}else{while(p1!=NULL){fwrite(p1,sizeo
3、f(structstudent),1,outFile);p1=p1->next;}fclose(outFile);}}//将数据存入文档中voidcheck(structstudent*head,structstudent*p1){structstudent*h=head;for(m=0;mnext){if(strcmp(h->num,p1->num)==0){printf("输入号码重复");printf("请重新输入学号:");scanf("%s",p1->num);getchar();check(head
4、,p1);}}}//检验学号是否重复structstudent*creat(){structstudent*head;structstudent*p1,*p2;n=0;p1=p2=(structstudent*)malloc(LEN);printf("学号:");scanf("%s",p1->num);getchar();printf("姓名:");gets(p1->name);printf("年龄:");scanf("%d",&p1->age);getchar();printf("专业:");gets(p1->profe
5、ssion);printf("数学成绩:");scanf("%d",&p1->maths);printf("英语成绩:");scanf("%d",&p1->english);printf("C语言成绩:");scanf("%d",&p1->C_program);head=NULL;while(strcmp(p1->num,"0")!=0){n=n+1;if(n==1)head=p1;elsep2->next=p1;p2=p1;p1=(structstudent*)malloc(LEN);printf("学号:");scan
6、f("%s",p1->num);getchar();check(head,p1);//检查输入的学号是不是重复且是不是重复输错printf("姓名:");gets(p1->name);printf("年龄:");scanf("%d",&p1->age);getchar();printf("专业:");gets(p1->profession);printf("数学成绩:");scanf("%d",&p1->maths);printf("英语成绩:");scanf("%d",&p1->english);printf("C语
7、言成绩:");scanf("%d",&p1->C_program);}p2->next=NULL;save(head);return(head);}//录入数据并将其保存至文档voidprint(structstudent*head){structstudent*p;printf("这%d个学生的成绩为:",n);printf("学号姓名年龄专业数学英语C语言平均成绩");p=head;if(head==NULL)printf("Theinfoerror");if(head!=NULL)while(p!=NULL){p
8、->ave=ave(p);printf("%s%8s%8d%13s%9d%10d%9d%10.2f",p->num,p->name,p->age,p->profession,p->maths,