當前位置:首頁 » 編程語言 » c語言課程設計選課系統
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言課程設計選課系統

發布時間: 2023-05-31 21:39:51

c語言 學生選課系統設計

這個程序屬於大作業類了,300+行,估計沒人寫的

❷ C語言學生選修課系統

//7《學生選修課程系統》設計任務
//(1)輸入功能:輸入30名學生學號、班級、姓名、選修課名稱。
//(2)設置要求:每個學生至少選修3科,總選修科目至少設置15科。
//(3)查詢功能:按學號、姓名、選修課顯示各選修課上課時間和地點。

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<malloc.h>
typedef struct subjects
{
int num;
char na[10];
char teacher[20];
char wtime[10];
char ttime[10];
int score;
struct subjects *next;
}SUB;
SUB *create_form()
{
SUB *head,*tail,*p;
int num,score;
char na[10],teacher[20],wtime[10],ttime[10];
head=tail=NULL;
printf(" 輸入選課程信息,以6個0結束:\n");
printf(" 課程代碼 課名 任教老師 上課星期 上課時間 學分\n");
scanf("%d%10s%14s%10s%8s%6d",&num,&na,&teacher,&wtime,&ttime,&score);
while(num!=0)
{
p=(SUB*)malloc(sizeof(SUB));
p->num;
strcpy(p->na,na);
strcpy(p->teacher,teacher);
strcpy(p->wtime,wtime);
strcpy(p->ttime,ttime);
p->score=score;
if(head==NULL)
head=p;
else
tail->next=p;
tail=p;
scanf("%d%s%s%s%s%d",&num,&na,&teacher,&wtime,&ttime,&score);
}
tail->next=NULL;
return head;
}
void savefile(SUB*head)
{
SUB *p;
FILE *fp;
fp=fopen("subjects.txt","w");
fprintf(fp,"歡迎進入東華理工大學2008-2009學年選修課系統(4-13)\n");
fprintf(fp,"課程代碼 課名 任教老師 上課星期 上課時間 學分\n");
for(p=head;p;p->next)
fprintf(fp,"%6d%10s%14s%10s%8s%6d",p->num,p->na,p->teacher,p->wtime,p->ttime,p->score);
fclose(fp);
}
void prin(SUB *head)
{
SUB *p;
if (head==NULL)
{
printf("沒有選修課程記錄!\n");
return;
}
printf("歡迎進入東華理工大學2008-2009學年選修課系統(4-13)\n");
printf("課程代碼 課名 任教老師 上課星期 上課時間 學分\n");
for(p=head;p;p->next)
printf("%6d%10s%16s%12s%12s%d",p->num,p->na,p->teacher,p->wtime,p->ttime,p->score);
}
SUB *inset(SUB *head)
{
SUB *ptr,*ptr2,*subj;
char ch, ch1;
printf("是否進行插入課程,如果需要插入請按回車建,不進行按空格結束!\n");
ch=getchar();
while(ch!=' '){
subj=(SUB*)malloc(sizeof(SUB));
ptr=subj;
printf(" 輸入要插入的課程信息:\n");
scanf("%d%s%s%s%s%d",subj->num,subj->na,subj->teacher,subj->wtime,subj->ttime,subj->score);
if(head==NULL){
head=ptr;
head->next=NULL;
}
else{
for(ptr2=head;ptr2;ptr2=ptr2->next)
if(ptr2->next==NULL){
ptr2->next=subj;
subj->next=NULL;
break;
}
ch='a';
}
printf("繼續請按回車建,結束請按空格:\n");
ch1=getchar();
ch=getchar();
}
return head;
}
SUB *del(SUB *head)
{
SUB*p1,*p2;
char ch,ch1;
int num;
printf("是否進行課程刪除,要刪除請按回車鍵,不進行請按空格:\n");
ch=getchar();
while(ch!=' ')
{
printf("輸入要刪除的課程代碼:\n");
scanf("%d",&num);
if(head->num==num){
p2=head;
head=head->next;
free(p2);
}
if(head==NULL)
return NULL;
p1=head;
p2=head->next;
while(p2!=NULL){
if(p2->num==num){
p1->next=p2->next;
free(p2);
}
else
p1=p2;
p2=p1->next;
}
printf("繼續刪除請按回車鍵,結束請按空格:\n");
ch1=getchar();
ch=getchar();
}
return head;
}
typedef struct student
{
int number;
int classes;
char chinesename[16];
char title [5][12];
struct student *other;
}STU;
void scanf_form(SUB *head)
{
int i,count,number,classes;
char ch,title[3][12],chinesename[16];
scanf("%d%d%16s",&number,&classes,&chinesename);
for(i=0;i<5;i++)
{
scanf("%s",&title[i]);
count++;
if(count==3)
{
ch=getchar();
if(ch!=' ')
{title[3][12]='0';
title[4][12]='0';
i=5;
ch='a';
}
}
if(count==4)
{
ch=getchar();
if(ch!=' ')
{title[4][12]='0';
i=5;
ch='a';
}
}
for(i=0;i<5;i++)
{
if(strcmp(title[i][12],head->na)!=0 && title[i][12]!='0')
{ printf("你輸入的課程名不正確,請從新輸入:\n");
scanf_form();
}
}
}
}
STU *study_form(SUB*head)
{
STU *hand,*tall,*q;
int i;
char ch,ch1;
hand=tall=NULL;
printf("輸入你個人信息,及選修的課名,以4個0結束:\n");
printf("註:每個學生至少選修3門課,大於3門時按回車鍵繼續,空格結束:\n");
scanf_form();
while(number!=0)
{
q=(STU*)malloc(sizeof(STU));
q->number=number;
q->classes=classes;
strcpy(p->chinesename,chinesename);
for(i=0;i<5;i++)
strcpy(p->title[i],title[i][12]);
if(hand=NULL)
hand=q;
else
tall->other=q;
tall=q;
scanf_form();
for(i=0;i<5;i++)
{
if(strcmp(title[i][12],head->na)!=0&&titli[i][12]!='0')
{ printf("你輸入的課程名不正確,請從新輸入:\n");
scanf_form();
}
}
tall->other=NULL;
return hand;
}
}
void savefiles(STU*hand)
{
STU *q;
FILE *fq;
fq=fopen("studennt.txt","w");
fprintf(fq, "學生選課信息表:\n");
for(q=hand;q;q=q->other)
fprintf(fq,"%16d%10d%16s%16s%16s%16s%16s%16s",q->number,q->classes,q->chinesename,q->title[0],q->title[1],q->title[2],q->title[3],q->title[4]);
fclose(fq);
}
void prins(STU*hand)
{
STU *q;
if(head==NULL)
{
printf("沒有學生選課信息記錄!\n");
return;
}
printf("學生選課信息一覽表:\n");
printf("學號 班級 姓名 課名 :\n");
for(q=hand;q;q->number)
printf("%16d%10d%16s%16s%16s%16s%16s%16s",q->number,q->classes,q->chinesename,q->title[0],q->title[1],q->title[2],q->title[3],q->title[4]);
}
STU *intserts(SUB*head,STU *hand)
{
STU *prt,*prt2,*stuj;
int i;
char ch,ch1;
printf("是否要進行插入學生選課信息,如果需要請按回車建,結束請按0:\n");
ch=getchar();
while(ch!=' ')
{
stuj=(STU*)malloc(sizeof(STU));
prt=stuj;
printf("輸入要插入的學生選課信息:\n");
scanf_form();
if(hand==NULL)
{hand=prt;
hand->other=NULL;
}
else
{for(prt2=hand;prt2;prt2=prt2->other)
if(prt2->other==NULL)
{prt2->other=stuj;
stuj->other=NULL;
break;
}
ch='a';
}
printf("繼續插入請按回車建,結束請按空格:\n");
ch1=getchar();
ch=getchar();
}
return hand;
}
STU *dells(STU *hand)
{
STU *q1,*q2;
char ch,ch1;
int number;
printf("是否進行學生選課信息刪除,要刪除請按回車建,不進行請按空格:\n");
ch=getchar();
while(ch!=' ')
{
printf("輸入要刪除的學號:\n");
scanf("%d",&number);
if(hand->number==number)
{
q2=hand;
hand=hand->other;
free(q2);
}
if(hand=NULL)
return NULL;
q1=hand;
q2=hand->other;
while(q2)
{if(q2->number==number)
{q1->other=q2->other;
free(q2);
}
else
q1=q2;
q2=q1->other;
}
printf("繼續刪除請按回車建,結束請按空格:\n");
ch1=getchar();
ch1=getchar();
}
return hand;
}
void search(STU*hand)
{
int a,number;
int t=1;
char type[10],ch,ch1;
STU *prt;
printf("是否進入查詢,按回車鍵進入,空格結束:\n");
ch=getchar();
while(ch!=' ')
{
printf("請輸入要查詢的學號:\n");
for(prt=hand;prt;prt=prt->other)
{
if(number=prt->number)
{printf("%16d%10d%16s%16s%16s%16s%16s%16s",prt->number,prt->classes,prt->chinesename,prt->title[0],prt->title[1],prt->title[2],prt->title[3],prt->title[4]);
t=0;
}
if(t!=0)
printf("未找到!\n");
t=1;
}
printf("繼續查找請按回車鍵,結束請按空格鍵:\n");
ch1=getchar();
ch=getchar();
}
}
void main()
{
SUB *head=create_form() ;
savefile(head);
prin(head);
head= inset(head);
head= del(head);
STU *hand=study_form(head);
savefiles(hand);
prins(hand);
hand=intserts(head,hand);
hand=dells(hand);
search(hand);
}

❸ 學生選課系統C語言程序

根據自己的需要,自己看著修改一下 ^^
#include<stdio.h>
#include<stdlib.h>
int N1,N2,kk1,kk2,kk3;
struct couse * head1;
struct student * head2;
struct couse//課程信息結構體
{
int num1;
char name1[20];
int score;
int nelepeo;//課程已選人數
int Melepeo;//課程人數上限
struct couse * next;
};
struct student//學生信息結構體
{
int num2;
char name2[20];
int nelenum[50];//已選課程編號
int nelen;//已選課程數量
struct student * next;
};
void Ms()
{
for(kk1=0;kk1<1100;kk1++)
for(kk2=0;kk2<1200;kk2++)
for(kk3=0;kk3<1200;kk3++);
}
void keyboardc()//錄入課程子函數(從鍵盤錄入)
{
struct couse *p1,*p2;
N1=0;
p1=p2=(struct couse*)malloc(sizeof(struct couse));
printf("課程編號\t課程名稱\t學分\t課程人數上限\n");
scanf("%d%s%d%d",&p1->num1,p1->name1,&p1->score,&p1->Melepeo);
p1->nelepeo=0;
head1=NULL;
while(p1->num1!=0)
{
N1=N1+1;
if(N1==1)head1=p1;
else p2->next=p1;
p2=p1;
p1=(struct couse * )malloc(sizeof(struct couse));
scanf("%d%s%d%d",&p1->num1,p1->name1,&p1->score,&p1->Melepeo);
p1->nelepeo=0;
}
p2->next=NULL;
}
void filec()//錄入鍵盤子函數(從文件錄入)
{
FILE * fp;
char filepath[20];
struct couse *p1,*p2;
N1=0;
printf("輸入要讀入的文件路徑:");
getchar();
gets(filepath);
if((fp=fopen(filepath,"r"))==NULL)
{
printf("找不到%s文件!\n",filepath);
exit(0);
}
p1=p2=(struct couse*)malloc(sizeof(struct couse));
fscanf(fp,"%d%s%d%d%d",&p1->num1,p1->name1,&p1->score,&p1->nelepeo,&p1->Melepeo);
head1=NULL;
while(!feof(fp))
{
N1=N1+1;
if(N1==1)head1=p1;
else p2->next=p1;
p2=p1;
p1=(struct couse * )malloc(sizeof(struct couse));
fscanf(fp,"%d%s%d%d%d",&p1->num1,p1->name1,&p1->score,&p1->nelepeo,&p1->Melepeo);
}
p2->next=NULL;
}
void inputc()//錄入課程主函數
{
int i;
printf("\t\t\t錄入課程信息\n");
printf("\n1.從鍵盤錄入\n");
printf("2.從文件錄入\n");
printf("3.返回主菜單\n");
printf("請選擇(1~3):\n");
scanf("%d",&i);
switch(i)
{
case(1):keyboardc();break;
case(2):filec();break;
case(3):break;
}
}
void insertc(struct couse *incouse)//課程管理子函數(增加課程)
{
struct couse *p0,*p1,*p2;
p1=head1;
p0=incouse;
if(head1==NULL)
{
head1=p0;
p0->next=NULL;
}
else
{
while((p0->num1 > p1->num1) && (p1->next!=NULL))
{
p2=p1;
p1=p1->next;
}
if(p0->num1 <= p1->num1)
{
if(head1==p1) head1=p0;
else p2->next=p0;
p0->next=p1;
}
else
{
p1->next=p0;
p0->next=NULL;
}
}
N1=N1+1;
}
void delc(int num1)//課程管理子函數(刪除課程)
{
struct couse *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;
else p2->next=p1->next;
printf("已刪除該編號課程!\n");
N1=N1-1;
}
else printf("無該編號的課程!\n");
end:;
}
void managementc()//課程管理主函數
{
struct couse * incouse;
int i,num1;
printf("\t\t\t課程管理\n");
printf("1.新增課程\n");
printf("2.刪除課程\n");
printf("3.返回主菜單\n");
printf("請選擇(1~3):\n");
scanf("%d",&i);
switch(i)
{
case(1):
{
incouse=(struct couse *)malloc(sizeof(struct couse));
printf("課程編號\t課程名稱\t學分\t課程人數上限\n");
scanf("%d%s%d%d",&incouse->num1,incouse->name1,&incouse->score,&incouse->Melepeo);
incouse->nelepeo=0;
insertc(incouse);
break;
}
case(2):
{
printf("請輸入要刪除課程的編號:\n");
scanf("%d",&num1);
delc(num1);
break;
}
case(3):break;
}
}
void keyboards()//錄入學生信息子函數(從鍵盤錄入)
{
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->name2);
p1->nelen=0;
for(i=0;i<20;i++) p1->nelenum[i]=0;
head2=NULL;
while(p1->num2!=0)
{
N2=N2+1;
if(N2==1)head2=p1;
else p2->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->nelenum[i]=0;
}
p2->next=NULL;
}
void files()//錄入學生信息子函數(從文件錄入)
{
int i=0;
FILE * fp;
char filepath[20];
struct student *p1,*p2;
N2=0;
printf("輸入要讀入的文件路徑:");
getchar();
gets(filepath);
if((fp=fopen(filepath,"r"))==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 p2->next=p1;
p2=p1;
p1=(struct student * )malloc(sizeof(struct student));
fread(p1,sizeof(struct student),1,fp);
}
p2->next=NULL;
}
void inputs()//錄入學生信息主函數
{
int i;
printf("\t\t\t錄入學生信息\n");
printf("\n1.從鍵盤錄入\n");
printf("2.從文件錄入\n");
printf("3.返回主菜單\n");
printf("請選擇(1~3):\n");
scanf("%d",&i);
switch(i)
{
case(1):keyboards();break;
case(2):files();break;
case(3):break;
}
}
void inserts(struct student * incouse)//學生信息管理子函數(填加學生信息)
{
struct student *p0,*p1,*p2;
p1=head2;
p0=incouse;
if(head2==NULL)
{
head2=p0;
p0->next=NULL;
}
else
{
while((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;
}
else
{
p1->next=p0;
p0->next=NULL;
}
}
N2=N2+1;
}
void dels(int num2)//學生信息管理子函數(刪除學生信息)
{
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;
else p2->next=p1->next;
printf("已刪除該學生信息!\n");
N2=N2-1;
}
else printf("無該學號的學生!\n");
end:;
}
void managements()//學生信息管理主函數
{
struct student * incouse;
int i,num2;
printf("\t\t\t學生信息管理\n");
printf("1.新增學生信息\n");
printf("2.刪除學生信息\n");
printf("3.返回主菜單\n");
printf("請選擇(1~3):\n");
scanf("%d",&i);
switch(i)
{
case(1):
{
incouse=(struct student *)malloc(sizeof(struct student));
incouse->nelen=0;
incouse->nelenum[0]=0;
printf("學生學號\t學生姓名\n");
scanf("%d%s",&incouse->num2,incouse->name2);
inserts(incouse);
break;
}
case(2):
{
printf("請輸入要刪除學生的學號:\n");
scanf("%d",&num2);
dels(num2);
break;
}
case(3):break;
}
}
void elect(struct student * s)//選課
{
struct couse * p;
int num1,i;
printf("請輸入要選課的編號:\n");
scanf("%d",&num1);
for(i=0;s->nelenum[i]!=0;i++);
s->nelenum[i]=num1;
(s->nelen)++;
p=head1;
while(p->num1!=num1) p=p->next;
(p->nelepeo)++;
}
void cheak()//學生選課子函數(查詢可選課程)
{
char e;
struct couse * c;
struct student * s;
int num2,i,j=0,t=0;
printf("請輸入你的學號:");
scanf("%d",&num2);
s=head2;
while(s->num2!=num2 && s->next!=NULL) s=s->next;
if(s->num2!=num2)
{
printf("不存在你的信息,請進入主菜單錄入你的信息!\n");
goto end;
}
c=head1;
printf("你的可選課程編號:\n");
while(c!=NULL)
{
for(t=0,i=0;s->nelenum[i]!=0;i++)
{
if(c->num1==s->nelenum[i]) t=1;
}
if(t==0 && (c->nelepeo!=c->Melepeo))
{
printf("%d\n",c->num1);
j++;
}
c=c->next;
}
if(j==0)
{
printf("你已選完所有課程,無法再多選!\n");
goto end;
}
printf("選課(y/n)?:\n");
getchar();
e=getchar();
i=0;
while(e=='y')
{
elect(s);
printf("繼續選課(y/n)?:\n");
getchar();
e=getchar();
}
end:;
}
void back(struct student * p)//退課
{
struct couse * p1;
int num1,i,j;
printf("請輸入你要退掉的課程編號:\n");
scanf("%d",&num1);
p1=head1;
while(p1->num1!=num1) p1=p1->next;
for(i=0;p->nelenum[i]!=num1;i++);
for(j=i;p->nelenum[j]!=0;j++) p->nelenum[j]=p->nelenum[j+1];
p->nelenum[--j]=0;
(p1->nelepeo)--;
printf("退課成功!\n");
}
void hcheak()//學生選課子函數(查詢已選課程)
{
char c;
struct couse * p0;
struct student * p;
int num2,i,f=0;
printf("請輸入學號:\n");
scanf("%d",&num2);
p=head2;
while(p->num2!=num2 && p!=NULL) p=p->next;
if(p==NULL)
{
printf("不存在你的信息,請回主菜單錄入信息:\n");
goto end;
}
printf("已選課程編號:\n");
if(p->nelenum[0]==0)
{
printf("你還沒選課!\n");
goto end;
}
for(i=0;p->nelenum[i]!=0;i++)
{
printf("%d\n",p->nelenum[i]);
p0=head1;
while(p0->num1!=p->nelenum[i]) p0=p0->next;
f=f+p0->score;
}
printf("總學分:%d\n",f);
printf("是否進行退課(y/n)?");
getchar();
c=getchar();
while(c=='y')
{
back(p);
printf("繼續退課(y/n)?");
getchar();
c=getchar();
(p->nelen)--;
}
end:;
}
void elective()//學生選課主函數
{
int i;
printf("\t\t\t學生選課\n");
printf("1.查詢可選課程\n");
printf("2.查詢已選課程\n");
printf("3.返回主菜單\n");
printf("請輸入(1~3):\n");
scanf("%d",&i);
switch(i)
{
case(1):cheak();break;
case(2):hcheak();break;
case(3):break;
}
}
void listc()//輸出課程信息
{
struct couse * p;
p=head1;
printf("課程編號 課程名稱 學分 課程已選人數 課程人數上限\n");
while(p!=NULL)
{
printf("%-8d%10s%6d%8d%12d\n",p->num1,p->name1,p->score,p->nelepeo,p->Melepeo);
p=p->next;
}
}
void lists()//輸出學生信息
{
struct student * p;
p=head2;
printf("學生學號 學生姓名 已選課程數量\n");
while(p!=NULL)
{
printf("%-4d %10s %6d\n",p->num2,p->name2,p->nelen);
p=p->next;
}
}
void intoc()//存儲課程信息
{
FILE * fp;
struct couse * p;
char filepath[30];
printf("輸入課程信息要保存的文件路徑:");
getchar();
gets(filepath);
if((fp=fopen(filepath,"w"))==NULL)
{
printf("\n保存失敗!");
exit(0);
}
p=head1;
while(p!=NULL)
{
fprintf(fp,"%d %s %d %d %d\n",p->num1,p->name1,p->score,p->nelepeo,p->Melepeo);
p=p->next;
}
fclose(fp);
printf("課程信息已保存在%s中!\n",filepath);
}
void intos()//存儲學生信息
{
FILE * fp;
struct student * p;
char filepath[30];
printf("輸入學生信息要保存的文件路徑:");
getchar();
gets(filepath);
if((fp=fopen(filepath,"w"))==NULL)
{
printf("\n保存失敗!");
exit(0);
}
p=head2;
while(p!=NULL)
{
fwrite(p,sizeof(struct student),1,fp);
p=p->next;
}
fclose(fp);
printf("學生信息已保存在%s中!\n",filepath);
}
void into()//存儲信息
{
int i;
printf("1.存儲課程信息\n");
printf("2.存儲學生信息\n");
printf("3.返回主菜單\n");
printf("請輸入(1~3)\n");
scanf("%d",&i);
switch(i)
{
case(1):intoc();break;
case(2):intos();break;
case(3):break;
}
}
void store()//信息主函數
{
int i;
printf("\t\t系統信息查看及存儲\n");
printf("1.查看課程信息\n");
printf("2.查看學生信息\n");
printf("3.存儲信息\n");
printf("4.返回主菜單\n");
printf("請輸入(1~4):\n");
scanf("%d",&i);
switch(i)
{
case(1):listc();break;
case(2):lists();break;
case(3):into();break;
case(4):break;
}
}
int main()//主函數
{
int i;
start:
printf("\n\t\t\t歡迎使用學生選課系統!\n");
printf("菜單:\n");
printf("1.錄入課程信息\n");
printf("2.課程管理\n");
printf("3.錄入學生信息\n");
printf("4.學生信息管理\n");
printf("5.學生選課\n");
printf("6.系統信息查看及存儲\n");
printf("7.退出系統\n");
printf("\n請輸入菜單選項(1~7):\n");
scanf("%d",&i);
if(i<1 || i>7)
{
printf("輸入錯誤,請重輸:\n");
goto start;
}
switch(i)
{
case(1):
{
system("cls");
inputc();
goto start;
break;
}
case(2):
{
system("cls");
managementc();
goto start;
break;
}
case(3):
{
system("cls");
inputs();
goto start;
break;
}
case(4):
{
system("cls");
managements();
goto start;
break;
}
case(5):
{
system("cls");
elective();
goto start;
break;
}
case(6):
{
system("cls");
store();
goto start;
break;
}
case(7):
{
system("cls");
printf("感謝使用本系統!\n\n再見!\n");
}
}
return(0);
}

❹ 急求c語言:學生選課系統程序設計(最好含流程圖 的)

#include<stdio.h>
#include<stdlib.h>
int N1,N2,kk1,kk2,kk3;
struct couse * head1;
struct student * head2;
struct couse//課程信息結構體
{
int num1;
char name1[20];
int score;
int nelepeo;//課程已選人數
int Melepeo;//課程人數上限
struct couse * next;
};
struct student//學生信息結構體
{
int num2;
char name2[20];
int nelenum[50];//已選課程編號
int nelen;//已選課程數量
struct student * next;
};
void Ms()
{
for(kk1=0;kk1<1100;kk1++)
for(kk2=0;kk2<1200;kk2++)
for(kk3=0;kk3<1200;kk3++);
}
void keyboardc()//錄入課程子函數(從鍵盤錄入)
{
struct couse *p1,*p2;
N1=0;
p1=p2=(struct couse*)malloc(sizeof(struct couse));
printf("課程編號\t課程名稱\t學分\t課程人數上限\n");
scanf("%d%s%d%d",&p1->num1,p1->name1,&p1->score,&p1->Melepeo);
p1->nelepeo=0;
head1=NULL;
while(p1->num1!=0)
{
N1=N1+1;
if(N1==1)head1=p1;
else p2->next=p1;
p2=p1;
p1=(struct couse * )malloc(sizeof(struct couse));
scanf("%d%s%d%d",&p1->num1,p1->name1,&p1->score,&p1->Melepeo);
p1->nelepeo=0;
}
p2->next=NULL;
}
void filec()//錄入鍵盤子函數(從文件錄入)
{
FILE * fp;
char filepath[20];
struct couse *p1,*p2;
N1=0;
printf("輸入要讀入的文件路徑:");
getchar();
gets(filepath);
if((fp=fopen(filepath,"r"))==NULL)
{
printf("找不到%s文件!\n",filepath);
exit(0);
}
p1=p2=(struct couse*)malloc(sizeof(struct couse));
fscanf(fp,"%d%s%d%d%d",&p1->num1,p1->name1,&p1->score,&p1->nelepeo,&p1->Melepeo);
head1=NULL;
while(!feof(fp))
{
N1=N1+1;
if(N1==1)head1=p1;
else p2->next=p1;
p2=p1;
p1=(struct couse * )malloc(sizeof(struct couse));
fscanf(fp,"%d%s%d%d%d",&p1->num1,p1->name1,&p1->score,&p1->nelepeo,&p1->Melepeo);
}
p2->next=NULL;
}
void inputc()//錄入課程主函數
{
int i;
printf("\t\t\t錄入課程信息\n");
printf("\n1.從鍵盤錄入\n");
printf("2.從文件錄入\n");
printf("3.返回主菜單\n");
printf("請選擇(1~3):\n");
scanf("%d",&i);
switch(i)
{
case(1):keyboardc();break;
case(2):filec();break;
case(3):break;
}
}
void insertc(struct couse *incouse)//課程管理子函數(增加課程)
{
struct couse *p0,*p1,*p2;
p1=head1;
p0=incouse;
if(head1==NULL)
{
head1=p0;
p0->next=NULL;
}
else
{
while((p0->num1 > p1->num1) && (p1->next!=NULL))
{
p2=p1;
p1=p1->next;
}
if(p0->num1 <= p1->num1)
{
if(head1==p1) head1=p0;
else p2->next=p0;
p0->next=p1;
}
else
{
p1->next=p0;
p0->next=NULL;
}
}
N1=N1+1;
}
void delc(int num1)//課程管理子函數(刪除課程)
{
struct couse *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;
else p2->next=p1->next;
printf("已刪除該編號課程!\n");
N1=N1-1;
}
else printf("無該編號的課程!\n");
end:;
}
void managementc()//課程管理主函數
{
struct couse * incouse;
int i,num1;
printf("\t\t\t課程管理\n");
printf("1.新增課程\n");
printf("2.刪除課程\n");
printf("3.返回主菜單\n");
printf("請選擇(1~3):\n");
scanf("%d",&i);
switch(i)
{
case(1):
{
incouse=(struct couse *)malloc(sizeof(struct couse));
printf("課程編號\t課程名稱\t學分\t課程人數上限\n");
scanf("%d%s%d%d",&incouse->num1,incouse->name1,&incouse->score,&incouse->Melepeo);
incouse->nelepeo=0;
insertc(incouse);
break;
}
case(2):
{
printf("請輸入要刪除課程的編號:\n");
scanf("%d",&num1);
delc(num1);
break;
}
case(3):break;
}
}
void keyboards()//錄入學生信息子函數(從鍵盤錄入)
{
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->name2);
p1->nelen=0;
for(i=0;i<20;i++) p1->nelenum[i]=0;
head2=NULL;
while(p1->num2!=0)
{
N2=N2+1;
if(N2==1)head2=p1;
else p2->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->nelenum[i]=0;
}
p2->next=NULL;
}
void files()//錄入學生信息子函數(從文件錄入)
{
int i=0;
FILE * fp;
char filepath[20];
struct student *p1,*p2;
N2=0;
printf("輸入要讀入的文件路徑:");
getchar();
gets(filepath);
if((fp=fopen(filepath,"r"))==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 p2->next=p1;
p2=p1;
p1=(struct student * )malloc(sizeof(struct student));
fread(p1,sizeof(struct student),1,fp);
}
p2->next=NULL;
}
void inputs()//錄入學生信息主函數
{
int i;
printf("\t\t\t錄入學生信息\n");
printf("\n1.從鍵盤錄入\n");
printf("2.從文件錄入\n");
printf("3.返回主菜單\n");
printf("請選擇(1~3):\n");
scanf("%d",&i);
switch(i)
{
case(1):keyboards();break;
case(2):files();break;
case(3):break;
}
}
void inserts(struct student * incouse)//學生信息管理子函數(填加學生信息)
{
struct student *p0,*p1,*p2;
p1=head2;
p0=incouse;
if(head2==NULL)
{
head2=p0;
p0->next=NULL;
}
else
{
while((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;
}
else
{
p1->next=p0;
p0->next=NULL;
}
}
N2=N2+1;
}
void dels(int num2)//學生信息管理子函數(刪除學生信息)
{
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;
else p2->next=p1->next;
printf("已刪除該學生信息!\n");
N2=N2-1;
}
else printf("無該學號的學生!\n");
end:;
}
void managements()//學生信息管理主函數
{
struct student * incouse;
int i,num2;
printf("\t\t\t學生信息管理\n");
printf("1.新增學生信息\n");
printf("2.刪除學生信息\n");
printf("3.返回主菜單\n");
printf("請選擇(1~3):\n");
scanf("%d",&i);
switch(i)
{
case(1):
{
incouse=(struct student *)malloc(sizeof(struct student));
incouse->nelen=0;
incouse->nelenum[0]=0;
printf("學生學號\t學生姓名\n");
scanf("%d%s",&incouse->num2,incouse->name2);
inserts(incouse);
break;
}
case(2):
{
printf("請輸入要刪除學生的學號:\n");
scanf("%d",&num2);
dels(num2);
break;
}
case(3):break;
}
}
void elect(struct student * s)//選課
{
struct couse * p;
int num1,i;
printf("請輸入要選課的編號:\n");
scanf("%d",&num1);
for(i=0;s->nelenum[i]!=0;i++);
s->nelenum[i]=num1;
(s->nelen)++;
p=head1;
while(p->num1!=num1) p=p->next;
(p->nelepeo)++;
}
void cheak()//學生選課子函數(查詢可選課程)
{
char e;
struct couse * c;
struct student * s;
int num2,i,j=0,t=0;
printf("請輸入你的學號:");
scanf("%d",&num2);
s=head2;
while(s->num2!=num2 && s->next!=NULL) s=s->next;
if(s->num2!=num2)
{
printf("不存在你的信息,請進入主菜單錄入你的信息!\n");
goto end;
}
c=head1;
printf("你的可選課程編號:\n");
while(c!=NULL)
{
for(t=0,i=0;s->nelenum[i]!=0;i++)
{
if(c->num1==s->nelenum[i]) t=1;
}
if(t==0 && (c->nelepeo!=c->Melepeo))
{
printf("%d\n",c->num1);
j++;
}
c=c->next;
}
if(j==0)
{
printf("你已選完所有課程,無法再多選!\n");
goto end;
}
printf("選課(y/n)?:\n");
getchar();
e=getchar();
i=0;
while(e=='y')
{
elect(s);
printf("繼續選課(y/n)?:\n");
getchar();
e=getchar();
}
end:;
}
void back(struct student * p)//退課
{
struct couse * p1;
int num1,i,j;
printf("請輸入你要退掉的課程編號:\n");
scanf("%d",&num1);
p1=head1;
while(p1->num1!=num1) p1=p1->next;
for(i=0;p->nelenum[i]!=num1;i++);
for(j=i;p->nelenum[j]!=0;j++) p->nelenum[j]=p->nelenum[j+1];
p->nelenum[--j]=0;
(p1->nelepeo)--;
printf("退課成功!\n");
}
void hcheak()//學生選課子函數(查詢已選課程)
{
char c;
struct couse * p0;
struct student * p;
int num2,i,f=0;
printf("請輸入學號:\n");
scanf("%d",&num2);
p=head2;
while(p->num2!=num2 && p!=NULL) p=p->next;
if(p==NULL)
{
printf("不存在你的信息,請回主菜單錄入信息:\n");
goto end;
}
printf("已選課程編號:\n");
if(p->nelenum[0]==0)
{
printf("你還沒選課!\n");
goto end;
}
for(i=0;p->nelenum[i]!=0;i++)
{
printf("%d\n",p->nelenum[i]);
p0=head1;
while(p0->num1!=p->nelenum[i]) p0=p0->next;
f=f+p0->score;
}
printf("總學分:%d\n",f);
printf("是否進行退課(y/n)?");
getchar();
c=getchar();
while(c=='y')
{
back(p);
printf("繼續退課(y/n)?");
getchar();
c=getchar();
(p->nelen)--;
}
end:;
}
void elective()//學生選課主函數
{
int i;
printf("\t\t\t學生選課\n");
printf("1.查詢可選課程\n");
printf("2.查詢已選課程\n");
printf("3.返回主菜單\n");
printf("請輸入(1~3):\n");
scanf("%d",&i);
switch(i)
{
case(1):cheak();break;
case(2):hcheak();break;
case(3):break;
}
}
void listc()//輸出課程信息
{
struct couse * p;
p=head1;
printf("課程編號 課程名稱 學分 課程已選人數 課程人數上限\n");
while(p!=NULL)
{
printf("%-8d%10s%6d%8d%12d\n",p->num1,p->name1,p->score,p->nelepeo,p->Melepeo);
p=p->next;
}
}
void lists()//輸出學生信息
{
struct student * p;
p=head2;
printf("學生學號 學生姓名 已選課程數量\n");
while(p!=NULL)
{
printf("%-4d %10s %6d\n",p->num2,p->name2,p->nelen);
p=p->next;
}
}
void intoc()//存儲課程信息
{
FILE * fp;
struct couse * p;
char filepath[30];
printf("輸入課程信息要保存的文件路徑:");
getchar();
gets(filepath);
if((fp=fopen(filepath,"w"))==NULL)
{
printf("\n保存失敗!");
exit(0);
}
p=head1;
while(p!=NULL)
{
fprintf(fp,"%d %s %d %d %d\n",p->num1,p->name1,p->score,p->nelepeo,p->Melepeo);
p=p->next;
}
fclose(fp);
printf("課程信息已保存在%s中!\n",filepath);
}
void intos()//存儲學生信息
{
FILE * fp;
struct student * p;
char filepath[30];
printf("輸入學生信息要保存的文件路徑:");
getchar();
gets(filepath);
if((fp=fopen(filepath,"w"))==NULL)
{
printf("\n保存失敗!");
exit(0);
}
p=head2;
while(p!=NULL)
{
fwrite(p,sizeof(struct student),1,fp);
p=p->next;
}
fclose(fp);
printf("學生信息已保存在%s中!\n",filepath);
}
void into()//存儲信息
{
int i;
printf("1.存儲課程信息\n");
printf("2.存儲學生信息\n");
printf("3.返回主菜單\n");
printf("請輸入(1~3)\n");
scanf("%d",&i);
switch(i)
{
case(1):intoc();break;
case(2):intos();break;
case(3):break;
}
}
void store()//信息主函數
{
int i;
printf("\t\t系統信息查看及存儲\n");
printf("1.查看課程信息\n");
printf("2.查看學生信息\n");
printf("3.存儲信息\n");
printf("4.返回主菜單\n");
printf("請輸入(1~4):\n");
scanf("%d",&i);
switch(i)
{
case(1):listc();break;
case(2):lists();break;
case(3):into();break;
case(4):break;
}
}
int main()//主函數
{
int i;
start:
printf("\n\t\t\t歡迎使用學生選課系統!\n");
printf("菜單:\n");
printf("1.錄入課程信息\n");
printf("2.課程管理\n");
printf("3.錄入學生信息\n");
printf("4.學生信息管理\n");
printf("5.學生選課\n");
printf("6.系統信息查看及存儲\n");
printf("7.退出系統\n");
printf("\n請輸入菜單選項(1~7):\n");
scanf("%d",&i);
if(i<1 || i>7)
{
printf("輸入錯誤,請重輸:\n");
goto start;
}
switch(i)
{
case(1):
{
system("cls");
inputc();
goto start;
break;
}
case(2):
{
system("cls");
managementc();
goto start;
break;
}
case(3):
{
system("cls");
inputs();
goto start;
break;
}
case(4):
{
system("cls");
managements();
goto start;
break;
}
case(5):
{
system("cls");
elective();
goto start;
break;
}
case(6):
{
system("cls");
store();
goto start;
break;
}
case(7):
{
system("cls");
printf("感謝使用本系統!\n\n再見!\n");
}
}
return(0);
}

❺ C語言程序設計,學生選課系統

這是這幾天我用C做的一個簡易的學生選課系統.其實是我們的1道程序實踐考試題,我想請大家看看,幫我提些建議.
#include<stdio.h>
#include<stdlib.h>
int N1,N2,kk1,kk2,kk3;
struct couse * head1;
struct student * head2;
struct couse//課程信息結構體
{
int num1;
char name1[20];
int score;
int nelepeo;//課程已選人數
int Melepeo;//課程人數上限
struct couse * next;
};
struct student//學生信息結構體
{
int num2;
char name2[20];
int nelenum[50];//已選課程編號
int nelen;//已選課程數量
struct student * next;
};
void Ms()
{
for(kk1=0;kk1<1100;kk1++)
for(kk2=0;kk2<1200;kk2++)
for(kk3=0;kk3<1200;kk3++);
}
void keyboardc()//錄入課程子函數(從鍵盤錄入)
{
struct couse *p1,*p2;
N1=0;
p1=p2=(struct couse*)malloc(sizeof(struct couse));
printf("課程編號\t課程名稱\t學分\t課程人數上限\n");
scanf("%d%s%d%d",&p1->num1,p1->name1,&p1->score,&p1->Melepeo);
p1->nelepeo=0;
head1=NULL;
while(p1->num1!=0)
{
N1=N1+1;
if(N1==1)head1=p1;
else p2->next=p1;
p2=p1;
p1=(struct couse * )malloc(sizeof(struct couse));
scanf("%d%s%d%d",&p1->num1,p1->name1,&p1->score,&p1->Melepeo);
p1->nelepeo=0;
}
p2->next=NULL;
}
void filec()//錄入鍵盤子函數(從文件錄入)

❻ c語言,編寫學生選課系統代碼,不要錄入文件的

試試這個

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct Person
{
char score; /*編號*/
char name[10]; /*姓名*/
char address[10]; /*住址*/
char workplace[10]; /*單位*/
char num[8]; /*固定電話*/
char mobile[11]; /*移動號碼*/
char sort[10]; /*分類*/
char Email[8]; /*E-mail*/
char QQ[10]; /*QQ*/

};

Person pe[80];

//登陸函數
void logon()
{printf("\n\n\n\t\t\t 通信錄管理\n\n");
printf("\n\n\n\n\n\t\t\t 2014年7月\n\n");
printf("\t\t\t 程序設計\n");
system("pause");
}
int menu_select()
{ char c;
logon();
do{
system("cls");
printf("\t\t *****檔案***** \n");
printf("\t\t┌───────┐\n");
printf("\t\t│ 1. 添加記錄 │\n");
printf("\t\t 2. 刪除記錄 │\n");
printf("\t\t│ 3. 查詢記錄 │\n");
printf("\t\t│ 4. 修改記錄 │\n");
printf("\t\t│ 5. 保存記錄 │\n");
printf("\t\t│ 0. 退出程序 │\n");
printf("\t\t└───────┘\n");
printf("\t\t請您選擇(0-5):");
c=getchar();
}while(c<'0'||c>'5');
return(c-'0');
}

int Input(Person per[],int n)
{
int i=0;
char sign,x[10];
while(sign!='n'&&sign!='N')
{
printf("\t編號:");
scanf("\t%d",&per[n+i].score);
printf("\t姓名:");
scanf("\t%s",per[n+i].name);
printf("\t電話號碼:");
scanf("\t%s",per[n+i].num);
printf("\t單位:");
scanf("\t%s",per[n+i].workplace);
printf("\tE-mail:");
scanf("\t%s",per[n+i].Email);
printf("\t住址:");
scanf("\t%s",per[n+i].address);
printf("\t移動手機:");
scanf("\t%s",per[n+i].mobile);
printf("\tQQ:");
scanf("\t%s",per[n+i].QQ);
printf("\t所屬類別:");
scanf("\t%s",per[n+i].sort);
gets(x);
printf("\n\t是否繼續添加?(Y/N)");
scanf("\t%c",&sign);
i++;
} //插入學生信息,插入一條學生信息之後,執行i++,繼續執行插入,直到不滿足循環條件
return(n+i);
}

int Delete_a_record(Person per[],int n)
{
char s[20];
int i=0,j;
printf("\t請輸入想刪除記錄中的名字:");
scanf("%s",s);
while(strcmp(per[i].name,s)!=0&&i<n)
i++;
if(i==n)
{
printf("\t通訊錄中沒有此人!\n");
return(n);
}
for(j=i;j<n-1;j++)
{
strcpy(per[j].num,per[j+1].num);
strcpy(per[j].name,per[j+1].name);
strcpy(per[j].workplace,per[j+1].workplace);
strcpy(per[j].Email,per[j+1].Email);
strcpy(per[j].address,per[j+1].address);
strcpy(per[j].QQ,per[j+1].QQ);
strcpy(per[j].mobile,per[j+1].mobile);
strcpy(per[j].sort,per[j+1].sort);
per[j].score=per[j+1].score;

} //刪除一條信息後,其後面的信息都要向前移一位
printf("\t\t\t已經成功刪除!\n");
return(n-1);
}
//查詢一條記錄
void Query_a_record(Person per[],int n)
{

int m;
printf("\t\n請選擇查詢方式:\n");
printf("\t┌─────- ┐\n");
printf("\t│1------姓名 │\n");
printf("\t│2------單位 │\n");
printf("\t│3------分類 │\n");
printf("\t│4------返回 │\n");
printf("\t└──────┘\n");
printf("請選擇:");
scanf("%d",&m);
while(m!=1&&m!=2&&m!=3&&m!=4)
{
printf("輸入錯誤,請重新選擇:");
scanf("%d",&m);
}

if(m==1)
{
char s[20];
int i=0;
printf("\t請輸入想查詢的姓名:");
scanf("\t%s",s);
while(strcmp(per[i].name,s)!=0&&i<n) i++;
if(i==n)
{
printf("\t檔案中沒有此人!\n");
return;
}
printf("\t此人編號: %d\n",per[i].score);
printf("\t固定電話: %s\n",per[i].num);
printf("\t單位: %s\n",per[i].workplace);
printf("\tE-mail: %s\n",per[i].Email);
printf("\t此人QQ: %s\n",per[i].QQ);
printf("\t此人手機號: %s\n",per[i].mobile);
printf("\t此人分類: %s\n",per[i].sort);
} ;

if(m==2)
{
char s[20];
int i=0,k=0;
printf("\t請輸入想查詢的單位:");
scanf("\t%s",s);
for(i=0;i<n;i++){
if(strcmp(per[i].workplace,s)==0){
printf("\t此人編號: %d\n",per[i].score);
printf("\t姓名: %s\n",per[i].name);
printf("\t固定電話: %s\n",per[i].num);
printf("\tE-mail: %s\n",per[i].Email);
printf("\t此人QQ: %s\n",per[i].QQ);
printf("\t此人手機號: %s\n",per[i].mobile);
printf("\t此人分類: %s\n",per[i].sort);
printf("\n\n");
}

else
k++;
}
if(k==n)
{
printf("\t檔案中沒有此人!\n");
return;
}

} ;

if(m==3)
{
char s[20];
int i=0,k=0;
printf("\t請輸入想查詢的分類:");
scanf("\t%s",s);
for(i=0;i<n;i++){
if(strcmp(per[i].sort,s)==0){
printf("\t此人編號: %d\n",per[i].score);
printf("\t姓名: %s\n",per[i].name);
printf("\t固定電話: %s\n",per[i].num);
printf("\tE-mail: %s\n",per[i].Email);
printf("\t此人QQ: %s\n",per[i].QQ);
printf("\t此人手機號: %s\n",per[i].mobile);
printf("\t此人單位: %s\n",per[i].sort);
printf("\n\n");
}

else
k++;
}
if(k==n)
{
printf("\t檔案中沒有此人!\n");
return;
}

} ;
}
//修改記錄
void Change(Person per[],int n)
{
char s[20];
int i=0;
printf("\t請輸入想修改的記錄中的名字:");
scanf("%s",s);
while(strcmp(per[i].name,s)!=0&&i<n)
i++;
if(i==n)
{
printf("\t檔案中沒有此人!\n");
return;
}
printf("\t編號:");
scanf("\t%d",&per[i].score);
printf("\t姓名:");
scanf("\t%s",per[i].name);
printf("\t電話號碼:");
scanf("\t%s",per[i].num);
printf("\t單位:");
scanf("\t%s",per[i].workplace);
printf("\tE-mail:");
scanf("\t%s",per[i].Email);
printf("\t住址:");
scanf("\t%s",per[i].address);
printf("\t移動手機:");
scanf("\t%s",per[i].mobile);
printf("\t所屬類別:");
scanf("\t%s",per[i].sort);
printf("\t修改成功!");
}
//寫入文件
void WritetoText(Person per[],int n)
{
int i=0;
FILE *fp; /*定義文件指針*/
char filename[20]; /*定義文件名*/
printf("\t保存到文件\n"); /*輸入文件名*/
printf("\t請輸入所保存的文件名:");
scanf("\t%s",filename);
if((fp=fopen(filename,"w"))==NULL)
{
printf("\t無法打開文件\n");
system("pause");
return;
}
fprintf(fp,"******************************************通訊錄******************************************\n");
fprintf(fp,"編號 姓名 電話號碼 通信地址 電子郵箱\n");
fprintf(fp,"------------------------------------------------------------------------------------------\n");
while(i<n)
{
fprintf(fp,"%-3d\t%-6s\t%-13s\t%-20s\t%-20s\n",per[i].score,per[i].name,per[i].num,per[i].workplace,per[i].Email);
i++;
}
fprintf(fp,"------------------------------------------------------------------------------------------\n");
fprintf(fp,"***************************************共有%d條記錄****************************************\n",n);
fclose(fp); /*關閉文件*/
printf("保存成功!\n");
}

/* 主函數*/
int main()
{
int n=0;
for(;;)
{
switch(menu_select())
{
case 1:
printf("\n\t添加記錄到檔案\n");
n=Input(pe,n);
break;

case 2:
printf("\n\t從檔案中刪除記錄\n");
n=Delete_a_record(pe,n);
printf("\t");
system("pause");
break;

case 3:
printf("\n\t在檔案中查找記錄\n");
Query_a_record(pe,n);
printf("\t");
system("pause");
break;

case 4:
printf("\n\t修改檔案中的記錄\n");
Change(pe,n);
printf("\t");
system("pause");
break;

case 5:
printf("\n\t保存功能\n");
WritetoText(pe,n);
printf("\t");
system("pause");
break;

case 0:
printf("\n\t\t謝謝使用,再見!\n");
printf("\n\t\t");
system("pause");
exit(0); //退出程序
}
}
}

❼ c語言編寫學生選課系統

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
//#include<iostream.h>
void clrscr(void)
{
system("cls");
}
char *getpass(char s[])
{
char *pass,ch;
int i;
pass=new char[100];
i=0;
pass[0]='\0';
printf("%s",s);
while(1)
{
ch=getch();
if(ch!=13)
{
printf("*");
pass[i]=ch;
i++;
pass[i]='\0';
}
else break;
}
//scanf("%s",pass);
return pass;
}
struct course
{
char name[20];
int score;
int students_limited;
course *pNext;
};

struct user
{
char name[20];
char password[17];
char coursename[20];
user *pNext;
};

int Login()
{
char key;

ST1:
clrscr();
printf("\n\n\n\n\n\n\n\t\t\tWelcome to Course System!");
printf("\n\n");
printf("\n\t\t\t1. Login with Administrator");
printf("\n\t\t\t2. Login with Users");
printf("\n\t\t\t0. Exit");
key=getch();

switch(key)
{
case '1' : return 1;
case '2' : return 2;
case '0' : return 0;
default : printf("\n\n\t\t\tInput wrong!\n\t\t\t\tPress any key to continue...");
getch();
goto ST1;
}
}

course *readcourse()
{
FILE *fp;
book *pHead,*pTemp,*pLast;

fp=fopen("coursemsg.dat","r");
if(fp==NULL)
{
printf("\n\n\t\t\tOpen course message file failed!");
return NULL;
}
pHead=NULL;
while(!feof(fp))
{
pTemp=new course;
if(fread(pTemp,sizeof(course),1,fp)!=1)
{
delete pTemp;
break;
}
if(pHead==NULL)
{
pHead=pTemp;
pLast=pTemp;
}
pLast->pNext=pTemp;
pTemp->pNext=NULL;
pLast=pTemp;
}//while
fclose(fp);
return pHead;
}

void writecoursetofile(course *pHead)
{
FILE *fp;
course *pTemp,*pNext;

fp=fopen("coursemsg.dat","w");
for(pTemp=pHead;pTemp;pTemp=pTemp->pNext)
fwrite(pTemp,sizeof(course),1,fp);
fclose(fp);
}

void Add_course()
{
course one,*p;
int i,j;
FILE *fp;

p=&one;
while(1)
{
clrscr();
printf("\n\n\n\n\n\n\n\n\t\tPlease input the name of course(-1 to end):");
//cin>>p->name;
scanf("%s",p->name);
if(!strcmp(p->name,"-1"))break;
i=0;
while(1)
{
if(p->name[i]=='\0')break;
else i++;
}
for(j=i;j<20;j++)p->name[j]='\0';
printf("\n\t\tInput it's scores:");
//cin>>p->score;
scanf("%d",&p->score);
fp=fopen("coursemsg.dat","a+");
fwrite(p,sizeof(course),1,fp);
fclose(fp);
printf("\n\n\t\tAdd course message OK!");
printf("\n\t\t\tPress any key to countinue...");
getch();
}
}

void Del_course()
{
course *pHead,*pNewHead,*pTemp,*pLast;
char name[20];

pHead=readcourse();
printf("\n\t\tPlease input the name of course to be delete:");
gets(name);

while(strcmp(pHead->name,name)==0)
{
pNewHead=pHead->pNext;
printf("\n\n\t\t--%s had been deleted" ,name);
delete pHead;
pHead=pNewHead;
}
for(pTemp=pHead,pLast=pHead;pTemp!=NULL;pLast=pTemp,pTemp=pTemp->pNext)
{
if(strcmp(pTemp->name,name)==0)
{
pLast->pNext=pTemp->pNext;
printf("\n\n\t\t--%s had been deleted" ,name);
delete pTemp;
pTemp=pLast;
}
}//for
writecoursetofile(pHead);
getch();
}

void course_Op()
{
char key;

ST3:
clrscr();
printf("\n\n\n\n\n\n\n\n\t\t\t\t1. Add Course");
printf("\n\t\t\t\t2. Delete Course");
printf("\n\t\t\t\t0. EXIT");
key=getch();
switch(key)
{
case '1' : Add_course();break;
case '2' : Del_course();break;
case '0' : goto _End;
default : printf("\n\tInput wrong!\n\tPress any key to continue...");
getch();
}
goto ST3;

_End:
;
}

void Add_user()
{
FILE *fp;
char name[20],*na,password[6],*pa;
int i,j;
user one,*p;

p=&one;
pa=password;
na=name;

while(1)
{
clrscr();
printf("\n\n\n\n\n\n\n\t\tPlease input user's name(-1 to end):");
gets(name);
if(!strcmp(name,"-1"))break;
pa=getpass("\n\t\tPlease input new password:");
strcpy(p->name,na);
strcpy(p->password,pa);
fp=fopen("usermsg.dat","ab+");
fwrite(p,sizeof(user),1,fp);
fclose(fp);
printf("\n\t\tuser's message has been saved!");
printf("\n\t\tPress any key to countinue...");
getch();
}
}
user *readcusmsg()
{
FILE *fp;
user *pHead,*pTemp,*pLast;

fp=fopen("usermsg.dat","rb");
if(fp==NULL)
{
printf("\n\nOpen user's message file failed");
return NULL;
}
pHead=NULL;

while(!feof(fp))
{
pTemp=new user;
if(fread(pTemp,sizeof(user),1,fp)!=1)
{
delete pTemp;
break;
}
if(pHead==NULL)
{
pHead=pTemp;
pLast=pTemp;
}
pLast->pNext=pTemp;
pTemp->pNext=NULL;
pLast=pTemp;
}//while
fclose(fp);
return pHead;
}

void writecusmsgtofile(user *pHead)
{
FILE *fp;
user *pTemp,*pNext;

fp=fopen("usermsg.dat","wb");
for(pTemp=pHead;pTemp;pTemp=pTemp->pNext)
fwrite(pTemp,sizeof(user),1,fp);
fclose(fp);
}

void user_Op()
{
char key;

ST4:
clrscr();
printf("\n\n\n\n\n\n\n\n\t\t\t\t1. Add Users");
printf("\n\t\t\t\t0. EXIT");
key=getch();

switch(key)
{
case '1' : Add_user();break;
case '0' : goto _End;
default : printf("\n\tInput wrong!\n\tPress any key to continue...");
getch();
}
goto ST4;

_End:;
}

void List_all_course()
{
course *pHead,*pTemp;
int Count=0,tense;

pHead=readcourse();
if(!pHead)
{
printf("\n\t(No data)");
exit(0);
}
printf("\n%30s%8s%10s","course name","Score","Tense");

for(pTemp=pHead;pTemp!=NULL;pTemp=pTemp->pNext)
{
if(pTemp->n>0)tense=1;
else tense=0;
printf("\n%30s%8d%10d",pTemp->name,pTemp->score,tense);
Count++;
if(Count%20==0){printf("Press any key to countinue...");getch();}
}
getch();
}

void Search_course_name()
{
char name[20];
int tense,k=1;
book *pHead,*pTemp,*pNext;

printf("\n\tPlease input the name of the course you want to search:");
gets(name);
pHead=readcourse();
for(pTemp=pHead;pTemp!=NULL;pTemp=pTemp->pNext)
if(!strcmp(pTemp->name,name))
{
if(pTemp->n>0)tense=1;
else tense=0;
k=0;
printf("\n%30s%8d%10d",pTemp->name,pTemp->score,tense);
}
if(k)
{
printf("\n\n\t\tThere's no course named %s",name);
printf("\n\t\t\tPress any key to countinue...");
}
getch();
}

void course_Search()
{
char key;

ST5:
clrscr();
printf("\n\n\n\n\n\n\t\t\t\t1. List all course");
printf("\n\t\t\t\t2. Search by the name of course");
printf("\n\t\t\t\t0. EXIT");
key=getch();

switch(key)
{
case '1' : List_all_course();break;
case '2' : Search_course_name();break;
case '0' : goto _End;
default : printf("\n\t\t\tInput wrong!\n\t\t\tPress any key to continue...");
getch();
}
goto ST5;

_End:;
}

void Pass(int Res)
{
FILE *fp;
char psw[17],*p,pass_in[17],user_name[20];
user *pHead,*pTemp;
int i,k=0;

clrscr();
p=pass;

if(Res==1)
{
if(!(fp=fopen("adm.psw","rb")))
{
printf("\n\n\n\n\n\n\n\t\tWelcome!\n\t******Login Administrator******");
p=getpass("\n\tPlease input your new password:");
fp=fopen("adm.psw","wb");
fprintf(fp,"%s",p);
fclose(fp);
}
else
{
fscanf(fp,"%s",pass_in);
fclose(fp);
printf("\n\n\n\n\n\n\t******Login by Administrator******");
p=getpass("\n\n\t\t\tPlease input your password:");
if(strcmp(p,pass_in))
{
printf("\n\t\tYour Password is wrong!");
printf("\n\t\tPress any key to EXIT...");
getch();
exit(0);
}//if_else
}
Adm_List();
}//if
else
{
printf("\n\n\n\n\n\n\n\n\t\t\t\tWelcome!");
printf("\n\t\t\t******Login by User******");
printf("\n\t\t\tPlease input your name:");
scanf("%s",user_name);
p=getpass("\n\t\t\tPlease input your password:");
pHead=reaser();
for(pTemp=pHead;pTemp!=NULL;pTemp=pTemp->pNext)
if(!strcmp(pTemp->name,user_name))
if(strcmp(pTemp->password,p))
{
k=1;
printf("\n\t\t\tYour password is wrong!");
printf("\n\t\t\t\tPress any key to EXIT...");
getch();
exit(0);
}//if_else
}//psw

int main()
{
int Res;

clrscr();
printf("\n\n\n\n\n\n\n\n");
printf("\n\t*****************************************************************");
printf("\n\t* courses System *");
printf("\n\t* *");
printf("\n\t* QiuYong No.20052419 *");
printf("\n\t* *");
printf("\n\t* 2006-7-20 *");
printf("\n\t*****************************************************************");
printf("\n\t\t\t\t\t\tPress any key to countinue...");
getch();

START:
Res=login();
if(Res==0)goto End;
else if(Res==3)Help();
else Psw(Res);
goto START;

End:
clrscr();
printf("\n\n\n\n\n\n\t\t\tGoodBye ^_^");
return 0;
}