C语言程序设计,学生选课系统

C语言程序设计,学生选课系统,第1张

这是这几天我用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=0kk1<1100kk1++)

for(kk2=0kk2<1200kk2++)

for(kk3=0kk3<1200kk3++)

}

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()//录入键盘子函数(从文件录入)

#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=headpp->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=headpp->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=headptr2ptr2=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=0i<5i++)

{

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=0i<5i++)

{

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=0i<5i++)

strcpy(p->title[i],title[i][12])

if(hand=NULL)

hand=q

else

tall->other=q

tall=q

scanf_form()

for(i=0i<5i++)

{

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=handqq=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=handqq->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=handprt2prt2=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=handprtprt=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)

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/11557693.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-17
下一篇 2023-05-17

发表评论

登录后才能评论

评论列表(0条)

保存