C語言學(xué)生選課系統(tǒng)代碼_第1頁
C語言學(xué)生選課系統(tǒng)代碼_第2頁
C語言學(xué)生選課系統(tǒng)代碼_第3頁
C語言學(xué)生選課系統(tǒng)代碼_第4頁
C語言學(xué)生選課系統(tǒng)代碼_第5頁
已閱讀5頁,還剩22頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

1、#include #include #include int N1,N2;struct studentint num2;char name220;int nelenum50;/所選課程編號(hào)int nelen;/所選課程學(xué)分和struct student * next;struct courseint num1; /課程編號(hào)char name120;char major20;char type20;int credit;int period;char teacher20;int people;/選此門課程的人數(shù)struct course *next;/結(jié)構(gòu)體指針;struct course *

2、head1;struct student * head2;void zhang()/從鍵盤錄入課程信息struct course *p1,*p2;N1=0;p1=p2=(struct course *)malloc(sizeof(struct course);n);scanf(%d%s%s%s%d%d%s,&p1-num1,p1-name1,p1-major,p1-type,&p1-cr edit,&p1-period,p1-teacher);p1-people=0;head1=NULL;while(p1-num1!=0)N1=N1+1;if(N1=1)head1=p1;else p2-nex

3、t=p1;p2=p1;p1=(struct course * )malloc(sizeof(struct course);scanf(%d%s%s%s%d%d%s,&p1-num1,p1-name1,p1-major,p1-type,&p1-cr edit,&p1-period,p1-teacher);p1-people=0;p2-next=NULL;void zhang1()/從文件錄入課程信息FILE * fp;char filepath20;struct course *p1,*p2;N1=0;printf( 請(qǐng)輸入您要讀取的路徑 :);getchar();gets(filepath);

4、if(fp=fopen(filepath,r)=NULL)printf( 找不到 %s 文件 !n,filepath);exit(0);p1=p2=(struct course*)malloc(sizeof(struct course);fscanf(fp,%d%s%s%s%d%d%s%d,&p1-num1,p1-name1,p1-major,p1-type,& p1-credit,&p1-period,p1-teacher,&p1-people);while(!feof(fp)N1=N1+1;if(N1=1)head1=p1;elsep2-next=p1;p2=p1;p1=(struct c

5、ourse * )malloc(sizeof(struct course);fscanf(fp,%d%s%s%s%d%d%s%d,&p1-num1,p1-name1,p1-major,p1-type,& p1-credit,&p1-period,p1-teacher,&p1-people);p2-next=NULL;void load()/錄入課程信息函數(shù)int i;printf(ttt錄入課程信息printf(n1.從鍵盤錄入 );printf(n2.從文件錄入 );printf(n3.返回主菜單 n);printf( 請(qǐng)選擇 1-3:);n);scanf(%d,&i);switch(i)c

6、ase 1: zhang(); break;case 2:zhang1();break;case 3:break;void insert(struct course *incourse)/增加課程信息struct course *p0,*p1,*p2;p1=head1;p0=incourse;if(head1=NULL)head1=p0;p0-next=NULL;elsewhile(p0-num1p1-num1) & (p1-next!=NULL)p2=p1;p1=p1-next;if(p0-num1num1)if(head1=p1)head1=p0;elsep2-next=p0;p0-nex

7、t=p1;elsep1-next=p0;p0-next=NULL;N1=N1+1;void delc(int num1)/刪除課程信息struct course *p1,*p2;if(head1=NULL)printf(n 無法刪除 !n);goto end;p1=head1;while(num1!=p1-num1 & p1-next!=NULL)p2=p1;p1=p1-next;if(num1=p1-num1)if(p1=head1)head1=p1-next;elsep2-next=p1-next;printf(已刪除 n);N1=N1-1;elseprintf( 沒有此課程 n);end

8、:;void managementc()/課程信息管理函數(shù)int i,num1;printf(ttt課程信息printf(1.添加課程 n);printf(2.刪除課程 n);printf(3.返回n);printf(請(qǐng)輸入 1-3:n);scanf(%d,&i);switch(i)struct course * p1;n);case 1:p1=(struct course *)malloc(sizeof(struct course);printf(課程編號(hào)t課程名稱t主修t課程性質(zhì)t學(xué)分t課時(shí)t教師n);scanf(%d%s%s%s%d%d%s,&p1-num1,p1-name1,p1-ma

9、jor,p1-type,&p1-cr edit,&p1-period,p1-teacher);p1-people=0;insert(p1); break;case 2:printf( 請(qǐng)輸入您要?jiǎng)h除的課程編號(hào) :n);scanf(%d,&num1);delc(num1); break;case 3:break;void putin(void)/從鍵盤錄入學(xué)生信息int i;struct student *p1,*p2;N2=0;p1=p2=(struct student *)malloc(sizeof(struct student);printf(學(xué)號(hào)t 姓名 n);scanf(%d%s,&p

10、1-num2,p1-name2);p1-nelen=0;for(i=0;inelenumi=0;head2=NULL;while(p1-num2!=0)N2=N2+1;if(N2=1)head2=p1;elsep2-next=p1;p2=p1;p1=(struct student * )malloc(sizeof(struct student);scanf(%d%s,&p1-num2,p1-name2);p1-nelen=0;for(i=0;inelenumi=0;p2-next=NULL; int i=0;void putin2()/從文件錄入學(xué)生信息FILE * fp;char filep

11、ath20;struct student *p1,*p2;N2=0;printf( 請(qǐng)輸入您要讀取的路徑 :);getchar();gets(filepath);if(fp=fopen(filepath,rt)=NULL)printf( 找不到 %s 文件 !n,filepath);exit(0);p1=p2=(struct student*)malloc(sizeof(struct student);fread(p1,sizeof(struct student),1,fp);head2=NULL;while(!feof(fp)i=0;N2=N2+1;if(N2=1)head2=p1;else

12、p2-next=p1;p2=p1;p1=(struct student * )malloc(sizeof(struct student);fread(p1,sizeof(struct student),1,fp);p2-next=NULL;void input()/錄入學(xué)生信息函數(shù)int i;printf(tttprintf(n1.錄入學(xué)生信息 n); 從鍵盤錄入 n);從文件錄入 n); 返回主菜單 n); printf( 請(qǐng)輸入printf(2.printf(3.1-3:n);scanf(%d,&i);switch(i)case 1:putin();break;case 2:putin2(

13、);break;case 3:break;void inserts(struct student * incouse)/增加學(xué)生信息struct student *p0,*p1,*p2;p1=head2;p0=incouse;if(head2=NULL)head2=p0;p0-next=NULL;elsewhile(p0-num2p1-num2) & (p1-next!=NULL)p2=p1;p1=p1-next;if(p0-num2 num2)if(head2=p1) head2=p0;else p2-next=p0;p0-next=p1;elsep1-next=p0;p0-next=NUL

14、L;N2=N2+1;void dels(int num2)/刪除學(xué)生信息struct student *p1,*p2;if(head2=NULL)printf(n 無法刪除 n);goto end;p1=head2;while(num2!=p1-num2 & p1-next!=NULL)p2=p1;p1=p1-next;if(num2=p1-num2)if(p1=head2)head2=p1-next;elsep2-next=p1-next;printf( 已刪除 n);N2=N2-1;elseprintf( 沒有此學(xué)生編號(hào) n);end:;void managements() /學(xué)生信息管理

15、函數(shù)struct student * p1;int i,num2;printf(tttprintf(1.printf(2.printf(3.學(xué)生信息管理 n); 添加學(xué)生信息 n); 刪除學(xué)生信息 n); 返回主菜單 n);printf(請(qǐng)選擇 1-3:n);scanf(%d,&i);switch(i)case 1:p1=(struct student *)malloc(sizeof(struct student);p1-nelen=0;p1-nelenum0=0;printf(numtnamen);scanf(%d%s,&p1-num2,p1-name2);inserts(p1);break

16、;case 2:printf( 請(qǐng)輸入您要?jiǎng)h除的學(xué)生編號(hào) :n);scanf(%d,&num2);dels(num2); break;case 3:break;void elect()/學(xué)生選課p=p-next;struct student * s;struct course * p;int a,i,b;printf( 請(qǐng)輸入您的學(xué)號(hào) :n);scanf(%d,&a);s=head2;while(s-num2)!=a&s-next!=NULL) s=s-next;if(s-num2!=a)printf( 您的信息不存在,請(qǐng)重新輸入 :n);goto end;if(s-nelen)10)prin

17、tf( 您的學(xué)分已滿 );goto end;printf( 請(qǐng)輸入您要選修的課程編號(hào) n);scanf(%d,&b);for(i=0;(s-nelenumi)=0;i+);s-nelenumi=b;p=head1;while(p-num1)!=b) for(i=0;(s-nelenumi)!=0;i+);s-nelenumi=b;(p-people)+;(s-nelen)=(s-nelen)+(p-credit);(p-people)+;end:;void back()/學(xué)生退課struct student * p;struct course * p1;int b,i,j,a;printf(

18、請(qǐng)輸入您的學(xué)號(hào) :n);scanf(%d,&a);p=head2;while(p-num2!=a&p!=NULL) p=p-next;if(p=NULL)printf( 您的信息不存在 :n);elseprintf( 請(qǐng)輸入您要退選的課程 :n);scanf(%d,&b);p1=head1;while(p1-num1!=b) p1=p1-next;for(i=0;p-nelenumi!=b;i+);for(j=i;p-nelenumj!=0;j+)p-nelenumj=p-nelenumj+1;p-nelenum-j=0;(p-nelen)=(p-nelen)-(p1-credit);(p1-

19、people)-;printf(succeed!n);void elective()/學(xué)生選課信息管理int i;printf(tttprintf(1.printf(2.printf(3.printf( scanf(%d,&i);學(xué)生選課信息管理 n);選課n);退課n); 返回主菜單 n);請(qǐng)輸入 1-3:n);switch(i)case 1:elect();break;case 2:back();break;case 3:break;void listc()/瀏覽課程信息struct course * p;p=head1;printf( 課程編號(hào) 教師 選課人數(shù) n);課程名稱 主修 課程

20、性質(zhì) 學(xué)分 課時(shí)while(p!=NULL)printf(%6d%13s%13s%10s%7d%7d%12s%5dn,p-num1,p-name1,p-major,p-type,p-credit,p-period,p-teacher,p-people);void lists()/瀏覽學(xué)生信息struct student * p;int a;p=head2;printf( 學(xué)生編號(hào)學(xué)生姓名所選課程編號(hào) 所選課程學(xué)分n);while(p!=NULL)printf(%6d%13s,p-num2,p-name2);printf(%6d,p-nelen);for(a=0;p-nelenuma!=0&an

21、elenuma);printf(n);p=p-next;void intoc()/存儲(chǔ)課程信息FILE * fp;struct course * p;char filepath30;printf( 輸入路徑 :);getchar();gets(filepath);if(fp=fopen(filepath,w)=NULL)無法儲(chǔ)存 !);exit(0);p=head1;while(p!=NULL)fprintf(fp,%d%s%s%s%d%d%s%dn,p-num1,p-name1,p-major,p-type ,p-credit,p-period,p-teacher,p-people);p=p

22、-next;fclose(fp);printf(已儲(chǔ)存入 s文件!n,filepath);void intos()/存儲(chǔ)學(xué)生信息FILE * fp;struct student * p;char filepath30;printf( 請(qǐng)輸入路徑 :);getchar();gets(filepath);if(fp=fopen(filepath,wt)=NULL)printf(n 無法儲(chǔ)存 !);exit(0);p=head2;while(p!=NULL)fwrite(p,sizeof(struct student),1,fp);fclose(fp);prin tf(已儲(chǔ)存入 %s 文件!n,fi

23、le path);p=p-next;void into()/信息存儲(chǔ)函數(shù)int i;printf(tttprintf(1.printf(2.printf(3. printf(信息存儲(chǔ) n); 課程信息存儲(chǔ) n); 學(xué)生信息存儲(chǔ) tn); 返回主菜單 n); 請(qǐng)輸入 1-3n);scanf(%d,&i);switch(i)case(1):intoc();break;case(2):intos();break;case(3):break;void store()/信息存儲(chǔ)瀏覽函數(shù)int i;printf(ttprintf(1.printf(2.printf(3.printf(4.printf(信息

24、存儲(chǔ)和瀏覽 n); 課程信息瀏覽 n); 學(xué)生信息瀏覽 n); 信息存儲(chǔ) n); 返回主菜單 n); 請(qǐng)輸入 1-4:n);scanf(%d,&i);switch(i)case(1):listc();break;case(2):lists();break;case(3):into();break;case(4):break;void search1()/按學(xué)生編號(hào)查找學(xué)生信息int a,b;struct student * p;printf( 請(qǐng)輸入學(xué)生編號(hào) );scanf(%d,&a);p=head2; printf( 學(xué)號(hào)學(xué)生姓名所選課程編號(hào) 所選課程學(xué)分 n);while(p!=NULL

25、)if(p-num2=a)printf(%6d%13s ,p-num2,p-name2);for(b=0;p-nelenumb!=0&bnelenumb);printf(%10dn,p-nelen);p=p-next;void search2()/按學(xué)生姓名查找學(xué)生信息int b;char name20;struct student * p;printf( 請(qǐng)輸入要查找的學(xué)生姓名 :);scanf(%s,name);p=head2;printf( 學(xué)號(hào)學(xué)生姓名所選課程編號(hào) 所選課程學(xué)分 n);while(p!=NULL)if(strcmp(name,p-name2)=0)printf(%6d%13s ,p-num2,p-name2);for(b=0;p-nelenumb!=0&bnelenumb);printf(%10dn,p-nelen);p=p-next;void search()/學(xué)生信息查找主函數(shù)int i;printf(tttprintf(n1.printf(n2.學(xué)生信息查找 ); 按學(xué)號(hào)查找 ); 按姓名查找 );printf(n3.printf(n返回主菜單 ); 請(qǐng)輸入 1-3:);scanf(%d,&i);switch(i) cas

溫馨提示

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

評(píng)論

0/150

提交評(píng)論