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

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、精品#include<stdio.h>#include<stdlib.h>#include<string.h>int N1,N2;struct studentint num2;char name220;int nelenum50;/ 所選課程編號int nelen;/ 所選課程學分和struct student * next;struct courseint num1;/ 課程編號char name120;char major20;char type20;int credit;int period;char teacher20;int people;/ 選此

2、門課程的人數(shù)struct course *next;/ 結構體指針;struct course * head1;struct student * head2;void zhang()/ 從鍵盤錄入課程信息struct course *p1,*p2;N1=0;p1=p2=(struct course *)malloc(sizeof(struct course);感謝下載載精品printf(" 課程編號 t 課程名稱 t 主修 t 課程性質 t 學分 t 課時 t 教師 n");scanf("%d%s%s%s%d%d%s",&p1->num1,

3、p1->name1,p1->major,p1->t ype,&p1->credit,&p1->period,p1->teacher);p1->people=0;head1=NULL;while(p1->num1!=0)N1=N1+1;if(N1=1)head1=p1;else p2->next=p1;p2=p1;p1=(struct course * )malloc(sizeof(struct course);scanf("%d%s%s%s%d%d%s",&p1->num1,p1->n

4、ame1,p1->major,p1->t ype,&p1->credit,&p1->period,p1->teacher);p1->people=0;p2->next=NULL;void zhang1()/ 從文件錄入課程信息FILE * fp;char filepath20;struct course *p1,*p2;N1=0;printf(" 請輸入您要讀取的路徑 :");getchar();gets(filepath);if(fp=fopen(filepath,"r")=NULL)感謝下載載

5、精品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=

6、1)head1=p1;elsep2->next=p1;p2=p1;p1=(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);p2->next=NULL;void load()/ 錄入課程信息函數(shù)int i;pr

7、intf("ttt錄入課程信息 n");printf("n1.從鍵盤錄入 ");printf("n2.從文件錄入 ");printf("n3.返回主菜單 n");printf(" 請選擇 1-3:");scanf("%d",&i);感謝下載載精品switch(i)case 1: zhang();break;case 2:zhang1();break;case 3:break;void insert(struct course *incourse)/ 增加課程信息str

8、uct course *p0,*p1,*p2;p1=head1;p0=incourse;if(head1=NULL)head1=p0;p0->next=NULL;elsewhile(p0->num1>p1->num1) && (p1->next!=NULL)p2=p1;p1=p1->next;if(p0->num1<=p1->num1)if(head1=p1)head1=p0;elsep2->next=p0;p0->next=p1;感謝下載載精品elsep1->next=p0;p0->next=NUL

9、L;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");N

10、1=N1-1;感謝下載載精品elseprintf(" 沒有此課程 n");end:;void managementc()/ 課程信息管理函數(shù)struct course * p1;int i,num1;printf("ttt課程信息管理 n");printf("1. 添加課程 n");printf("2. 刪除課程 n");printf("3. 返回 n");printf(" 請輸入 1-3:n");scanf("%d",&i);switch(i)c

11、ase 1:p1=(struct course *)malloc(sizeof(struct course);printf(" 課程編號 t 課程名稱 t 主修 t 課程性質 t 學分 t 課時 t 教師 n");scanf("%d%s%s%s%d%d%s",&p1->num1,p1->name1,p1->major,p1->t ype,&p1->credit,&p1->period,p1->teacher);p1->people=0;insert(p1);break;case 2:

12、printf("請輸入您要刪除的課程編號:n");scanf("%d",&num1);delc(num1);break;case 3:break;感謝下載載精品void putin(void)/ 從鍵盤錄入學生信息int i;struct student *p1,*p2;N2=0;p1=p2=(struct student *)malloc(sizeof(struct student);printf(" 學號 t 姓名 n");scanf("%d%s",&p1->num2,p1->nam

13、e2);p1->nelen=0;for(i=0;i<20;i+) p1->nelenumi=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;i<20;i+) p1->nelenumi=0;p2

14、->next=NULL;void putin2()/ 從文件錄入學生信息int i=0;FILE * fp;char filepath20;struct student *p1,*p2;感謝下載載精品N2=0;printf(" 請輸入您要讀取的路徑 :");getchar();gets(filepath);if(fp=fopen(filepath,"rt")=NULL)printf(" 找不到%s 文件 !n",filepath);exit(0);p1=p2=(struct student*)malloc(sizeof(stru

15、ct student);fread(p1,sizeof(struct student),1,fp);head2=NULL;while(!feof(fp)i=0;N2=N2+1;if(N2=1)head2=p1;elsep2->next=p1;p2=p1;p1=(struct student * )malloc(sizeof(struct student);fread(p1,sizeof(struct student),1,fp);p2->next=NULL;void input()/ 錄入學生信息函數(shù)int i;printf("ttt錄入學生信息 n");pri

16、ntf("n1.從鍵盤錄入 n");感謝下載載精品printf("2. 從文件錄入 n");printf("3. 返回主菜單 n");printf(" 請輸入 1-3:n");scanf("%d",&i);switch(i)case 1:putin();break;case 2:putin2();break;case 3:break;void inserts(struct student * incouse)/ 增加學生信息struct student *p0,*p1,*p2;p1=he

17、ad2;p0=incouse;if(head2=NULL)head2=p0;p0->next=NULL;elsewhile(p0->num2>p1->num2) && (p1->next!=NULL)p2=p1;p1=p1->next;if(p0->num2 <= p1->num2)if(head2=p1) head2=p0;感謝下載載精品else p2->next=p0;p0->next=p1;elsep1->next=p0;p0->next=NULL;N2=N2+1;void dels(int n

18、um2)/ 刪除學生信息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(

19、" 沒有此學生編號 n");end:;void managements()/ 學生信息管理函數(shù)struct student * p1;int i,num2;printf("ttt學生信息管理 n");printf("1. 添加學生信息 n");printf("2. 刪除學生信息 n");printf("3. 返回主菜單 n");printf(" 請選擇 1-3:n");scanf("%d",&i);switch(i)case 1:p1=(struc

20、t student *)malloc(sizeof(struct student); p1->nelen=0;p1->nelenum0=0;printf("numtnamen");scanf("%d%s",&p1->num2,p1->name2);inserts(p1);break;case 2:printf("請輸入您要刪除的學生編號:n");scanf("%d",&num2);dels(num2);break;case 3:break;感謝下載載精品void elect(

21、)/ 學生選課struct student * s;struct course * p;int a,i,b;printf(" 請輸入您的學號 :n");scanf("%d",&a);s=head2;while(s->num2)!=a&&s->next!=NULL) s=s->next;if(s->num2!=a)printf(" 您的信息不存在,請重新輸入:n");goto end;if(s->nelen)>10)printf(" 您的學分已滿 ");go

22、to end;printf(" 請輸入您要選修的課程編號n");scanf("%d",&b);for(i=0;(s->nelenumi)=0;i+);s->nelenumi=b;p=head1;while(p->num1)!=b)p=p->next;for(i=0;(s->nelenumi)!=0;i+);s->nelenumi=b;(p->people)+;(s->nelen)=(s->nelen)+(p->credit);(p->people)+;感謝下載載精品end:;voi

23、d back()/ 學生退課struct student * p;struct course * p1;int b,i,j,a;printf(" 請輸入您的學號 :n");scanf("%d",&a);p=head2;while(p->num2!=a&&p!=NULL) p=p->next;if(p=NULL)printf(" 您的信息不存在 :n");elseprintf(" 請輸入您要退選的課程 :n");scanf("%d",&b);p1=hea

24、d1;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->people)-;printf("succeed!n");void elective()/ 學生選課信息管理int i;感謝下載載精品printf("ttt學生選課信息

25、管理 n");printf("1. 選課 n");printf("2. 退課 n");printf("3. 返回主菜單 n");printf(" 請輸入 1-3:n");scanf("%d",&i);switch(i)case 1:elect();break;case 2:back();break;case 3:break;void listc()/ 瀏覽課程信息struct course * p;p=head1;printf(" 課程編號課程名稱主修課程性質學分課時

26、教師選課人數(shù) n");while(p!=NULL)printf("%6d%13s%13s%10s%7d%7d%12s%5dn",p->num1,p->nam e1,p->major,p->type,p->credit,p->period,p->teacher,p->people);p=p->next;void lists()/ 瀏覽學生信息struct student * p;int a;感謝下載載精品p=head2;printf(" 學生編號學生姓名所選課程編號所選課程學分 n");whi

27、le(p!=NULL)printf("%6d%13s",p->num2,p->name2);printf("%6d",p->nelen);for(a=0;p->nelenuma!=0&&a<14;a+)printf("%d",p->nelenuma);printf("n");p=p->next;void intoc()/ 存儲課程信息FILE * fp;struct course * p;char filepath30;printf(" 輸入路徑

28、:");getchar();gets(filepath);if(fp=fopen(filepath,"w")=NULL)無法儲存 !");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->next;fclose(fp);printf(&q

29、uot; 已儲存入 %s 文件 !n",filepath);void intos()/ 存儲學生信息FILE * fp;struct student * p;char filepath30;printf(" 請輸入路徑 :");getchar();gets(filepath);if(fp=fopen(filepath,"wt")=NULL)printf("n無法儲存 !");exit(0);p=head2;while(p!=NULL)fwrite(p,sizeof(struct student),1,fp);p=p->

30、next;fclose(fp);printf(" 已儲存入%s 文件 !n",filepath);void into()/ 信息存儲函數(shù)int i;感謝下載載精品printf("ttt信息存儲 n");printf("1. 課程信息存儲 n");printf("2. 學生信息存儲 tn");printf("3. 返回主菜單 n");printf(" 請輸入 1-3n");scanf("%d",&i);switch(i)case(1):intoc()

31、;break;case(2):intos();break;case(3):break;void store()/ 信息存儲瀏覽函數(shù)int i;printf("tt信息存儲和瀏覽 n");printf("1. 課程信息瀏覽 n");printf("2. 學生信息瀏覽 n");printf("3. 信息存儲 n");printf("4. 返回主菜單 n");printf(" 請輸入 1-4:n");scanf("%d",&i);switch(i)cas

32、e(1):listc();break;case(2):lists();break;case(3):into();break;case(4):break;感謝下載載精品void search1()/ 按學生編號查找學生信息int a,b;struct student * p;printf(" 請輸入學生編號 ");scanf("%d",&a);p=head2;printf(" 學號學生姓名所選課程編號所選課程學分 n");while(p!=NULL)if(p->num2=a)printf("%6d%13s &qu

33、ot;,p->num2,p->name2);for(b=0;p->nelenumb!=0&&b<14;b+)printf("%d",p->nelenumb);printf("%10dn",p->nelen);p=p->next;void search2()/ 按學生姓名查找學生信息int b;char name20;struct student * p;printf(" 請輸入要查找的學生姓名:");scanf("%s",name);p=head2;prin

34、tf(" 學號學生姓名所選課程編號所選課程學分 n");while(p!=NULL)感謝下載載精品if(strcmp(name,p->name2)=0)printf("%6d%13s ",p->num2,p->name2);for(b=0;p->nelenumb!=0&&b<14;b+)printf("%d",p->nelenumb);printf("%10dn",p->nelen);p=p->next;void search()/ 學生信息查找主函數(shù)

35、int i;printf("ttt學生信息查找 ");printf("n1.按學號查找 ");printf("n2.按姓名查找 ");printf("n3.返回主菜單 ");printf("n請輸入 1-3:");scanf("%d",&i);switch(i)case 1:search1();break;case 2:search2();break;case 3:break;void main()/ 主函數(shù)char m;int i;start:printf("

溫馨提示

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

評論

0/150

提交評論