📄 xuanke4.c
字号:
}
}
printf(" Current semester is %d!\n",stu->semester);
printf(" %d courses pass!\n",cournum);
printf(" %d courses not pass!\n",key-cournum);
printf(" %d course select!\n",selnum);
printf(" Get %.0f credit hour.\n",getvalue);
printf(" Average score is %.2f!\n",(allscore/allvalue));
printf(" Press any key to continue......");
getch();
clrscr();
goto STUPART;
/*显示所有学生*/ALLSTU:
/*将所有简单学生信息写入allstu数组*/
clrscr();
TeacherScr2();
fp=fopen("allstudent","r");
if(fp==NULL)
{
printf("File open error!\n");
fclose(fp);
getch();
clrscr();
goto STUPART;
}
key=0;
while(!feof(fp))
{
fread(allstu[key],sizeof(struct Stu),1,fp);
key++;
}
fclose(fp);
printf("The list of all student:\n");
printf(" num name studynum\n");
for(i=0;i<key-1;i++)
{
printf(" %-2d %-20s%s\n",i+1,allstu[i]->name,allstu[i]->num);
}
printf("Press any key to continue!\n");
getch();
clrscr();
goto STUPART;
SPECIALPASS:/*特殊操作*********************************/
clrscr();
TeacherScr2();
printf("Please input student studynumber(press 5 back,press 6 exist):\n");
scanf("%s",a);
if(a[0]=='5')
{
clrscr();
goto STUPART;
}
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);
}
SPECIAL:
clrscr();
TeacherScr3();
printf(" Please input operation number:");
scanf("%d",&key);
switch(key)
{
case 1:goto SPESCORE;/*特定科目输入学生成绩*/
case 2:goto SPESEMESTER; /*使学生进入特定学期*/
case 3:goto SPESELECT;/*为学生选择特定课程*/
case 4:goto SPECOURSE;/*使学生有权利选特定课程*/
case 5:clrscr(); goto STUPART;
case 6:goto END;
default: printf("Input error!\n");
printf("Press any key to continue......\n");
getch();
clrscr();
goto SPECIAL;
}
/*特定科目输入学生成绩*/SPESCORE:
clrscr();
TeacherScr3();
printf("############## GIVE SPECIAL SCORE ##############\n");
for(i=0;i<26;i++)
{
printf("*%2d %-28s *",i+1,all[i].name);
if((i%2)==1)
printf("\n");
}
printf("\n");
printf("Please input scourse number:");
scanf("%d",&i);
if(i>=1&&i<=26)
{
printf("Please input score:");
scanf("%d",&all[i-1].score);
if(all[i-1].score>=0&&all[i-1].score<=100)
{
if(all[i-1].score>=60&&all[i-1].score<=100)
{
all[i-1].flag=3;
printf("Give score success!\n");
}
else if(all[i-1].score>=0&&all[i-1].score<60)
{
all[i-1].flag=1;
printf("Give score success!\n");
}
WriteInfo();
strcpy(av[1],a);
if((fp=fopen(av[1],"w"))==NULL)
{
printf("Open file error!\n");
getch();
clrscr();
goto SPECIAL;
}
else fwrite(stu,sizeof(struct Student),1,fp);
fclose(fp);
}
else/*分数不在0和100之间*/
printf("Score error!Please input number between 0 and 100.\n");
printf("Press any key to continue......\n(Press 'B' to back special operation section)\n");
back=getch();
if(back=='b'||back=='B')
{
goto SPECIAL;
}
else
{
goto SPESCORE;
}
}
else/*i不再1和26之间*/
{
printf("Scourse number error!\n");
printf("Press any key to continue......\n(Press 'B' to back special operation section)\n");
back=getch();
if(back=='b'||back=='B')
{
goto SPECIAL;
}
else
{
goto SPESCORE;
}
}
/*使学生进入特定学期*/SPESEMESTER:
clrscr();
TeacherScr3();
printf("############## CHANGE SEMESTER ##############\n");
printf("Current semester is %d.\n",stu->semester);
printf("Change into which semester:");
scanf("%d",&stu->semester);
printf("Semester change success!\n");
WriteInfo();
strcpy(av[1],a);
if((fp=fopen(av[1],"w"))==NULL)
{
printf("Open file error!\n");
getch();
clrscr();
goto SPECIAL;
}
else fwrite(stu,sizeof(struct Student),1,fp);
fclose(fp);
printf("Press any key to continue!");
getch();
goto SPECIAL;
/*为学生选择特定课程*/SPESELECT:
clrscr();
TeacherScr3();
printf("############## SELECT SPECIAL COURSE ##############\n");
cournum=-1;
for(i=0;i<26;i++)
{
if(all[i].flag<2)
{
cournum++;
printf("*%2d %-28s *",i+1,all[i].name);
if((cournum%2)==1)
printf("\n ");
}
}
printf("\n ");
printf("Please input course number:");
scanf("%d",&i);
if(i>=1&&i<=26)
{
if(all[i-1].flag<1)
all[i-1].flag=1;
Select(i-1);
}
else
{
printf("Course number error!");
}
printf("Press any key to continue......\n(Press 'B' to back special operation section)\n");
back=getch();
if(back=='b'||back=='B')
{
WriteInfo();
strcpy(av[1],a);
if((fp=fopen(av[1],"w"))==NULL)
{
printf("Open file error!");
getch();
clrscr();
goto SPECIAL;
}
else fwrite(stu,sizeof(struct Student),1,fp);
fclose(fp);
clrscr();
goto SPECIAL;
}
else
{
clrscr();
goto SPESELECT;
}
/*使学生有权利选特定课程*/SPECOURSE:
clrscr();
TeacherScr3();
printf("############## COURSE COULD SELECT ##############\n");
cournum=-1;
for(i=0;i<26;i++)
{
if(all[i].flag<1)
{
cournum++;
printf("*%2d %-28s *",i+1,all[i].name);
if((cournum%2)==1)
printf("\n");
}
}
printf("\n");
printf("Please input scourse number to let student could select:");
scanf("%d",&i);
if(i>=1&&i<=26)
{
switch(all[i-1].flag)
{
case -1:
case 0:
case 1:all[i-1].flag=1;printf("Succeed!\n");break;
case 2:printf("Error!Have selectde the course!\n");break;
case 3:printf("Error!Have finish the course!\n");break;
default:printf("Course flag error!");
}
}
else
{
printf("Course number error!");
}
printf("Press any key to continue......\n(Press 'B' to back special operation section)\n");
back=getch();
if(back=='b'||back=='B')
{
WriteInfo();
strcpy(av[1],a);
if((fp=fopen(av[1],"w"))==NULL)
{
printf("Open file error!");
getch();
clrscr();
goto SPECIAL;
}
else
{
fwrite(stu,sizeof(struct Student),1,fp);
fclose(fp);
goto SPECIAL;
}
}
else/*back不为'B'时*/
{
goto SPECOURSE;
}
/*修改密码*/PASSWORD:
if((fp=fopen("password","w+"))==NULL)
{
printf("\nSorry can't find password file!\n");
getch();
clrscr();
goto TEACHER;
}
RESET: printf("\nPlease input new password:\n");
for(i=0;i<6;i++)
{
pass1[i]=getch();
printf("*");
}
pass1[i]='\0';
printf("\nPlease input new password again:\n");
for(i=0;i<6;i++)
{
pass2[i]=getch();
printf("*");
}
pass2[i]='\0';
if(strcmp(pass1,pass2)==0)
{
fputs(pass1,fp);
printf("\nPassword reset!\n");
}
else
{
printf("\nPassword error!");
printf("Press any key to continue......\n");
getch();
clrscr();
TeacherScr();
goto RESET;
}
fclose(fp);
printf("Press any key to continue......\n");
getch();
clrscr();
goto TEACHER;
/*************************************教师界面结束**********************************/
STUDENTPASS:/*学生登录界面*/
clrscr();
StartScr();
printf("Please input your studynumber:");
scanf("%s",a);
strcpy(av[1],a);
if((fp=fopen(av[1],"r"))==NULL)
{
printf("Sorry,no account!");
printf("Press any key to continue......");
getch();
clrscr();
goto STUDENTPASS;
}
else fread(stu,sizeof(struct Student),1,fp);
ReadInfo();
fclose(fp);
STUDENT:
clrscr();
StudentScr();
printf(" Please input operation number:");
scanf("%d",&key);
switch(key)
{
case 1:goto SELECT;
case 2:goto SCORE;
case 3:goto VALUE;
case 4:goto SELECTED;
case 5:goto BACK;
case 6:goto END;
default: printf("Input error!\n");
printf("Press any key to continue......\n");
getch();
clrscr();
goto STUDENT;
}
/*选择课程*/ SELECT:
clrscr();
StudentScr();
printf("############## SELECT COURSE ##############\n");
selnum=ShowCourToSelect();
if(selnum==0)
{
printf("There is no course to select!\n");
printf("Press any key to continue......\n");
getch();
WriteInfo();
strcpy(av[1],a);
if((fp=fopen(av[1],"w"))==NULL)
{
printf("Open file error!");
getch();
clrscr();
goto STUDENT;
}
else fwrite(stu,sizeof(struct Student),1,fp);
fclose(fp);
clrscr();
goto STUDENT;
}
printf("Input the course number you want to select:");
scanf("%d",&i);
if(i<1||i>26)
{
printf("Course number input error!\n");
printf("Press any key to continue......");
getch();
clrscr();
goto SELECT;
}
Select(i-1);
if(all[i-1].flag==2)
{
printf("Press any key to continue......\n(Press 'B' to back student first section)\n");
back=getch();
if(back=='b'||back=='B')
{
WriteInfo();
strcpy(av[1],a);
if((fp=fopen(av[1],"w"))==NULL)
{
printf("Open file error!");
getch();
clrscr();
goto STUDENT;
}
else fwrite(stu,sizeof(struct Student),1,fp);
fclose(fp);
clrscr();
goto STUDENT;
}
else
{
clrscr();
StudentScr();
goto SELECT;
}
}
else
{
printf("Select error!\n");
printf("Press any key to continue......\n(Press 'B' to back student first section)\n");
back=getch();
if(back=='b'||back=='B')
{
WriteInfo();
strcpy(av[1],a);
if((fp=fopen(av[1],"w"))==NULL)
{
printf("Open file error!");
getch();
clrscr();
goto STUDENT;
}
else fwrite(stu,sizeof(struct Student),1,fp);
fclose(fp);
clrscr();
goto STUDENT;
}
else
{
clrscr();
StudentScr();
goto SELECT;
}
}
/*成绩查询*/SCORE:
clrscr();
StudentScr();
printf("############## INQUIRE SCORE ##############\n");
getvalue=0;
allvalue=0;
allscore=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;
if(all[i].score!=0)
{
allscore=allscore+all[i].score*all[i].value;
allvalue=allvalue+all[i].value;
printf(" %-2d %-30s %d %-10s %d \n",i+1,all[i].name,all[i].value,all[i].character,all[i].score);
}
}
if(allscore==0)
printf("No course get score!\n");
else
{
printf("You have get %.0f credit hour.\n",getvalue);
printf("Average score is %.2f!\n",(allscore/allvalue));
}
printf("Press any key to continue......\n");
getch();
clrscr();
goto STUDENT;
/*学分查询*/VALUE:
clrscr();
StudentScr();
getvalue=0;
allvalue=0;
for(i=0;i<26;i++)
{
if(all[i].flag==3)
getvalue=getvalue+all[i].value;
if(all[i].flag==2)
allvalue=allvalue+all[i].value;
}
printf("You have get %.0f credit hour.\n",getvalue);
printf("Credit hour of all selected course is %.0f.\n",allvalue);
printf("Press any key to continue......\n");
getch();
clrscr();
goto STUDENT;
/*已选课程*/SELECTED:
clrscr();
StudentScr();
allvalue=0;
printf("############## SELECTED COURSES ##############\n");
printf("number coursename semester credit hour character\n");
for(i=0;i<26;i++)
{
if(all[i].flag==2)
{
allvalue=allvalue+all[i].value;
printf(" %-2d %-30s %d %d %-10s\n",i+1,all[i].name,all[i].semester,all[i].value,all[i].character);
}
}
if(allvalue==0)
printf("No course selected!\n");
else printf("Credit hour of all selected course is %.0f.\n",allvalue);
printf("Press any key to continue......\n");
getch();
clrscr();
goto STUDENT;
BACK:/*返回首页*/
clrscr();
goto START;
END:/*退出程序*/
exit(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -