2022年C語言大作業(yè)_第1頁
2022年C語言大作業(yè)_第2頁
2022年C語言大作業(yè)_第3頁
2022年C語言大作業(yè)_第4頁
2022年C語言大作業(yè)_第5頁
已閱讀5頁,還剩19頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)

文檔簡介

#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;};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("\nFileerror.");}else{while(p1!=NULL){fwrite(p1,sizeof(structstudent),1,outFile);p1=p1->next;}fclose(outFile);}}//將數(shù)據(jù)存入文檔中voidcheck(structstudent*head,structstudent*p1){structstudent*h=head;for(m=0;m<n;m++,h=h->next) { if(strcmp(h->num,p1->num)==0) {printf("輸入號碼重復(fù)\n"); printf("請重新輸入學(xué)號:"); scanf("%s",p1->num); getchar(); check(head,p1); } } }//檢查學(xué)號與否重復(fù)structstudent*creat(){structstudent*head;structstudent*p1,*p2;n=0;p1=p2=(structstudent*)malloc(LEN);printf("學(xué)號:\n");scanf("%s",p1->num);getchar();printf("姓名:\n");gets(p1->name);printf("年齡:\n");scanf("%d",&p1->age); getchar();printf("專業(yè):\n");gets(p1->profession);printf("數(shù)學(xué)成績:\n");scanf("%d",&p1->maths);printf("英語成績:\n");scanf("%d",&p1->english);printf("C語言成績:\n");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("學(xué)號:\n");scanf("%s",p1->num);getchar(); check(head,p1);//檢查輸入學(xué)號是不是重復(fù)且是不是重復(fù)輸錯printf("姓名:\n");gets(p1->name);printf("年齡:\n");scanf("%d",&p1->age); getchar();printf("專業(yè):\n");gets(p1->profession);printf("數(shù)學(xué)成績:\n");scanf("%d",&p1->maths);printf("英語成績:\n");scanf("%d",&p1->english);printf("C語言成績:\n");scanf("%d",&p1->C_program);}p2->next=NULL;save(head);return(head);}//錄入數(shù)據(jù)并將其保存至文檔voidprint(structstudent*head){structstudent*p;printf("\n這%d個學(xué)生成績?yōu)?\n",n);printf("學(xué)號姓名年齡專業(yè)數(shù)學(xué)英語C語言平均成績\n");p=head;if(head==NULL)printf("Theinfoerror\n");if(head!=NULL)while(p!=NULL){p->ave=ave(p);printf("%s%8s%8d%13s%9d%10d%9d%10.2f",p->num,p->name,p->age,p->profession,p->maths,p->english,p->C_program,p->ave);printf("\n");p=p->next;}}//輸出鏈表//structstudent*read(){structstudent*head=NULL;structstudent*p2=head;structstudentrecord;FILE*infile;infile=fopen("stu.bin","rb");n=1;if(infile==NULL){printf("\nFileerror.");}else{head=(structstudent*)malloc(sizeof(structstudent));fread(head,sizeof(*head),1,infile);p2=head;while(fread(&record,sizeof(record),1,infile))//fread返回數(shù)據(jù)個數(shù),結(jié)束和出錯返回0;{ p2->next=(structstudent*)malloc(sizeof(structstudent)); memcpy(p2->next,&record,sizeof(record));//復(fù)制構(gòu)造體數(shù)據(jù)p2=p2->next;n=n+1;}p2->next=NULL;fclose(infile);}returnhead;}//從文獻中讀取數(shù)據(jù)structstudent*search_num(structstudent*head,chararray[20]){structstudent*p1;p1=head;if(head==NULL){printf("打開錯誤");return(head);}while((strcmp(array,p1->num)!=0)&&(p1->next!=NULL)){p1=p1->next;}//找到相應(yīng)學(xué)號if(strcmp(array,p1->num)==0){printf("學(xué)號姓名年齡專業(yè)數(shù)學(xué)英語C語言\n");printf("%s%10s%10d%15s%11d%12d%11d",p1->num,p1->name,p1->age,p1->profession,p1->maths,p1->english,p1->C_program);printf("\n");}elseprintf("此學(xué)號不存在\n");return(head);}//按學(xué)號查詢數(shù)據(jù)//]structstudent*search_name(structstudent*head,chararray[20]){structstudent*p1;p1=head;if(head==NULL){printf("打開錯誤");return(head);}while((strcmp(array,p1->name)!=0)&&(p1->next!=NULL)){p1=p1->next;}//找到相應(yīng)學(xué)號if(strcmp(array,p1->name)==0){printf("學(xué)號姓名年齡專業(yè)數(shù)學(xué)英語C語言\n");printf("%s%10s%10d%15s%11d%12d%11d",p1->num,p1->name,p1->age,p1->profession,p1->maths,p1->english,p1->C_program);printf("\n");}elseprintf("此姓名不存在\n");return(head);}//按姓名查詢數(shù)據(jù)//structstudent*change(structstudent*head,chararray[20]){ structstudent*p1;p1=head;if(head==NULL){printf("打開錯誤!");return(head);}while((strcmp(array,p1->num)!=0)&&(p1->next!=NULL)){p1=p1->next;}//找到相應(yīng)學(xué)號if(strcmp(array,p1->num)==0){printf("請輸入更改學(xué)號:\n");printf("學(xué)號:\n");scanf("%s",p1->num);getchar();printf("姓名:\n");gets(p1->name);printf("年齡:\n");scanf("%d",&p1->age); getchar();printf("專業(yè):\n");gets(p1->profession);printf("數(shù)學(xué)成績:\n");scanf("%d",&p1->maths);printf("英語成績:\n");scanf("%d",&p1->english);printf("C語言成績:\n");scanf("%d",&p1->C_program);save(head);}elseprintf("所查學(xué)號不存在\n");return(head);}//修改數(shù)據(jù)//structstudent*del(structstudent*head,chararray[20]){ structstudent*p1,*p2; if(head==NULL) {printf("\nlistnull!\n"); returnhead; } p1=head; while((strcmp(array,p1->num)!=0)&&(p1->next!=NULL)) {p2=p1; p1=p1->next; }//找到相應(yīng)學(xué)號、 if((strcmp(array,p1->num)==0)) {if(strcmp(array,head->num)==0) head=p1->next; else p2->next=p1->next; } else printf("你查詢學(xué)號(%s)不存在!",p1->num); save(head); return(head);}voidadd(structstudent*head){ structstudent*p1;printf("\n請輸入添加學(xué)生信息:\n");p1=(structstudent*)malloc(LEN);printf("學(xué)號:\n");scanf("%s",p1->num);getchar(); check(head,p1);printf("姓名:\n");gets(p1->name);printf("年齡:\n");scanf("%d",&p1->age); getchar();printf("專業(yè):\n");gets(p1->profession);printf("數(shù)學(xué)成績:\n");scanf("%d",&p1->maths);printf("英語成績:\n");scanf("%d",&p1->english);printf("C語言成績:\n");scanf("%d",&p1->C_program);FILE*outFile; outFile=fopen("stu.bin","ab"); if(outFile==NULL){printf("\n打開錯誤."); } fwrite(p1,sizeof(structstudent),1,outFile); fclose(outFile);}voidsta(structstudent*head,chararray[20],intmax,intmin){ structstudent*p1=head; intk=0;if(strcmp(array,"maths")==0){ while(p1!=NULL) { if(p1->maths>=min&&p1->maths<=max) k++; p1=p1->next; } printf("數(shù)學(xué)科目在%d到%d之間人數(shù)為:%d\n",min,max,k);}elseif(strcmp(array,"english")==0){ while(p1!=NULL) { if(p1->english>=min&&p1->english<=max) k++; p1=p1->next; } printf("英語科目在%d到%d之間人數(shù)為:%d\n",min,max,k);}elseif(strcmp(array,"C_program")==0){ while(p1!=NULL) { if(p1->C_program>=min&&p1->C_program<=max) k++; p1=p1->next; } printf("C語言科目在%d到%d之間人數(shù)為:%d\n",min,max,k);}}voidexit(){printf("\t\t");printf("**********************\n"); printf("\t\t");printf("*******感謝使用*******\n"); printf("\t\t");printf("**********************\n"); k=0;}voidChooseproject(inti){structstudent*head=NULL; if(i==1) { head=read();print(head); }elseif(i==2){ intp=1;printf("請選取按學(xué)號查詢(1)還是按姓名查詢(0):"); scanf("%d",&p); while(p!=1&&p!=0) { printf("輸入錯誤!"); printf("請選取學(xué)號查詢(1)還是姓名查詢(0)"); scanf("%d",&p); } if(p==1) { head=read(); charnum[20]; printf("請輸入查詢學(xué)號:\n");scanf("%s",num);head=search_num(head,num);while(strcmp(num,"0")!=0){printf("與否繼續(xù)查詢(是就輸學(xué)號,否就輸0):\n");scanf("%s",num);if(strcmp(num,"0")==0)break;head=search_num(head,num); } } elseif(p==0) { head=read(); charname[20]; printf("請輸入查詢學(xué)號:\n");scanf("%s",name);head=search_name(head,name);while(strcmp(name,"0")!=0){printf("與否繼續(xù)查詢(是就輸學(xué)號,否就輸0):\n");scanf("%s",name);if(strcmp(name,"0")==0)break;head=search_name(head,name); } } } elseif(i==3) { head=read(); charnum[20]; printf("請輸入要更改學(xué)號:\n");scanf("%s",num);getchar();head=change(head,num);print(head);while(strcmp(num,"0")!=0){printf("與否繼續(xù)更改(是就輸學(xué)號,否就輸0):\n");scanf("%s",num);getchar();if(strcmp(num,"0")==0)break;head=change(head,num);print(head);} } elseif(i==4) { head=read(); add(head); } elseif(i==5) { charnum[20]; head=read(); printf("請輸入要刪除學(xué)號:\n"); scanf("%s",num); getchar(); head=del(head,num); print(head); } elseif(i==6) { head=read(); inti; printf("\t\t");printf("************1.學(xué)號排序;********************\n"); printf("\t\t");printf("************2.平均成績排序;****************\n"); printf("\t\t");printf("************3.數(shù)學(xué)成績排序;****************\n"); printf("\t\t");printf("************4.英語成績排序;****************\n"); printf("\t\t");printf("************5.C語言成績排序;***************\n"); printf("請輸入相應(yīng)排序代號:"); scanf("%d",&i); sort_down(head,i); } elseif(i==7) { head=read(); intmin,max; charsubject[20]; printf("\t\t");printf("************數(shù)學(xué)(maths);***************\n"); printf("\t\t");printf("************英語(english);*************\n"); printf("\t\t");printf("***********C語言(C_program);***********\n"); printf("請選取要記錄項目:\n"); scanf("%s",subject); getchar(); while((strcmp(subject,"maths")!=0&&strcmp(subject,"english")!=0&&strcmp(subject,"C_program")!=0)) { printf("輸入錯誤!"); printf("\t\t");printf("************數(shù)學(xué)(maths);***********\n"); printf("\t\t");printf("************英語(english);***********\n"); printf("\t\t");printf("***********C語言(C_program);***********\n"); printf("請選取要記錄項目:\n"); scanf("%s",subject); getchar(); } printf("請輸入分?jǐn)?shù)段區(qū)間:");printf("區(qū)間上限:"); scanf("%d",&max); printf("區(qū)間下限:"); scanf("%d",&min); while(min>=max) { printf("輸入下限不不大于等于上限,錯誤!"); printf("請重新輸入分?jǐn)?shù)段區(qū)間:");printf("區(qū)間上限:"); scanf("%d",max); printf("區(qū)間下限:"); scanf("%d",min); } sta(head,subject,max,min); } elseif(i==8) { printf("\t\t");printf("************************************\n"); printf("\t\t");printf("**************感謝使用**************\n"); printf("\t\t");printf("************************************\n"); k=0; } }//選取功能voidmenu(){inti; printf("\t\t");printf("***********1.信息瀏覽;***********\n"); printf("\t\t");printf("***********2.信息查詢;***********\n"); printf("\t\t");printf("***********3.信息修改;***********\n"); printf("\t\t");printf("***********4.信息添加;***********\n"); printf("\t\t");printf("***********5.信息刪除;***********\n"); printf("\t\t");printf("***********6.信息排序;***********\n"); printf("\t\t");printf("***********7.信息記錄;***********\n"); printf("\t\t");printf("***********8,退出系統(tǒng);***********\n"); printf("請選取項目:"); scan

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論