//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();

这是一个C语言编写的简单学生选修课系统,包括输入、保存和查询功能。代码中可能存在错误,需要进行修正,如结构体成员初始化、内存分配和文件操作等。

2万+

被折叠的 条评论
为什么被折叠?



