📄 xuanke4.c
字号:
#include <stdio.h>
#include <string.h>
#include <conio.h>
#define MAXSTU 30
/*定义课程结构***********************/
typedef struct cour{
char name[40];/*课程名称*/
int semester;/*开始学期*/
int score;/*考试分数*/
int value;/*所占学分*/
int flag;/*课程标志:-1表示还有前继课程未修,0表示无前继课程,1表示可选择该课程,2表示已选择该课程,3表示该课程已通过*/
char character[10];
struct cour *before;
struct cour *next;
}course;
/*定义学生信息结构**********************/
struct Student{
char name[10];
char num[9];
int semester;
int data[26*2];/*双数记录考试分数,单数记录课程标志*/
}*stu;
/*定义学生简单信息结构********************/
struct Stu{
char name[30];
char num[9];
}*Stu,*allstu[MAXSTU];
course all[26]=
{{"Advanced Mathematics",1,0,5,0,"required"},
{"College Physics",2,0,6,-1,"required"},
{"Circuitry Analysis",1,0,3,0,"required"},
{"Analogical Electronics",2,0,4,-1,"required"},
{"Digital Electronics",3,0,4,-1,"required"},
{"Principles of Microcomputer",4,0,6,-1,"required"},
{"Programming with C Language",1,0,5,0,"required"},
{"Visual C++ Programming",2,0,4,-1,"required"},
{"Java Language Programming",3,0,4,-1,"required"},
{"Discrete Mathematics",2,0,4,0,"required"},
{"Data Structure",3,0,6,-1,"required"},
{"Operating system",4,0,4,-1,"required"},
{"Database Principles",5,0,5,-1,"required"},
{"Software engineering",5,0,4,0,"required"},
{"Assembly Language",4,0,4,0,"required"},
{"Graph theory",6,0,3,0,"required"},
{"College English",1,0,5,0,"required"},
{"Compilation Method",5,0,4,0,"required"},
{"Linear Algebra",2,0,3,0,"required"},
{"Graduation Project",6,0,10,0,"required"},
{"Network Technology",2,0,5,0,"elective"},
{"Specialty English",3,0,4,0,"elective"},
{"Set Theory",2,0,5,0,"elective"},
{"Numeric Calculation",1,0,4,0,"elective"},
{"Fundamentals of Law",1,0,3,0,"elective"},
{"Intelligence robot",4,0,5,0,"elective"}};
/*初始界面显示***************************/
StartScr()
{
printf("###############################################################################\n");
printf("####### Welcome to Course System! ######\n");
printf("###############################################################################\n");
printf("####### 1.Login with Teacher 2.Login with Student 3.Exit ######\n");
printf("###############################################################################\n\n");
}
TeacherScr()
{
printf("###############################################################################\n");
printf("####### Welcome to Course System!(Teacher Part) ######\n");
printf("###############################################################################\n");
printf("####### 1.Creat user 2.Student 3.Change password 4.Back 5.Exit ######\n");
printf("###############################################################################\n\n");
}
TeacherScr2()
{
printf("###############################################################################\n");
printf("####### Welcome to Course System!(Teacher Part 2) ######\n");
printf("###############################################################################\n");
printf("####### 1.Give score 2.Student infor 3.Show course ######\n");
printf("####### 4.Special operation 5.Back 6.Exit ######\n");
printf("###############################################################################\n\n");
}
TeacherScr3()
{
printf("###############################################################################\n");
printf("####### Welcome to Course System!(Teacher Part 3) ######\n");
printf("###############################################################################\n");
printf("####### 1.Give score 2.Semester operation 3.Select course ######\n");
printf("####### 4.Course could select 5.Back 6.Exit ######\n");
printf("###############################################################################\n\n");
}
StudentScr()
{
printf("###############################################################################\n");
printf("####### Welcome to Course System!(Student Part) ######\n");
printf("###############################################################################\n");
printf("####### 1.Select course 2.Inquire score 3.Inquire credit hour ######\n");
printf("####### 4.Selected course 5.back 6.Exit ######\n");
printf("###############################################################################\n\n");
}
/*将学生信息课程部分读入课程信息组*/
ReadInfo()
{
int i;
for(i=0;i<26;i++)
{
all[i].score=stu->data[(i+1)*2-2];
all[i].flag=stu->data[(i+1)*2-1];
}
}
/*将课程信息组写入学生信息课程部分*/
WriteInfo()
{
int i;
for(i=0;i<26;i++)
{
stu->data[(i+1)*2-2]=all[i].score;
stu->data[(i+1)*2-1]=all[i].flag;
}
}
/*输出可选课程*/
ShowCourToSelect()
{
int i,j=0;
printf("number coursename semester credit hour character\n");
for(i=0;i<26;i++)
{
if((all[i].semester<=stu->semester&&(all[i].flag==0))||all[i].flag==1)
{
all[i].flag=1;
j++;
printf(" %-2d %-30s %d %d %-10s\n",i+1,all[i].name,all[i].semester,all[i].value,all[i].character);
}
}
return j;
}
/*选课函数*/
Select(int i)
{
switch(all[i].flag)
{
case 1:all[i].flag=2;printf("%s selected!\n",all[i-1].name);break;
case 2:printf("Error!You have select the course before!\n");break;
case 3:printf("Error!You have finish the course!\n");break;
case 0:printf("Error!You can't select the course this semester.\n");break;
case -1:printf("Error!Can't select!Doesn't finish former course.\n");break;
default: printf("Flag error!\n");
}
}
main(int argc,char *av[])
{
FILE *fp;/*文件指针*/
int key;/*记录操作数*/
int i;/*循环计数*/
int cournum;/*课程数目*/
int selnum;/*选择课程数目*/
int score;/*记录所输入成绩*/
int x,y;/*记录位置*/
char pass1[7],pass2[7];/*记录密码*/
char back;/*记录返回操作数*/
float getvalue=0,allvalue=0,allscore;
char a[10],b[10]; /*记录学号及姓名*/
/*课程链接*/
/***************关联课程1****************/
all[0].before=NULL;all[0].next=&all[1];
all[1].before=&all[0];all[1].next=NULL;
/***************关联课程2****************/
all[2].before=NULL;all[2].next=&all[3];
all[3].before=&all[2];all[3].next=&all[4];
all[4].before=&all[3];all[4].next=&all[5];
all[5].before=&all[4];all[5].next=NULL;
/***************关联课程2****************/
all[6].before=NULL;all[6].next=&all[7];
all[7].before=&all[6];all[7].next=&all[8];
all[8].before=&all[4];all[8].next=NULL;
/***************关联课程3****************/
all[9].before=NULL;all[9].next=&all[10];
all[10].before=&all[9];all[10].next=&all[11];
all[11].before=&all[10];all[11].next=&all[12];
all[12].before=&all[11];all[12].next=NULL;
/***************无关联课程****************/
for(i=13;i<26;i++)
{
all[i].before=NULL;all[i].next=NULL;
}
/******************课程连接结束*****************************/
START:
StartScr();
printf(" Please input operation number:");
scanf("%d",&key);
switch(key)
{
case 1:goto TEACHERPASS;
case 2:goto STUDENTPASS;
case 3:goto END;
default: printf("Input error!\n");
printf("Press any key to continue......\n");
getch();
clrscr();
goto START;
}
TEACHERPASS:
/*密码登录*/
printf(" Please input teacher password:");
for(i=0;i<6;i++)
{
pass1[i]=getch();
printf("*");
}
pass1[i]='\0';
if((fp=fopen("password","r"))==NULL)
{
printf("\nSorry,can't find password file!\n");
printf("Press any key to continue......\n");
getch();
goto START;
}
else fgets(pass2,7,fp);
fclose(fp);
if(strcmp(pass1,pass2)!=0)
{
printf("\nPassword error!\n");
printf("Press any key to continue......\n");
getch();
clrscr();
goto START;
}
else printf("Login with Teacher success!\n");
printf("Press any key to continue......\n");
clrscr();
goto TEACHER;
/*进入教师首页*/
TEACHER:
TeacherScr();
printf(" Please input operation number:");
scanf("%d",&key);
switch(key)
{
case 1:goto CREAT;/*产生新用户*/
case 2:goto STUPART;/*进入学生信息界面*/
case 3:goto PASSWORD;
case 4:goto BACK;
case 5:goto END;
default: printf("Input error!\n");
printf("Press any key to continue......\n");
getch();
clrscr();
goto TEACHER;
}
/*产生新用户*/CREAT:
clrscr();
TeacherScr();
printf("############## CREAT NEW USER ##############\n");
printf("Now you will creat a new user.\nPlease input studynumber:");
scanf("%s",a);
if(strlen(a)!=8)
{
printf("Studynumber input error!\n");
printf("Press any key to continue......\n(Press 'B' to back teacher first section)\n");
back=getch();
if(back=='b'||back=='B')
{
clrscr();
goto TEACHER;
}
else
{
clrscr();
TeacherScr();
goto CREAT;
}
}
strcpy(av[1],a);
fp=fopen(av[1],"r");
if(fp!=NULL)
{
printf("Sorry,the user has existed!\n");
printf("Press any key to continue......\n(Press 'B' to back teacher first section)\n");
back=getch();
if(back=='b'||back=='B')
{
clrscr();
fclose(fp);
goto TEACHER;
}
else
{
clrscr();
TeacherScr();
fclose(fp);
goto CREAT;
}
}
else fclose(fp);
printf("Please input the name:");
scanf("%s",b); /*********************/printf("b=%s\n",b);
strcpy(stu->name,b);
strcpy(stu->num,a);
stu->semester=1;
for(i=0;i<26*2;i++)
{
stu->data[i]=0;
}
/*将数据写入学生信息文件*/
strcpy(av[1],a);
if((fp=fopen(av[1],"w"))==NULL)
{
printf("Sorry,can't creat new user!\n");
getch();
fclose(fp);
clrscr();
goto TEACHER;
}
else
{
fwrite(stu,sizeof(struct Student),1,fp);
fclose(fp);
}
printf("stu->name3:%s,stu->num3:%s\n",stu->name,stu->num);
/*将简单学生信息数据写入所有学生信息文件*/
strcpy(Stu->name,b);
strcpy(Stu->num,a);
printf("Stu->name:%s,Stu->num:%s\n",Stu->name,Stu->num);
fp=fopen("allstudent","a");
if(fp==NULL)
{
printf("Sorry,can't creat new user!\n");
fclose(fp);
getch();
clrscr();
goto TEACHER;
}
else
{
fwrite(Stu,sizeof(struct Stu),1,fp);
fclose(fp);
printf("Creat success!\n");
}
printf("Press any key to continue......\n(Press 'B' to back teacher first section)\n");
back=getch();
if(back=='b'||back=='B')
{
clrscr();
fclose(fp);
goto TEACHER;
}
else
{
clrscr();
TeacherScr();
fclose(fp);
goto CREAT;
}
/*进入学生信息界面*/
STUPART:
clrscr();
TeacherScr2();
printf(" Please input operation number:");
scanf("%d",&key);
switch(key)
{
case 1:goto GIVESCORE;/*输入学生成绩*/
case 2:goto SHOWSTUINFO; /*显示学生信息*/
case 3:goto ALLSTU;/*显示所有学生*/
case 4:goto SPECIALPASS;/**/
case 5:clrscr(); goto TEACHER;
case 6:goto END;
default: printf("Input error!\n");
printf("Press any key to continue......\n");
getch();
clrscr();
goto STUPART;
}
/*输入学生成绩*/GIVESCORE:
/*输入学号*/
printf(" Please input student studynumber(press 5 back,press 6 exist):\n ");
scanf("%s",a);
if(a[0]=='5')
{
clrscr();
goto TEACHER;
}
else if(a[0]=='6') goto END;
strcpy(av[1],a);
if((fp=fopen(av[1],"r"))==NULL)
{
printf("Sorry,no account!");
getch();
clrscr();
goto STUPART;
}
else fread(stu,sizeof(struct Student),1,fp);
ReadInfo();
fclose(fp);
clrscr();
TeacherScr2();
printf("####### STUDYNUMBER: %-9s ######\n",stu->num);
printf("number coursename credit hour character score\n");
allvalue=0;
getvalue=0;
for(i=0;i<26;i++)
{
if(all[i].flag==2)
{
allvalue=all[i].value+allvalue;
printf(" %-2d %-30s %d %-10s ",i+1,all[i].name,all[i].value,all[i].character);
GET:
x=wherex();
y=wherey();
scanf("%d",&score);
if(score>=0&&score<=100)
{
all[i].score=score;
if(all[i].score>=60)
{
all[i].flag=3;
getvalue=getvalue+all[i].value;
if (all[i].next!=NULL)
all[i].next->flag=0;
}
else all[i].flag=1;
}
else
{
printf("Score input error!");
printf("Press any key to continue...(Press 'B' back teacher part 2)");
back=getch();
if(back=='b'||back=='B')
{
goto SPECIAL;
}
else
{
gotoxy(x,y);
printf("\n");
clreol();
gotoxy(x,y);
clreol();
goto STUPART;
}
}
}
}
if(allvalue==0)
{
printf("Error!No course selected!\n");
printf("Press any key to continue......\n");
getch();
clrscr();
goto STUPART;
}
else if((getvalue/allvalue)>0.6&&getvalue>=10)/*学分修够选课的60%,并且本学期得到10个学分可以进入下一学期*/
{
stu->semester++;
printf("Get enough credit hour,goto semester %d.\n",stu->semester);
printf("Press any key to continue......\n");
getch();
}
else
{
printf("Didn't get enough credit hour,stay on semester %d.\n",stu->semester);
printf("Press any key to continue......\n");
getch();
}
WriteInfo();
strcpy(av[1],a);
if((fp=fopen(av[1],"w"))==NULL)
{
printf("Open file error!\n");
getch();
clrscr();
goto STUPART;
}
else fwrite(stu,sizeof(struct Student),1,fp);
fclose(fp);
clrscr();
goto STUPART;
/*显示学生信息*/ SHOWSTUINFO:
clrscr();
TeacherScr2();
printf("Please input student studynumber(press 5 back,press 6 exist):\n");
scanf("%s",a);
if(a[0]=='5')
{
clrscr();
goto TEACHER;
}
else if(a[0]=='6') goto END;
strcpy(av[1],a);
if((fp=fopen(av[1],"r"))==NULL)
{
printf("Sorry,no account!");
getch();
clrscr();
goto STUPART;
}
else fread(stu,sizeof(struct Student),1,fp);
ReadInfo();
fclose(fp);
clrscr();
TeacherScr2();
printf("############## SHOW STUDENT INFORMATION ##############\n");
printf("####### STUDYNUMBER: %-9s ######\n",stu->num);
getvalue=0;
allvalue=0;
allscore=0;
key=0;
cournum=0;
selnum=0;
printf("number coursename credit hour character score\n");
for(i=0;i<26;i++)
{
if(all[i].score>=60)
{
getvalue=getvalue+all[i].value;
cournum++;
}
if(all[i].score!=0)
{
allscore=allscore+all[i].score*all[i].value;
allvalue=allvalue+all[i].value;
key++;
printf(" %-2d %-30s %d %-10s %d \n",i+1,all[i].name,all[i].value,all[i].character,all[i].score);
}
if(all[i].flag==2)
{
selnum++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -