当前位置:首页 » 编程语言 » 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;
}