📄 教务管理.txt
字号:
num[i][1]=p2->number;
age[i][0]=p2->age;
found=0;
i++;
}
}
inx:
for(k=NUM;k<3+NUM&&k<i;k++) /*输出格式控制*/
{
cprintf("|\t number:%-22ld|\t name:%-22s|\t sex:%-10s|",num[k][1],student[k][0],student[k][1]);
cprintf("|------------------------------------------------------------------------------|");
cprintf("|\t bir_p:%-23s|\t add:%-23s|\t age:%-10u|",student[k][2],student[k][4],age[k][0]);
cprintf("|------------------------------------------------------------------------------|");
cprintf("|\t mobilephone:%-17s|\t tel:%-23ld|\t kind:%-9s|",student[k][5],num[k][0],student[k][3]);
cprintf("|------------------------------------------------------------------------------|");
}
NUM+=3;
iny: while(bioskey(1)==0);
key=bioskey(0);
key=key&0xff?0:key>>8;
if(key==81){
if(NUM<i){ goto inx;}
else {
cprintf("\t That's all!Reread,pageup! /*翻页显示*/ ");
goto iny;
}
}
if(key==73)
{ if(NUM-3>0){NUM-=6;goto inx;}
else{
cprintf("\t For more information,pagedown! ");
goto iny;
}
}
if(found)
WarnSTU(); /*没有找到学生*/
}
void write_file(struct CLASS *headp,FILE *myfile)/*将数据写入磁盘文件*/
{
struct CLASS *p1;
struct STUD *p2;
struct SUB *p3;
for(p1=headp->next;p1!=NULL;p1=p1->next){
fwrite(p1,sizeof(struct CLASS),1,myfile); /*循环读取各节点信息*/
for(p2=p1->first;p2!=NULL;p2=p2->next){
fwrite(p2,sizeof(struct STUD),1,myfile);
for(p3=p2->first;p3!=NULL;p3=p3->next)
fwrite(p3,sizeof(struct SUB),1,myfile);
}
}
}
struct CLASS * read_file(struct CLASS *headp,FILE *myfile)/*从磁盘文件读信息创建链表*/
{
struct CLASS buf1,*p1,*tail1;
struct STUD buf2,*p2,*tail2;
struct SUB buf3,*p3,*tail3;
int n,m,k;
int flag=0;
for(tail1=headp->next,n=0;n<headp->next->classes;tail1=p1,++n){ /*create the class linetable*/
if(fread(&buf1,sizeof(struct CLASS),1,myfile)!=1)
{ headp->next->classes=n;
break;
}
p1=(struct CLASS *)malloc(sizeof(struct CLASS));
*p1=buf1;
if(headp->next==NULL)
headp->next=p1;
else{
tail1->next=p1;
p1->next=NULL;
}
p1->first=NULL;
/*construct students line*/
for(m=0,tail2=p1->first;m<p1->students;tail2=p2,++m){
if(fread(&buf2,sizeof(struct STUD),1,myfile)!=1)
{ p1->students=m;
break;
}
p2=(struct STUD*)malloc(sizeof(struct STUD));
*p2=buf2;
if(p1->first==NULL)
p1->first=p2;
else{
tail2->next=p2;
p2->next=NULL;
}
p2->first=NULL;
for(tail3=p2->first,k=0;k<p2->subjects;tail3=p3,++k)/*创建课程链*/
{
if(fread(&buf3,sizeof(struct SUB),1,myfile)!=1)
{ p2->subjects=k;
break;
}
p3=(struct SUB *)malloc(sizeof(struct SUB));
*p3=buf3;
if(p2->first==NULL)
p2->first=p3;
else{
tail3->next=p3;
p3->next=NULL;
}
} /*end of subjects' line*/
} /*end of students*/
flag=1;
} /*end of class'*/
if(flag) SUCESSES();
else cprintf("\n FALE IN OPEN!");
return(headp);
}
void out(struct CLASS *headp,int Above,int Below)/*按分数段输出学生成绩*/
{
char OUTPUT[100][2][20];
long OUT1[100][1];
int OUT2[100][1];
int i=0,k,NUM=0,no,subnum,flag=1;
struct STUD *p2;
struct CLASS *p1;
struct SUB *p3;
cprintf("\t Input the class number:");
scanf("%d",&no);
cprintf("\t Input the subject number:");
scanf("%d",&subnum);
for(p1=headp->next; p1!=NULL; p1=p1->next)
{
if(p1->no==no) break;
else continue;
}
if(p1==NULL){WarnCLA();return;}
for(p2=p1->first;p2!=NULL;p2=p2->next)
{for(p3=p2->first;p3!=NULL&&p3->number!=subnum;p3=p3->next);
if(p3->un_score>=Below&&p3->un_score<=Above)/*将分数在BELOW-ABOVE之间的所有学生输出*/
{
strcpy(OUTPUT[i][0],p2->name);
strcpy(OUTPUT[i][1],p3->name);
OUT1[i][0]=p2->number;
OUT2[i][0]=p3->un_score;
i++;
flag=0;
}
else continue;
}
if(flag){cprintf("There is no student!");return;}
inx:for(k=NUM;k<5+NUM&&k<i&&k>=0;k++)
{
cprintf("|\t number:%-10ld|\t name:%-14s|\t SUBname:%-10s |\t un_score:%-3d|",
OUT1[k][0],OUTPUT[k][0],OUTPUT[k][1] ,OUT2[k][0]);
cprintf("|------------------------------------------------------------------------------|");
}
NUM+=5; /*翻页功能设置*/
iny: while(bioskey(1)==0);
key=bioskey(0);
key=key&0xff?0:key>>8;
if(key==81){ /* pagedown */
if(NUM<i) {goto inx;}
else {
cprintf("\t IT IS THE END! ");
goto iny;
}
}
if(key==73){ /* pageup */
if(NUM<=5){
cprintf("\t For more information,page down! ");
goto iny;
}
else {
NUM-=10;
goto inx;
}
}
}
void CLAAVE(struct CLASS *headp)/*求班级的总平均成绩*/
{ struct CLASS *p1;
struct STUD *p2;
struct SUB *p3;
int i,no,A=0;
unsigned sum=0,credit=0;
float CLAave=0;
cprintf("Input the Class Number:");
scanf("%u",&no);
for(p1=headp->next;p1!=NULL;p1=p1->next)
{
if(p1->no==no)break;
else continue;
}
if(p1==NULL){WarnSTU();return;}
for(p2=p1->first;p2!=NULL;p2=p2->next)
for(p3=p2->first;p3!=NULL;p3=p3->next)
{
sum+=SUBAVE(headp,no, p3->number,A)*p3->credit; /*调用求各科平均成绩的函数*/
credit+=p3->credit;
}
CLAave=(float)sum/credit;/*计算班级平均成绩*/
cprintf("The Cla_average of Class%u is %3.2f.",no,CLAave);
}
float SUBAVE(struct CLASS *headp,int no,int subnum,int A)/*计算各科的平均成绩*/
{
struct CLASS *p1;
struct STUD *p2;
struct SUB *p3;
int sum;
float average;
char ch;
float total;
int n,i;
for(p1=headp->next;p1!=NULL;p1=p1->next)
{
if(p1->no==no)break;
else continue;
}
if(p1==NULL){ WarnCLA();goto inEND;}
sum=0;
i=0;
for(p2=p1->first;p2!=NULL;p2=p2->next)
{
for(p3=p2->first;p3!=NULL;p3=p3->next)
{
if(p3->number==subnum)
{
sum+=p3->un_score;
i++;
break;
}
}
}
average=(float)sum/i;
if(A){
cprintf(" \t CLASS %-2u : The %s's average is %-44.2f",p1->no,p3->name,average);/*格式控制*/
cprintf("\-------------------------------------------------------------------------------");
}
inEND: return(average);
}
void incredit(struct CLASS *headp)/*统计学生的学分*/
{
struct CLASS *p1;
struct STUD *p2;
struct SUB *p3;
int total=0,no;
long stu_num;
int flag=0;
cprintf("\n Input the class number:");
scanf("%u",&no);
cprintf("\t Input the student's number:");
scanf("%ld",&stu_num);
for(p1=headp->next;p1!=NULL;p1=p1->next)
{
if(p1->no!=no) continue;
if(p1->no==no) break;
else continue;
}
if(p1==NULL){WarnCLA();return;}
for(p2=p1->first;p2!=NULL;p2=p2->next)
{
if(p2->number!=stu_num)continue;
else break;
}
if(p2==NULL){WarnSTU();return;}
for(p3=p2->first;p3!=NULL;p3=p3->next) /*找到学生*/
{
flag=1;
if(p3->un_score>=60)
total+=p3->credit;
else continue;
}
if(flag)cprintf("|\t class:%-16u|\t student:%-19s|\t total credit:%-8d|",p1->no,p2->name,total);
else WarnSUB();
}
struct CLASS * mod_stu(struct CLASS *headp)/*修改学生基本信息*/
{
struct CLASS *p1;
struct STUD *p2;
int order;
char KIND[20];
char SEX[10];
char Licence[12];
char ch;
int i,flag=1;
long stu_num;
int n=0;
int no;
in1:if(n>3) /*连续四次输入错误密码,返回*/
{ cprintf("Too many errors!");
goto inEND;
}
cprintf("\nInput your keywords:");
scanf("%s",Licence);
do{ cprintf("\nInput the class number:");
scanf("%u",&no);
in2: cprintf("\nInput the student's number:");
scanf("%ld",&stu_num);
if(((stu_num/100)%100)!=no) /*输入的学号与班级号不匹配*/
{cprintf("Wrong numbers!");
goto in2;
}
for(p1=headp->next;p1!=NULL;p1=p1->next)
{
if(p1->no==no) break; /*找到班级入口*/
else continue;
}
if(p1==NULL){WarnCLA();goto inEND;} /*没有找到班级,或班级尚未创建*/
for(p2=p1->first;p2!=NULL;p2=p2->next)
{
if(p2->number!=stu_num)continue;
else break;
} /*找到学生*/
if(p2==NULL){WarnSTU();goto inEND;}
if(strcmp(p2->STUkey,Licence))/*验证密码*/
{ cprintf( "Wrong keywords! ");
n++;
goto in1;
}
/*输入你要修改的内容*/
inx: cprintf("\nInput the item you want to modify(|1:ADMkey |2:STUkey |3:Mobilephone|4:Number|");
cprintf("\n|5:Name |6:Kind |7:Bir_p |8:Age |9:Sex |10:Tel |11:Add |");
scanf("%d",&order);
if(order==1)
{
cprintf("\t Input the Administer's new keywords : ");
for(i=0;i<strlen(p1->ADMkey);i++)
p1->ADMkey[i]=' ';
scanf("%s",p1->ADMkey);
flag=0;
}
if(order==2)
{
cprintf("\t Input the %s's new keywords : ",p2->name);
for(i=0;i<strlen(p2->STUkey);i++)
p2->STUkey[i]=' ';
scanf("%s",p2->STUkey);
flag=0;
}
if(order==3)
{
cprintf("\t Input %s's new mobilephone number:",p2->name);
scanf("%ld",&p2->mobilephone);
flag=0;
}
if(order==4)
{
in3: cprintf("\t Input %s's new number:",p2->name);
scanf("%ld",&p2->number);
if(((stu_num/100)%100)!=no)/*学号要与班级号码匹配*/
{ cprintf("Wrong numbers!");
goto in3;
}
flag=0;
}
if(order==5)
{
cprintf("\t Input the student %s's new name : ",p2->name);
for(i=0;i<strlen(p2->name);i++)
p2->name[i]=' ';
scanf("%s",p2->name);
flag=0;
}
if(order==6)
{
for(i=0;i<strlen(p2->kind);i++)
p2->kind[i]=' ';
in4: cprintf("\t Input %s's new kind:",p2->name);/*输入信息要与要求的匹配*/
scanf("%s",KIND);
if(strcmp(KIND,"Party")==0||strcmp(KIND,"League")==0||strcmp(KIND,"Pioneer")==0||strcmp(KIND," ")==0)
strcpy(p2->kind,KIND);
else { cprintf("Wrong information!Insert again!");
goto in4;
}
flag=0;
}
if(order==7)
{
for(i=0;i<strlen(p2->bir_p);i++)
p2->bir_p[i]=' ';
cprintf("\t Input %s's new birth place:",p2->name);
scanf("%s",p2->bir_p);
flag=0;
}
if(order==8)
{
cprintf("\t Input %s's new age:",p2->name);
scanf("%u",&p2->age);
flag=0;
}
if(order==9)
{
for(i=0;i<strlen(p2->sex);i++)
p2->kind[i]=' ';
in5: cprintf("\t Input %s's new sex:",p2->name);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -