c语言程序设计文档——学生成绩管理系统
您好,今天小然来为大家解答以上的问题。c语言程序设计文档相信很多小伙伴还不知道,现在让我们一起来看看吧!
1、学生成绩管理系统:#include#include#include#defineLENsizeof(structscorenode)#defineDEBUG#includestructscorenode{intnumber;/学号/charname[10];/姓名/floatyuwen;/语文成绩/floatyingyu;/英语成绩/floatshuxue;/数学成绩/structscorenodenext;};typedefstructscorenodescore;intn,k;/n,k为全局变量,本程序中的函数均可以使用它//==============================================================================================/scorecreat2311(void)/函数creat2311,功能:创建链表,此函数带回一个指向链表头的指针/{scorehead;scorep1,p2,p3,max;inti,j;floatfen;chart[10];n=0;p1=p2=p3=(score)malloc(LEN);head=p3;/开辟一个新单元/printf("请输入,输0退出!n");repeat1:printf("请输入学生学号(学号应大于0):");/输入学号,学号应大于0/scanf("%d",&p1->number);while(p1->number{getchar();printf("输入错误,请重新输入学生学号:");scanf("%d",&p1->number);}/输入学号为字符或小于0时,程序报错,提示重新输入学号/if(p1->number==0)gotoend;/当输入的学号为0时,转到末尾,结束创建链表/else{p3=head;if(n>0){for(i=0;i{if(p1->number!=p3->number)p3=p3->next;else{printf("学号重复,请重输!n");gotorepeat1;/当输入的学号已经存在,程序报错,返回前面重新输入/}}}}printf("请输入学生姓名:");scanf("%s",&p1->name);/输入学生姓名/printf("请输入语文成绩(0~100):");/输入语文成绩,成绩应在0-100/scanf("%f",&p1->yuwen);while(p1->yuwenyuwen>100){getchar();printf("输入错误,请重新输入语文成绩");/输入错误,重新输入语文成绩直到正确为止/scanf("%f",&p1->yuwen);}printf("请输入英语成绩(0~100):");/输入英语成绩,成绩应在0-100/scanf("%f",&p1->yingyu);while(p1->yingyuyingyu>100){getchar();printf("输入错误,请重新输入英语成绩");/输入错误,重新输入英语成绩直到正确为止/scanf("%f",&p1->yingyu);}printf("请输入数学成绩(0~100):");/输入数学成绩,成绩应在0-100/scanf("%f",&p1->shuxue);while(p1->shuxueshuxue>100){getchar();printf("输入错误,请重新输入数学成绩");scanf("%f",&p1->shuxue);}/输入错误,重新输入数学成绩直到正确为止/head=NULL;while(p1->number!=0){n=n+1;if(n==1)head=p1;elsep2->next=p1;p2=p1;p1=(score)malloc(LEN);printf("请输入,输0退出!n");repeat2:printf("请输入学生学号(学号应大于0):");scanf("%d",&p1->number);/输入学号,学号应大于0/while(p1->number{getchar();printf("输入错误,请重新输入学生学号:");scanf("%d",&p1->number);}/输入学号为字符或小于0时,程序报错,提示重新输入学号/if(p1->number==0)gotoend;/当输入的学号为0时,转到末尾,结束创建链表/else{p3=head;if(n>0){for(i=0;i{if(p1->number!=p3->number)p3=p3->next;else{printf("学号重复,请重输!n");gotorepeat2;/当输入的学号已经存在,程序报错,返回前面重新输入/}}}}printf("请输入学生姓名:");scanf("%s",&p1->name);/输入学生姓名/printf("请输入语文成绩(0~100):");scanf("%f",&p1->yuwen);/输入语文成绩,成绩应在0-100/while(p1->yuwenyuwen>100){getchar();printf("输入错误,请重新输入语文成绩");scanf("%f",&p1->yuwen);}/输入错误,重新输入语文成绩直到正确为止/printf("请输入英语成绩(0~100):");scanf("%f",&p1->yingyu);/输入英语成绩,成绩应在0-100/while(p1->yingyuyingyu>100){getchar();printf("输入错误,请重新输入英语成绩");scanf("%f",&p1->yingyu);}/输入错误,重新输入英语成绩直到正确为止/printf("请输入数学成绩(0~100):");scanf("%f",&p1->shuxue);/输入数学成绩,成绩应在0-100/while(p1->shuxueshuxue>100){getchar();printf("输入错误,请重新输入数学成绩");scanf("%f",&p1->shuxue);}/输入错误,重新输入数学成绩直到正确为止/}end:p1=head;p3=p1;for(i=1;i{for(j=i+1;j{max=p1;p1=p1->next;if(max->number>p1->number){k=max->number;max->number=p1->number;p1->number=k;/交换前后结点中的学号值,使得学号大者移到后面的结点中/strcpy(t,max->name);strcpy(max->name,p1->name);strcpy(p1->name,t);/交换前后结点中的姓名,使之与学号相匹配/fen=max->yuwen;max->yuwen=p1->yuwen;p1->yuwen=fen;/交换前后结点中的语文成绩,使之与学号相匹配/fen=max->yingyu;max->yingyu=p1->yingyu;p1->yingyu=fen;/交换前后结点中的英语成绩,使之与学号相匹配/fen=max->shuxue;max->shuxue=p1->shuxue;p1->shuxue=fen;/交换前后结点中的数学成绩,使之与学号相匹配/}}max=head;p1=head;/重新使max,p指向链表头/}p2->next=NULL;/链表结尾/printf("输入的学生数为:%d个!n",n);return(head);}/==============================================================================================//==============================================================================================/scoreload2311(scorehead)/函数load2311,功能:从文件读入学生记录/{scorep1,p2;intm=0;charfilepn[10];FILEfp;printf("请输入文件路径及文件名:");scanf("%s",filepn);/输入文件路径及名称/if((fp=fopen(filepn,"r+"))==NULL){printf("不能打开文件!n");return0;}fscanf(fp,"考试成绩管理系统n");fscanf(fp,"作者:周纯钢班级:信息023学号:11n");fscanf(fp,"-----------------------------------------n");fscanf(fp,"|学号t|姓名t|语文t|英语t|数学t|n");fscanf(fp,"-----------------------------------------n");/读入表格域/printf("考试成绩管理系统n");printf("作者:周纯钢班级:信息023学号:11n");printf("-----------------------------------------n");printf("|学号t|姓名t|语文t|英语t|数学t|n");printf("-----------------------------------------n");/打印表格域/m=m+1;if(m==1){p1=(score)malloc(LEN);/开辟一个新单元/fscanf(fp,"%d%s%f%f%f",&p1->number,p1->name,&p1->yuwen,&p1->yingyu,&p1->shuxue);printf("|%dt|%st|%.1ft|%.1ft|%.1ft|n",p1->number,p1->name,p1->yuwen,p1->yingyu,p1->shuxue);/文件读入与显示/head=NULL;do{n=n+1;if(n==1)head=p1;elsep2->next=p1;p2=p1;p1=(score)malloc(LEN);/开辟一个新单元/fscanf(fp,"%d%s%f%f%fn",&p1->number,p1->name,&p1->yuwen,&p1->yingyu,&p1->shuxue);printf("|%dt|%st|%.1ft|%.1ft|%.1ft|n",p1->number,p1->name,p1->yuwen,p1->yingyu,p1->shuxue);/文件读入与显示/}while(!feof(fp));p2->next=p1;p1->next=NULL;n=n+1;}printf("-----------------------------------------n");/表格下线/fclose(fp);/结束读入,关闭文件/return(head);}/==============================================================================================//==============================================================================================/scoreadd2311(scorehead,scorestu)/函数add2311,功能:追加,并且将所有按学号排序/{scorep0,p1,p2,p3,max;inti,j;floatfen;chart[10];p3=stu=(score)malloc(LEN);/开辟一个新单元/printf("n输入要增加的学生的资料!");repeat4:printf("请输入学生学号(学号应大于0):");scanf("%d",&stu->number);/输入学号,学号应大于0/while(stu->number{getchar();printf("输入错误,请重新输入学生学号:");scanf("%d",&stu->number);}/输入错误,重新输入学号///if(stu->number==0)gotoend2;/当输入的学号为0时,转到末尾,结束追加/else{p3=head;if(n>0){for(i=0;i{if(stu->number!=p3->number)p3=p3->next;else{printf("学号重复,请重输!n");gotorepeat4;/当输入的学号已经存在,程序报错,返回前面重新输入/}}}}//printf("输入学生姓名:");scanf("%s",stu->name);/输入学生姓名/printf("请输入语文成绩(0~100):");scanf("%f",&stu->yuwen);/输入语文成绩,成绩应在0-100/while(stu->yuwenyuwen>100){getchar();printf("输入错误,请重新输入语文成绩");scanf("%f",&stu->yuwen);}/输入错误,重新输入语文成绩直到正确为止/printf("请输入英语成绩(0~100):");scanf("%f",&stu->yingyu);/输入英语成绩,成绩应在0-100/while(stu->yingyuyingyu>100){getchar();printf("输入错误,请重新输入英语成绩");scanf("%f",&stu->yingyu);}/输入错误,重新输入英语成绩直到正确为止/printf("请输入数学成绩(0~100):");scanf("%f",&stu->shuxue);/输入数学成绩,成绩应在0-100/while(stu->shuxueshuxue>100){getchar();printf("输入错误,请重新输入数学成绩");scanf("%f",&stu->shuxue);}/输入错误,重新输入数学成绩直到正确为止/p1=head;p0=stu;if(head==NULL){head=p0;p0->next=NULL;}/当原来链表为空时,从首结点开始存放资料/else/原来链表不为空/{if(p1->next==NULL)/找到原来链表的末尾/{p1->next=p0;p0->next=NULL;/将它与新开单元相连接/}else{while(p1->next!=NULL)/还没找到末尾,继续找/{p2=p1;p1=p1->next;}p1->next=p0;p0->next=NULL;}}n=n+1;}printf("-----------------------------------------n");/表格下线/fclose(fp);/结束读入,关闭文件/return(head);}/==============================================================================================//==============================================================================================/scoreadd2311(scorehead,scorestu)/函数add2311,功能:追加,并且将所有按学号排序/{scorep0,p1,p2,p3,max;inti,j;floatfen;chart[10];p3=stu=(score)malloc(LEN);/开辟一个新单元/printf("n输入要增加的学生的资料!");repeat4:printf("请输入学生学号(学号应大于0):");scanf("%d",&stu->number);/输入学号,学号应大于0/while(stu->number{getchar();printf("输入错误,请重新输入学生学号:");scanf("%d",&stu->number);}/输入错误,重新输入学号///if(stu->number==0)gotoend2;/当输入的学号为0时,转到末尾,结束追加/else{p3=head;if(n>0){for(i=0;i{if(stu->number!=p3->number)p3=p3->next;else{printf("学号重复,请重输!n");gotorepeat4;/当输入的学号已经存在,程序报错,返回前面重新输入/}}}}#include#include#define MAX 100struct addr{char name[30];char street[40];char city[20];char state[3];unsigned long int zip;}add_list[MAX];void init_list(void),enter(void);void delete(void),list(void);void load(void),se(void);int menu_select(void),find_free(void);int main(void){char cho;init_list();/initialize the structure array/for(;;){cho=menu_select();switch(cho){case 1:enter();break;case 2:delete();break;case 3:list();break;case 4:se();break;case 5:load();break;case 6:exit(0);}}return 0;}/Initialize the list/void init_list(void){register int t;for(t=0;tadd_list[t].name[0]='0';}/Get a menu selection/int menu_select(void){char s[80];int c;printf("1.Enter a namen");printf("2.Delete a namen");printf("3.List the filen");printf("4.Se the filen");printf("5.Load the filen");printf("6.Quitn");do{printf("nEnter your cho:");gets(s);c=atoi(s);}while(c6);return c;}/Input addresses into the list/void enter(void){int slot;char s[80];slot=find_free();if(slot==-1){printf("nList Full");return;}printf("Enter name:");gets(add_list[slot].name);printf("Enter street:");gets(add_list[slot].street);printf("Enter city:");gets(add_list[slot].city);printf("Enter state:");gets(add_list[slot].state);printf("Enter zip:");gets(s);add_list[slot].zip=strtoul(s,'0',10);}/Find an unused structure/int find_free(void){register int t;for(t=0;add_list[t].name[0]&&tif(t==MAX)return -1;/no slots free/return t;}/Delete an address/void delete(void){register int slot;char s[80];printf("enter record # :");gets(s);slot=atoi(s);if(slot>=0&&slotadd_list[slot].name[0]='0';}/Display the list on the screen/void list(void){register int t;for(t=0;tif(add_list[t].name[0]){printf("%sn",add_list[t].name);printf("%sn",add_list[t].street);printf("%sn",add_list[t].city);printf("%sn",add_list[t].state);printf("%sn",add_list[t].zip);}}printf("nn");}/Se the list/void se(void){FILE fp;register int i;if((fp=fopen("maillist","wb"))==NULL)printf("Cannot open filen");return;for(i=0;iif(add_list[i].name)if(fwrite(&add_list[i],sizeof(struct addr),1,fp)!=1)printf("File write errorn");fclose(fp);}/Load the file/void load(void){FILE fp;register int i;if((fp=fopen("maillist","rb"))==NULL){printf("Cannot open filen");return;}init_list();for(i=0;iif(fread(&add_list[i],sizeof(struct addr),1,fp)!=1){if(feof(fp))break;printf("File read errorn");}fclose(fp);}我是运行过再拿上来的,你输入了什么值,然后出了什么错?=======================================================#include#include#includeinlineintget_value(intmatrix,intn,inti,intj){returnmatrix[in+j];}inlinevoidset_value(intmatrix,intn,inti,intj,intvalue){matrix[in+j]=value;}inlineintget(intmatrix,intn,inti,intj){returnmatrix+in+j;}inlineintprev(intm,intn){returnm>?m-1:n-1;}inlineintnext(intm,intn){returnmn-1?m+1:0;}inlinevoidrrse(intmatrix,intn,inti,intj,intt){set_value(matrix,n,i,j,t-get_value(matrix,n,i,j));}inlinevoidswap(inta,intb){intt=a;a=b;b=t;}intintialize_matrix(intn){intlen=sizeof(int)(nn);intmatrix=(int)malloc(len);memset(matrix,0,len);returnmatrix;}intint_length(intn){intlen=0;while(n>0){n/=10;++len;}returnlen;}voidgenerate_odd_matrix(intmatrix,intn,ints){inti=0,j=n>>1,end=s+nn;set_value(matrix,n,i,j,s);while(++s!=end){if(get_value(matrix,n,prev(i,n),next(j,n))==0){i=prev(i,n);j=next(j,n);}elsei=next(i,n);set_value(matrix,n,i,j,s);}}voidsequential_fill(intmatrix,intn,ints){intend=nn;while(send){matrix++=s++;}}voidgenerate_4k_matrix(intmatrix,intn,ints){sequential_fill(matrix,n,s);inti,j,m,t=nn+1;for(i=0;in;i+=4){for(j=0;jn;j+=4){for(m=0;m4;++m){rrse(matrix,n,i+m,j+m,t);rrse(matrix,n,i+m,j+3-m,t);}}}}voidmatrix_fill(intmatrix,intn,intall,intm,inti,intj,intoffset){inta,b;for(a=0;a!=m;++a){for(b=0;b!=m;++b){set_value(matrix,n,i+a,j+b,get_value(all,m,a,b)+offset);}}}voidprint_matrix(intmatrix,intn);voidgenerate_4k2_matrix(intmatrix,intn,ints){intm=n>>1,m_sqr=mm,k=n/4,i,j,p;intall_matrix=intialize_matrix(m);generate_odd_matrix(all_matrix,m,s);matrix_fill(matrix,n,all_matrix,m,0,0,0);matrix_fill(matrix,n,all_matrix,m,0,m,m_sqr2);matrix_fill(matrix,n,all_matrix,m,m,0,m_sqr3);matrix_fill(matrix,n,all_matrix,m,m,m,m_sqr);p=m>>1;for(i=0;ip;++i){for(j=0;jk;++j){swap(get(matrix,n,i,j),get(matrix,n,i+m,j));}}for(j=p;jp+k;++j){swap(get(matrix,n,i,j),get(matrix,n,i+m,j));}for(++i;i++i){for(j=0;jk;++j){swap(get(matrix,n,i,j),get(matrix,n,i+m,j));}}for(i=0;im;++i){for(j=0;jk-1;++j){swap(get(matrix,n,i,m+p-j),get(matrix,n,i+m,m+p-j));}}free(all_matrix);}voidprint_matrix(intmatrix,intn){inti,j;charfof="%%%dd",format[10];sprintf(format,fof,int_length(nn));for(i=0;i!=n;++i){for(j=0;j!=n;++j){printf(format,get_value(matrix,n,i,j));}printf("n");}printf("n");}intmain(){intn;printf("Inputthedimensionm(n>3):n");scanf("%d",&n);if(n{printf("nmustbegreaterthan3n");return0;}intmatrix=intialize_matrix(n);if(n%2!=0){generate_odd_matrix(matrix,n,1);}elseif(n%4==0){generate_4k_matrix(matrix,n,1);}else{generate_4k2_matrix(matrix,n,1);}print_matrix(matrix,n);free(matrix);return0;}#define后面的FORMAT来代表"%dn%sn%fn........"如果在程序中出现FORMAT就会被替换成"%dn%sn%fn........“,给你举个简单的例子.#defineN10就相当于定义一个变量N=10,程序中出现的N都会给替换成10.希望对你有所帮助!表示用FORMAT来代表"%dn%sn%fn........“也就是说在程序中用到FORMAT,其实就是用了"%dn%sn%fn........“#include"stdio.h"main(){intn,i,tatol=0;floate;intdat[200];printf("请输入若干学生成绩,当为负数结束输入:");n=0;scanf("%d",&dat[n]);while(dat[n]&&n{n++;scanf("%d",&dat[n])}if(dat[n]>0)n=n+1;for(i=0;ie=total/n;printf("n学生平均成绩为%4.1f",e);printf("n低于平均成绩的有:");for(i=0;i{if(dat[i]",dat[i]);}}#includemain(){doubles,a[100];intn,i;n=0;while(scanf("%lf",&a[n])){if(a[n]break;n++;}s=0;for(i=0;is+=a[i];s=s/n;printf("平均分是%lfn",s);printf("低于平均分的同学:n");for(i=0;iif(a[i]printf("%d%lfn",i+1,a[i]);}#includemain(){doubleerage,sum=0;intfound=1;for(i=0,found=1,i++){scanf("lf%",&a[i]);if(a[i]=>0){sum=sum+a[i];n++;}elsefound=0;erage=sum/n;printf("平均数:lf%",erage);printf("低于平均值的数:")for(i=0,i{if(a[i]printf("lf%",a[i]);}}#includeintmain(){floatarray1[100];inti=0,j,k;floatsum=0,erage;printf("请输入成绩:n");while(array1[i]>0){scanf("%lf",&array1[i]);i++;}for(j=0;jsun+=array1[j];errage=sum/(i+1);printf("平均成绩:%fn",erage);printf("低于平均成绩的同学:");for(k=0;k{if(array1[k]printf("%f",array[k])}}。
本文到这结束,希望上面文章对大家有所帮助。
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系 836084111@qq.com 删除。