C语言版的教务管理系统,文本界面的,这是我写的第一个程序,也是第一次写程序,和一个朋友一起写的,大家看了就知道有多么烂,没有注释,程序结构混乱,乱用goto,哈哈,文档也丢失了.真是可惜.不过里面还是有一些我的得意的地方,至少它是我写的第一个程序,而从此我爱上了程序设计.
#include
#include
#include
#include
#define MAX 10
#define N 20
#define M 10
void by_name(struct CLASS *headp);
void by_number(struct CLASS *headp);
void by_age(struct CLASS *headp);
void by_tel(struct CLASS *headp);
void write_file(struct CLASS *headp,FILE *myfile);
float SUBAVE(struct CLASS *headp,int,int,int);
void CLAAVE(struct CLASS *headp);
void incredit(struct CLASS *headp);
void sort(struct CLASS *headp);
void method(void);
void WarnCLA();
void WarnSTU();
void WarnSUB();
void SUCESSES();
void out(struct CLASS *headp,int,int);
void introduce(void);
void screen(int,int,int,char *p[]);
struct CLASS * read_file(struct CLASS *headp,FILE *myfile);
struct CLASS * create(struct CLASS *headp);
struct CLASS * mod_stu(struct CLASS *headp);
struct CLASS * mod_sbj(struct CLASS *headp);
struct CLASS * mod_score(struct CLASS *headp);
struct CLASS * mod_STUkey(struct CLASS *headp);
struct CLASS * del_sbj(struct CLASS *headp);
struct CLASS * del_stu(struct CLASS *headp);
struct CLASS * del_cla(struct CLASS *headp);
struct CLASS * ins_cla(struct CLASS *headp);
struct CLASS * ins_stu(struct CLASS *headp);
struct CLASS * ins_sbj(struct CLASS *headp);
struct STUD{ /*学生结构体*/
long number;
unsigned subjects;
unsigned age;
float average;
char STUkey[12];
char name[N];
char kind[M];
char sex[M];
char bir_p[N];
char add[N];
long tel;
char mobilephone[15];
struct STUD* next;
struct SUB* first;
};
struct CLASS{ /*班级结构体*/
unsigned no;
unsigned students;
unsigned classes;
char ADMkey[12];
float score[MAX];
float average;
struct STUD* first;
struct CLASS* next;
};
struct SUB{ /*课程结构体*/
unsigned number;
char name[N];
unsigned credit;
unsigned ps_score;
unsigned tx_score;
unsigned un_score;
struct SUB* next;
};
FILE *fp;
int key0,key1,key,test,dx,dy,y,x,i; /*外部变量说明*/
char buf[30*10*2],buf1[30*2];
char *chp[ ]= {"file", /* 菜单项目*/
"search",
"insert",
"modify",
"delete",
"tongji",
"help",
"outby",
};
char * file[]={
"create",
"open ",
"save ",
"exit ",
};
char * search[]={
"by name",
"by number",
"by tel",
"by age",
};
char * insert[]={
"student",
"subject",
"class",
"Copy",
};
char * modify[]={
"student",
"subject",
"score ",
"STUkey",
};
char * delete[]={
"student",
"subject",
"class",
"xxxxxx",
};
char * tongji[]={
"SUBAVE",
"impass",
"incredit",
"output",
};
char * help[]={
"introduct",
"method",
"sort ",
"CLAAVE",
};
char * outby[]={
"Best",
"Good",
"Middle",
"Bad ",
};
void main()
{
char c;
int Above, Below,no,subnum,A;
struct CLASS cla;
struct CLASS * head;
struct CLASS * p1;
struct STUD * p2;
struct SUB * p3;
head=NULL;
textbackground(GREEN);
clrscr( );
window(18,7,62,16);
textbackground(WHITE); /*制作欢迎界面*/
textcolor(BLACK);
clrscr( );
window(36,8,74,9);
cprintf("WELCOME!");
window(28,9,74,10);
cprintf("Teaching management system");
window(24,10,74,11);
cprintf("Copyright ZhuTao & Star Dragon Li");
window(30,11,74,12);
cprintf("Number:012003017307");
window(26,12,74,13);
cprintf("Computer Science & Technology");
window(25,13,74,14);
cprintf("Informtion Security Class four.");
window(34,14,74,15);
cprintf("Date:2004.8");
window(1,1,80,1);
textbackground(WHITE);
textcolor(BLACK);
clrscr( );
window(1,1,80,2);
for(i=0;i<8;i++)
cprintf(" %s",chp[i]);
while(1)
{
key=0;
while(bioskey(1)==0);
key=bioskey(0);
key=key&0xff?0:key>>8;
inx: if(key==45) exit(0); /* press alt+x*/
if(key==33) /* press alt+f*/
{
dx=0,i=0;
x=4+dx;
screen(x,dx,i,file);
if(key!=33) goto inx;
if(key1==45) exit(0); /* alt + x */
if(key0==13)
switch(test)
{
case 1:
head=create(head);
break;
case 2:
fp=fopen("kugua.dat","rb");
fread(&cla,sizeof(struct CLASS),1,fp); /*打开文件*/
head->next=NULL;
cla.next=NULL;
cla.first=NULL;
head->next=read_file(&cla,fp);
fclose(fp);
break;
case 3:
if((fp=fopen("kugua.dat","wb"))==NULL){
fprintf(stderr,"error:cantcreate file!/n");
return;
}
fwrite(head->next,sizeof(struct CLASS),1,fp);
write_file(head->next,fp);
fclose(fp);
break;
case 4:
window(1,2,80,20);
textbackground(LIGHTGREEN);
textcolor(YELLOW);
clrscr();
window(20,8,60,13);
textbackground(WHITE);
textcolor(BLACK);
clrscr();
window(29,10,60,11);
textbackground(WHITE);
textcolor(BLACK);
gotoxy(40,22);
cprintf("Save your change?(y/n)");
while(isspace(c=getchar()));
if(c=='y'||c=='Y'){
if((fp=fopen("kugua.dat","wb"))==NULL){
fprintf(stderr,"error:can't create file!/n");
return;
}
rewind(fp);
fwrite(head->next,sizeof(struct CLASS),1,fp);
write_file(head->next,fp);
fclose(fp);
for(p1=head->next;p1!=NULL;p1=p1->next){ /*退出时释放内存*/
for(p2=p1->first;p2!=NULL;p2=p2->next){
for(p3=p2->first;p3!=NULL;p3=p3->next)
free(p3);
free(p2);
}
free(p1);
}
}
exit(0);
default:
break;
}
if(key0==27) /* esc key */
{
window(1,1,80,2);
puttext(4+dx,2,15+dx,7,buf);
textbackground(WHITE);
textcolor(BLACK);
gotoxy(4,1);
cprintf("%s",chp[0]);
window(1,2,80,22);
textbackground(LIGHTGREEN);
textcolor(YELLOW);
clrscr();
}
}
if(key==31) /*press alt+s*/
{
dx=7;
x=4+dx;
i=1;
screen(x,dx,i,search);
if(key1==45) exit(0);
if(key!=31) goto inx;
if(key0==13)
switch(test)
{
case 1:
by_name(head);
break;
case 2:
by_number(head);
break;
case 3:
by_tel(head);
break;
case 4:
by_age(head);
break;
default:
cprintf("/nInput error!");
break;
}
if(key==27) /* esc key */
{
window(1,1,80,2);
puttext(4+dx,2,15+dx,7,buf);
textbackground(WHITE);
textcolor(BLACK);
gotoxy(11,1);
cprintf("%s",chp[1]);
window(1,2,80,22);
textbackground(LIGHTGREEN);
textcolor(YELLOW);
clrscr();
}
}
if(key==23) /* alt+i */ /*print alt+i*/
{ dx=2*8;
i=2;
x=4+dx;
screen(x,dx,i,insert);
if(key1==45) exit(0);
if(key!=23) goto inx;
if(key0==13)
switch(test)
{
case 1:
head=ins_stu(head);
break;
case 2:
head=ins_sbj(head);
break;
case 3:
head=ins_cla(head);
break;
case 4:
break;
default:
break;
}
if(key0==27) /* esc key */
{
window(1,1,80,2);
puttext(4+dx,2,15+dx,7,buf);
textbackground(WHITE);
textcolor(BLACK);
gotoxy(20,1);
cprintf("%s",chp[2]);
window(1,2,80,22);
textbackground(LIGHTGREEN);
textcolor(YELLOW);
clrscr();
}
}
if(key==50) /*alt+m*/ /*print alt+m*/
{ dx=25;
i=3;
x=4+dx;
screen(x,dx,i,modify);
if(key1==45) exit(0);
if(key!=50) goto inx;
if(key0==13)
switch(test)
{
case 1:
head=mod_stu(head);
break;
case 2:
head=mod_sbj(head);
break;
case 3:
head=mod_score(head);
break;
case 4:head=mod_STUkey(head);
break;
default:
break;
}
if(key0==27) /* esc key */
{
window(1,1,80,2);
puttext(4+dx,2,15+dx,7,buf);
textbackground(WHITE);
textcolor(BLACK);
gotoxy(29,1);
cprintf("%s",chp[3]);
window(1,2,80,22);
textbackground(LIGHTGREEN);
textcolor(YELLOW);
clrscr();
}
}
if(key==32) /* alt+d */
{ dx=34;
i=4;
x=4+dx;
screen(x,dx,i,delete);
if(key1==45) exit(0);
if(key!=32) goto inx;
if(key0==13)
switch(test)
{
case 1:
head=del_stu(head);
break;
case 2:
head=del_sbj(head);
break;
case 3:
head=del_cla(head);
break;
case 4:
break;
default:
break;
}
if(key0==27) /* esc key */
{
window(1,1,80,2);
puttext(4+dx,2,19+dx,5,buf);
textbackground(WHITE);
textcolor(BLACK);
gotoxy(38,1);
cprintf("%s",chp[4]);
window(1,2,80,22);
textbackground(LIGHTGREEN);
textcolor(YELLOW);
clrscr();
}
}
if(key==20) /*print alt+t*/
{ dx=43;
i=5;
x=4+dx;
screen(x,dx,i,tongji);
if(key1==45) exit(0);
if(key!=20) goto inx;
if(key0==13)
switch(test)
{
case 1:A=1;
cprintf("/n Input the class number:");
scanf("%u",&no);
cprintf("/n Input the subject number:");
scanf("%u",&subnum);
SUBAVE(head,no,subnum,A);
break;
case 2:Above=59;Below=0;
out(head,Above,Below);
break;
case 3:
incredit(head);
break;
case 4:
Above=100;Below=0;
out(head,Above,Below);
break;
default:
break;
}
if(key0==27) /* esc key */
{
window(1,1,80,2);
puttext(4+dx,2,15+dx,7,buf);
textbackground(WHITE);
textcolor(BLACK);
gotoxy(47,1);
cprintf("%s",chp[5]);
window(1,2,80,22);
textbackground(LIGHTGREEN);
textcolor(YELLOW);
clrscr();
}
}
if(key==24) /*print alt+o*/
{
dx=59;
i=7;
x=4+dx;
screen(x,dx,i,outby); /*画采单窗口*/
if(key1==45) exit(0);
if(key!=24) goto inx;
if(key0==13)
switch(test)
{
case 1:
Above=100;
Below=90;
out(head, Above, Below);
break;
case 2:
Above=89;
Below=80;
out(head,Above,Below);
break;
case 3:
Above=79;
Below=70;
out(head,Above,Below);
break;
case 4:
Above=69;
Below=60;
out(head,Above,Below);
break;
default:
break;
}
if(key0==27) /* esc key */
{
window(1,1,80,2);
puttext(4+dx,2,15+dx,7,buf);
textbackground(WHITE);
textcolor(BLACK);
gotoxy(65,1);
cprintf("%s",chp[7]);
window(1,2,80,22);
textbackground(LIGHTGREEN);
textcolor(YELLOW);
clrscr();
}
}
if(key==35) /*print alt+h*/
{ dx=52;
i=6;
x=4+dx;
screen(x,dx,i,help);
if(key1==45) exit(0);
if(key!=35) goto inx;
if(key0==13)
switch(test)
{
case 1:
introduce();
break;
case 2:
method();
break;
case 3:
sort(head);
break;
case 4:
CLAAVE(head);
break;
default:
break;
}
if(key0==27) /* esc key */
{
window(1,1,80,2);
puttext(4+dx,2,15+dx,7,buf);
textbackground(WHITE);
textcolor(BLACK);
gotoxy(56,1);
cprintf("%s",chp[6]);
window(1,2,80,22);
textbackground(LIGHTGREEN);
textcolor(YELLOW);
clrscr();
}
}
}
}
struct CLASS * create(struct CLASS *headp) /*创建文件*/
{
struct CLASS *p1;
unsigned sum;
char ch;
unsigned CREDIT;
char CH[8];
int total=0;
do{
p1=(struct CLASS *)malloc(sizeof(struct CLASS));
cprintf("/n Input class number :");
scanf("%u",&p1->no);
cprintf("/n Input administer key words :");/*创建班级管理员密码*/
scanf("%s",p1->ADMkey);
p1->next=headp->next;
headp->next=p1;
p1->first=NULL; /*创建班级链*/
p1->students=0;
do{
struct STUD *p2;
sum=0;
CREDIT=0;
p2=(struct STUD*)malloc(sizeof(struct STUD));
inx: cprintf("/n Input student's number:");
scanf("%ld",&p2->number);
if(((p2->number/100)%100)!=p1->no) /*学号要与班号统一*/
{
cprintf("Wrong number!");
goto inx;
}
cprintf(" /tInput student's name :"); /*录入学生基本信息*/
scanf("%s",p2->name);
iny: cprintf(" /tInput student's kind ('Party''League''pioneer''None'):");
scanf("%s",CH);
if(!strcmp(CH,"Party")||!strcmp(CH,"League")||!strcmp(CH,"Pioneer")||!strcmp(CH, "None "))
strcpy(p2->kind,CH);
else {cprintf("Wrong kind!");goto iny;}
cprintf(" /tInput student's keywords :");
scanf("%s",p2->STUkey);
inz:cprintf(" /tInput student's sex :");
scanf("%s",CH);
if(!strcmp(CH,"Male")||!strcmp(CH,"Female"))
strcpy(p2->sex,CH);
else {cprintf("Input wrong information!");goto inz;}
cprintf(" /tInput student's birth place :");
scanf("%s",p2->bir_p);
cprintf(" /tInput student's address :");
scanf("%s",p2->add);
cprintf(" /tInput student's age :");
scanf("%u",&p2->age);
cprintf(" /tInput student's telephone number :");
scanf("%ld",&p2->tel);
cprintf(" /tInput student's mobilephone number or input 'xxxx':");
scanf("%s",p2->mobilephone);
p2->next=p1->first;
p1->first=p2; /*创建学生链*/
p2->first=NULL;
p2->subjects=0;
do{
struct SUB *p3;
p3=(struct SUB*)malloc(sizeof(struct SUB));/*录入课程基本信息*/
cprintf("/n Input subject number:");
scanf("%u",&p3->number);
cprintf("/n Input subject name:");
scanf("%s",p3->name);
cprintf("/n Input subject credit:");
scanf("%u",&p3->credit);
cprintf(" /tInput ps_score,tx_score,un_score:");
inA: scanf("%u%u%u",&p3->ps_score,&p3->tx_score,&p3->un_score);
if(p3->ps_score>100||p3->tx_score>100||p3->un_score>100)
{ cprintf("/ninput scores small than 100");goto inA;}
sum+=p3->credit*p3->un_score;
CREDIT+=p3->credit;
p3->next=p2->first; /*创建课程链*/
p2->first=p3;
p2->subjects++;
cprintf("/n continue input subject?(y//n)");
while(isspace(ch=getchar()));
}while(ch=='y'||ch=='Y');
p2->average=(float)sum/ CREDIT;
p1->students++;
cprintf("/n continue input student?(y//n)");
while(isspace(ch=getchar()));
}while(ch=='y'||ch=='Y');
total++;
cprintf("/n continue input class?(y//n)");
while(isspace(ch=getchar()));
}while(ch=='y'||ch=='Y');
p1->classes=total;
clrscr( );
SUCESSES();
return(headp);
}
void by_name(struct CLASS *headp)/*用名字查询*/
{
char CH;
char name[20];
int found=1,i=0,NUM=0,k;
struct CLASS *p1;
struct STUD *p2;
struct student
{
long number;
int age;
char name[N];
char kind[M];
char sex[M];
char bir_p[N];
char mobilephone[15];
char add[N];
long tel;
struct student* next;
};
struct student *pstud=NULL,*s2,*c2;
cprintf("Input student's name:");
scanf("%s",name);
for(p1=headp->next;p1!=NULL;p1=p1->next) /*循环查找各个班级*/
for(p2=p1->first;p2!=NULL;p2=p2->next)
{ if(!strcmp(p2->name,name))
{ s2=(struct student*)malloc(sizeof(struct student));
strcpy(s2->name,p2->name);
strcpy(s2->sex,p2->sex);
strcpy(s2->bir_p,p2->bir_p); /*创建临时链表存储匹配的信息以便控制输出*/
strcpy(s2->kind,p2->kind);
strcpy(s2->add,p2->add);
strcpy(s2->mobilephone,p2->mobilephone);
s2->tel=p2->tel;
s2->number=p2->number;
s2->age=p2->age;
s2->next=pstud;
pstud=s2;
found=0;
i++;
}
continue;
}
inf: c2=pstud;NUM=0; /*输出所有同名的学生基本信息*/
inx:
for(k=NUM;k<4+NUM&&c2!=NULL;k++,c2=c2->next) /*格式控制*/
{
cprintf("|/t number:%-22ld|/t name:%-22s|/t sex:%-10s|",c2->number,c2->name,c2->sex,c2->kind);
cprintf("|------------------------------------------------------------------------------|");
cprintf("|/t bir_p:%-23s|/t add:%-23s|/t age:%-10u|",c2->bir_p,c2->add,c2->age);
cprintf("|------------------------------------------------------------------------------|");
cprintf("|/t mobilephone:%-17s|/t tel:%-23ld|/t kind:%-9s|",c2->mobilephone,c2->tel,c2->sex);
cprintf("|------------------------------------------------------------------------------|");
}
/*翻页功能*/
inz: while(bioskey(1)==0);
key=bioskey(0);
key=key&0xff?0:key>>8;
if(key==81){ /*按PAGEDOWN*/
NUM+=5;
if(k else {
cprintf("/t That's all!Reread,pageup! ");
goto inz;
}
}
if(key==73) /*按PAGEGEUP*/
{
NUM-=5;
if(k-5>0)goto inf;
else{
cprintf("/t For more information,pagedown! ");
goto inz;
}
}
for(c2=pstud;c2!=NULL;c2=c2->next)free(c2);
if(found) WarnSTU(); /*没有找到学生*/
}
void by_number(struct CLASS *headp) /*用学号查询*/
{
int found=1;
long number;
struct STUD *p2;
struct CLASS *p1;
cprintf("Input student's number:");
scanf("%ld",&number);
for(p1=headp->next;p1!=NULL;p1=p1->next){
for(p2=p1->first;p2->number!=number&&p2!=NULL;p2=p2->next) /*格式控制*/
;
if(p2){cprintf("|/t number:%-22ld|/t name:%-22s|/t sex:%-10s|",p2->number,p2->name,p2->sex,p2->kind);
cprintf("|------------------------------------------------------------------------------|");
cprintf("|/t bir_p:%-23s|/t add:%-23s|/t age:%-10u|",p2->bir_p,p2->add,p2->age);
cprintf("|------------------------------------------------------------------------------|");
cprintf("|/t mobilephone:%-17s|/t tel:%-23ld|/t kind:%-9s|",p2->mobilephone,p2->tel,p2->sex);
cprintf("|------------------------------------------------------------------------------|");
found=0;
p2=NULL;
}
}
if(found) WarnSTU();
}
void by_tel(struct CLASS *headp) /*用电话号码查询*/
{
int found=1;
struct STUD *p2;
struct CLASS *p1;
long tel;
cprintf("/nInput the student's tel:");
scanf("%ld",&tel);
for(p1=headp->next;p1!=NULL;p1=p1->next)
for(p2=p1->first;p2!=NULL;p2=p2->next)
{ if(p2->tel==tel){ /*格式控制*/
cprintf("|/t number:%-22ld|/t name:%-22s|/t sex:%-10s|",p2->number,p2->name,p2->sex,p2->kind);
cprintf("|------------------------------------------------------------------------------|");
cprintf("|/t bir_p:%-23s|/t add:%-23s|/t age:%-10u|",p2->bir_p,p2->add,p2->age);
cprintf("|------------------------------------------------------------------------------|");
cprintf("|/t mobilephone:%-17s|/t tel:%-23ld|/t kind:%-9s|",p2->mobilephone,p2->tel,p2->sex);
cprintf("|------------------------------------------------------------------------------|");
found=0;
}
continue;
}
if(found)
WarnSTU(); /*没有找到学生*/
}
void by_age(struct CLASS *headp) /*按年龄查询,输出所有同年龄的学生基本信息*/
{
char CH;
unsigned age1;
int found=1,i=0,NUM=0,k;
struct CLASS *p1;
struct STUD *p2;
char student[30][6][30];
long num[30][2];
unsigned age[30][1];
cprintf("Input student's age:");
scanf("%d",&age1);
for(p1=headp->next;p1!=NULL;p1=p1->next)
for(p2=p1->first;p2!=NULL;p2=p2->next)
{ if(p2->age==age1)
{
strcpy(student[i][0],p2->name); /*将所有匹配信息存入数组以便控制输出*/
strcpy(student[i][1],p2->sex);
strcpy(student[i][2],p2->bir_p);
strcpy(student[i][3],p2->kind);
strcpy(student[i][4],p2->add);
strcpy(student[i][5],p2->mobilephone);
num[i][0]=p2->tel;
num[i][1]=p2->number;
age[i][0]=p2->age;
found=0;
i++;
}
}
inx:
for(k=NUM;k<3+NUM&&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 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
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
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
{
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=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
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
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
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
p2->name[i]=' ';
scanf("%s",p2->name);
flag=0;
}
if(order==6)
{
for(i=0;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
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
p2->kind[i]=' ';
in5: cprintf("/t Input %s's new sex:",p2->name);
scanf("%s",KIND);
if(strcmp(SEX,"Male")!=0||strcmp(SEX,"Famale")!=0)
strcpy(p2->kind,SEX);
else {cprintf("Wrong information!Insert again!");
goto in5;
}
flag=0;
}
if(order==10)
{
cprintf("/t Input %s's new tel:",p2->name);
scanf("%ld",&p2->tel);
flag=0;
}
if(order==11)
{
for(i=0;i
p2->add[i]=' ';
cprintf("/t Input %s's new address:",p2->name);
scanf("%s",p2->add);
flag=0;
}
if(flag)
{
cprintf("/t Input item error! ");
goto inx;
}
cprintf("SUCESSES!Continue?(y/n)");
while(isspace(ch=getchar()));
}while(ch=='y'||ch=='Y');
inEND: return(headp);
}
struct CLASS * mod_sbj(struct CLASS *headp)/*修改科目信息*/
{
struct CLASS *p1;
struct STUD *p2;
struct SUB *p3;
int order;
char key[12];
int ch, n=0;
int sbj_num,no,flag=1;
long stu_num;
in1:if(n>3) /*连续四次输入错误密码,返回*/
{ cprintf("Too many errors!");
goto inEND;
}
cprintf("/nInput the your keywords:");/*输入学生密码*/
scanf("%s",key);
do{
cprintf("/nInput the class number:");
scanf("%u",&no);
in2:cprintf("/n Input the student number:");
scanf("%ld",&stu_num);
if(((stu_num/100)%100)!=no)
{ cprintf("Wrong numbers!");
goto in2;
}
cprintf("/n Input the subject number:");
scanf("%u",&sbj_num);
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,key)) /*验证密码*/
{ cprintf( "Wrong keywords! ");
n++;
goto in1;
}
for(p3=p2->first;p3!=NULL;p3=p3->next)
{
if(p3->number!=sbj_num)continue;
else break;
} /*找到课程入口*/
if(p3==NULL){WarnSUB();goto inEND;} /*课程尚未创建*/
/*输入你要修改的项目*/
cprintf("/n/t student name:%-16s /t subject name:%-13s /t credit:%-10d",p2->name,p3->name,p3->credit);
inx: cprintf("/nInput the item you want to modify ( 1:name ,2:credit ,3:number ):");
scanf("%d",&order);
if(order==1)
{ flag=0;
for(i=0;i
p3->name[i]=' ';
cprintf("/t Input the new name :");
scanf("%s",p3->name);
}
if(order==2)
{ flag=0;
cprintf("/t Input the new cridit:");
p3->credit=0;
scanf("%u",&p3->credit);
}
if(order==3)
{ flag=0;
cprintf("/t Input the new number:");
p3->number=0;
scanf("%u",&p3->number);
}
if(flag){
cprintf("/t Input item error! ");
goto inx;
}
cprintf("SUCESSES!Continue?(y/n)");
while(isspace(ch=getchar()));
}while(ch=='y'||ch=='Y');
inEND: return(headp);
}
struct CLASS * mod_score(struct CLASS *headp)/*修改科目的成绩*/
{
struct CLASS *p1;
struct STUD *p2;
struct SUB *p3;
int order;
char key[12];
int no,subnum=0;
long stu_num;
int n=0,flag=1,sum=0,credit=0;
in1:if(n>3) /*连续四次输入错误密码*/
{ cprintf("Too many errors!");
goto inEND;
}
cprintf("/nInput the your keywords:");
scanf("%s",key);
cprintf("/n Input the class number:");
scanf("%u",&no);
in2:cprintf("/n Input the student number:");
scanf("%ld",&stu_num);
if(((stu_num/100)%100)!=no)
{ cprintf("Wrong numbers!");
goto in2;
}
cprintf("/n 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();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,key))
{ cprintf( "Wrong keywords! ");
n++;
goto in1;
}
p2->average=0;
for(p3=p2->first;p3!=NULL;p3=p3->next)
{
if(p3->number==subnum)break;
else continue;
}
if(p3==NULL){WarnSUB();goto inEND;}
cprintf("/n ps_score:%-17u /t tx_score:%-16u /t un_score:%-14u", p3->ps_score,p3->tx_score,p3->un_score );
iny: cprintf("/t input the item you want to modify ( 1:ps_score ,2:tx_score ,3:un_score ): ");
scanf("%d",&order);
if(order==1)
{
in3: cprintf("/t Input %s's new ps_score:",p3->name);
p3->ps_score=0;
scanf("%u",&p3->ps_score);
if(p3->ps_score>100||p3->ps_score<0)
{ cprintf("Wrong numbers!");
goto in3;
}
flag=0;
}
if(order==2)
{ flag=0;
in4: cprintf("/t Input %s's new tx_score:",p3->name);
p3->tx_score=0;
scanf("%u",&p3->tx_score);
if(p3->tx_score>100||p3->tx_score<0)
{ cprintf("Wrong numbers!");
goto in4;
}
}
if(order==3)
{ flag=0;
in5: cprintf("/t Input %s's new un_score:",p3->name);
p3->un_score=0;
scanf("%u",&p3->un_score);
if(p3->un_score>100||p3->un_score<0)
{ cprintf("Wrong numbers!");
goto in5;
}
}
for(p3=p2->first;p3!=NULL;p3=p3->next)
{sum+=p3->un_score*p3->credit;
credit+=p3->credit;
}
p2->average=(float)sum/credit;
if(flag) {
cprintf("/n Input error!-------------------------------------------------------------------");
goto iny;
}
SUCESSES();
inEND: return(headp);
}
struct CLASS *mod_STUkey(struct CLASS *headp)/*修改学生的密码*/
{
struct CLASS *p1;
struct STUD *p2;
long stunum;
int i=0;
char key[12];
cprintf("Input your number:");
scanf("%ld",&stunum);
for(p1=headp->next;p1!=NULL;p1=p1->next)
{if(p1->no==(stunum/100)%100)break;
else continue;
}
if(p1==NULL){WarnSTU();goto inEND;}
for(p2=p1->first;p2!=NULL;p2=p2->next)
{if(p2->number==stunum)break;
else continue;
}
if(p2==NULL){WarnSTU();goto inEND;}
inx:
if(i>3){cprintf("Too many errors!");goto inEND;}
cprintf("Input your keyword:");
scanf("%s",key);
if(strcmp(key,p2->STUkey)){cprintf("Wrong keyword!");i++;goto inx;}
cprintf("Input your new keyword:");
for(i=0;i
p2->STUkey[i]=' ';
scanf("%s",p2->STUkey);
clrscr( );
SUCESSES();
inEND:return(headp);
}
struct CLASS * del_cla(struct CLASS *headp)/*删除班级*/
{
long num;
int ch,n=0;
char key[12];
int no;
struct SUB * p3;
struct STUD * p2;
struct CLASS *p1,*last;
in1:if(n>3)
{ cprintf("Too many errors!");
goto inEND;
}
cprintf("/nInput the administer's keywords:");
scanf("%s",key);
do{
cprintf("/n input the class number:");
scanf("%u",&no);
for(last=p1=headp->next;p1!=NULL;last=p1,p1=p1->next)
{
if(p1->no==no) break;
else continue;
}
if(p1==NULL){WarnCLA();goto inEND;} /*找到班级入口*/
if(strcmp(headp->next->ADMkey,key))
{ cprintf( "Wrong keywords! ");
n++;
goto in1;
}
if(p1==headp->next)
{
if(p1->next!=NULL) headp->next=p1->next;
else headp->next=NULL;
}
else last->next=p1->next;
for(p2=p1->first;p2!=NULL;p2=p2->next) /*释放内存单元*/
{for(p3=p2->first;p3!=NULL;p3=p3->next)
free(p3);
free(p2);
}
free(p1);
cprintf("SUCESSES!Continue?(y/n)");
while(isspace(ch=getchar()));
}while(ch=='y'||ch=='Y');
inEND: return(headp);
}
struct CLASS * del_stu(struct CLASS *headp) /*删除学生*/
{
long num;
int ch,n=0;
char key[12];
int no,stu_num=0;
struct STUD *last,*p2;
struct CLASS *p1;
struct SUB * p3;
in1:if(n>3)
{ cprintf("Too many errors!");
goto inEND;
}
cprintf("/nInput the administer's keywords:");
scanf("%s",key);
do{
cprintf("/n input the class number:");
scanf("%u",&no);
in2:cprintf("/nInput the student's number :");
scanf("%ld",&num);
if((num/100)%100!=no)
{ cprintf("Wrong number!");
goto in2;
}
for(p1=headp->next;p1!=NULL;p1=p1->next)
{
if(p1->no==no) break;/*找到班级入口*/
else continue;
}
if(p1==NULL){WarnCLA();goto inEND;}
if(strcmp(p1->ADMkey,key))
{ cprintf( "Wrong keywords! ");
n++;
goto in1;
}
for(p2=p1->first;p2!=NULL;last=p2,p2=p2->next)
{
if(p2->number!=stu_num)continue;/*找到学生*/
else break;
}
if(p2==NULL){WarnSTU();goto inEND;}
cprintf("/t class:%-10u /t name:%-16s /t birth place:%-23s",p1->no,p2->name,p2->bir_p); /*c2 is to delete*/
if(p2!=p1->first)
last->next=p2->next;
else
p1->first=p2->next;
for(p3=p2->first;p3!=NULL;p3=p3->next)
free(p3);
free(p2);
cprintf("SUCESSES!Continue?(y/n)");
while(isspace(ch=getchar()));
}while(ch=='y'||ch=='Y');
inEND: return(headp);
}
struct CLASS * del_sbj(struct CLASS *headp)/*删除课程*/
{
struct CLASS *p1;
struct STUD *p2;
struct SUB *p3,*last;
int ch,n=0;
char key[12];
int no,sum=0,credit=0;
int subnum;
long stu_num;
in1:if(n>3) /*多次输入错误密码自动退出*/
{ cprintf("Too many errors!");
goto inEND;
}
cprintf("/nInput the your keywords:");
scanf("%s",key);
do{
cprintf("/n Input the class number:");
scanf("%u",&no);
in2:cprintf("/n Input the student number:");
scanf("%ld",&stu_num);
if((stu_num/100)%100!=no)
{ cprintf("Wrong number!");
goto in2;
}
cprintf("/n Input the subject number:");
scanf("%u",&subnum);
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,key))
{ cprintf( "Wrong keywords! ");
n++;
goto in1;
}
for(p3=p2->first;p3!=NULL;last=p3,p3=p3->next)
{
if(p3->number!=subnum)continue;
else break;
}
if(p3==NULL){WarnSUB();goto inEND;} /*找到课程入口*/
cprintf("/n/t number:%-16u /t name:%-11s/t score:%4u /t credit:%-14u",p3->number,p3->name,p3->un_score,p3->credit);
if(p3!=p2->first) /*p3 is not the head node*/
last->next=p3->next;
else
p2->first=p3->next;
free(p3);
p2->subjects--;
for(p3=p2->first;p3!=NULL;p3=p3->next)
{sum+=p3->un_score*p3->credit;
credit+=p3->credit;
}
p2->average=(float)sum/credit;
cprintf("/t Continue?(y/n)");
while(isspace(ch=getchar()));
}while(ch=='y'||ch=='Y');
clrscr( );
inEND: return(headp);
}
struct CLASS * ins_cla(struct CLASS *headp)/*插入班级*/
{
char ch;
int n=0;
char Licence[12];
struct CLASS *p1,*l1,*t1;
in1: if(n>3)
{ cprintf("Too many errors!");
goto inEND;
}
cprintf("/nInput the administer's keywords:");/*输入管理员密码*/
scanf("%s",Licence);
if(strcmp(headp->next->ADMkey,Licence))
{ cprintf( "Wrong keywords! ");
n++;
goto in1;
}
inx:
p1=(struct CLASS*)malloc(sizeof(struct CLASS));
cprintf("/n input the class number :");
scanf("%u",&p1->no);
for(t1=headp->next;t1!=NULL;t1=t1->next)/*查找班级入口*/
if(p1->no==t1->no)
{
cprintf("/t The class is exist! continue?(y/n)");
while(isspace(ch=getchar()));
if(ch=='y'||ch=='Y')
goto inx;
else goto inEND;
}
if(headp->next==NULL)
{ p1->next=NULL;/*班级不存在*/
headp->next=p1;
p1->classes=0;
goto iny;
}
if(p1->no>headp->next->no)
{ p1->next=headp->next;/*作为链头*/
headp->next=p1;
}
else
{
for(t1=headp->next;t1->no>p1->no;l1=t1,t1=t1->next)
{ if(t1->next==NULL)
{ p1->next=NULL;
t1->next=p1;/*插入作为链尾*/
goto iny;
}
else continue;
}
p1->next=t1;
l1->next=p1; /*插在中间*/
}
iny: cprintf("/n input the administer's keywords:");
scanf("%s",p1->ADMkey);
cprintf("Sucsses!");
for(t1=headp->next;t1!=NULL;t1=t1->next)
t1->classes++;
p1->students=0;
p1->first=NULL;
clrscr( );
SUCESSES();
inEND: return(headp);
}
struct CLASS * ins_stu(struct CLASS *headp)/*插入学生*/
{ char ch,Ch,c;
char CH[12];
char Licence[12];
int n=0,flag=1;
int no;
struct CLASS *p11,*p12,*last1;
struct STUD *p21,*p22,*p2,*last;
p2=(struct STUD*)malloc(sizeof(struct STUD));
cprintf("/n input the class number:");
scanf("%u",&no);
in2:cprintf("/t input the student's number :");
scanf("%ld",&p2->number);
if((p2->number/100)%100!=no)
{ cprintf("Wrong number!");
goto in2;
}
inx:
in1:if(n>3) /*多次输入错误密码*/
{
cprintf("Too many errors!");
goto inEND;
}
cprintf("/nInput the administer's keywords:");
scanf("%s",Licence);
for(p11=headp->next; p11!=NULL;last1=p11, p11=p11->next) /*p11为遍历指针*/
{
if (p11->no == no)
{
p12 = p11;
break;
}
else continue; /*p12为班级入口*/
}
if(last1==NULL){WarnCLA();goto inEND;}
if(strcmp(p12->ADMkey,Licence))
{
cprintf( "Wrong keywords! ");
n++;
goto in1;
}
for(p21=p12->first; p21!=NULL; p21=p21->next)/*p21为遍历指针*/
{
if(p21->number == p2->number)
{
cprintf("/t the student is exist! continue?(y/n)");
while(isspace(Ch=getchar()));
if(Ch=='y'||Ch=='Y')
goto in2;
else goto inEND;
}
}
if(p12->first==NULL)
{ /*作为链头*/
p2->next=NULL;
p12->first=p2;
p12->students=0;
flag=0;
goto iny;
}
if(p2->number>p12->first->number)/*插入作为链头*/
{ p2->next=p12->first;
p12->first=p2;
flag=0;
}
else{
for(p21=p12->first;p21->number>p2->number;last=p21,p21=p21->next)
{ if(p21->next==NULL)
{ p2->next=NULL; /*插入作为链尾*/
p21->next=p2;
flag=0;
goto iny;
}
else continue;
}
p2->next=p21;
last->next=p2; /*插在中间*/
flag=0;
}
iny: cprintf("/t SUCCESS!");
cprintf(" /tInput student's name :"); /*录入学生基本信息*/
scanf("%s",p2->name);
inz: cprintf(" /tInput student's sex :");
scanf("%s",CH);
if(!strcmp(CH,"Male")||!strcmp(CH,"Female"))
strcpy(p2->sex,CH);
else {cprintf("Input wrong information!");goto inz;}
in3: cprintf(" /tInput student's kind :");
scanf("%s",CH);
if(!strcmp(CH,"Party")||!strcmp(CH,"League")||!strcmp(CH,"Pioneer")||!strcmp(CH, ' '))
strcpy(p2->kind,CH);
else {cprintf("Wrong kind!");goto in3;}
cprintf(" /tInput student's birth place :");
scanf("%s",p2->bir_p);
cprintf(" /tInput student's address :");
scanf("%s",p2->add);
cprintf(" /tInput student's age :");
scanf("%u",&p2->age);
cprintf(" /tInput student's keywords :");
scanf("%s",p2->STUkey);
cprintf(" /tInput student's telephone number :");
scanf("%ld",&p2->tel);
cprintf(" /tInput student's mobilephone number :");
scanf("%s",p2->mobilephone);
p12->students++;
p2->average=0;
p2->subjects=0;
p2->first=NULL;
SUCESSES();
inEND:if(flag){ clrscr( );WarnSTU(); } return(headp);
}
struct CLASS * ins_sbj(struct CLASS *headp)/*插入课程信息*/
{
int no;
long num;
int n=0,sum=0,credit=0;
char ch;
char key[12];
struct CLASS *p1;
struct STUD *p2;
struct SUB *p3,*p31,*p32;
inx: p3=(struct SUB*)malloc(sizeof(struct SUB));
cprintf("/n input the class number :");
scanf("%u",&no);
cprintf("/n input the student's number :");
scanf("%ld",&num);
in1:if(n>3) /*多次输入错误密码*/
{ cprintf("Too many errors!");
goto inEND;
}
cprintf("/nInput your keywords:");
scanf("%s",key);
cprintf("/n input the subject's number :");
scanf("%u",&p3->number);
for(p1=headp->next;p1!=NULL;p1=p1->next) /* find the class */
{ if(p1->no==no) break;
else continue;
}
if(p1==NULL){WarnCLA();goto inEND;}
for(p2=p1->first;p2!=NULL;p2=p2->next) /* find the student */
{ if(p2->number==num) break;
else continue;
}
if(p2==NULL){WarnSTU();goto inEND;} /*验证密码*/
if(strcmp(p2->STUkey,key))
{ cprintf( "Wrong keywords! ");
n++;
goto in1;
}
for(p31=p2->first;p31!=NULL;p31=p31->next)
if(p3->number==p31->number)
{
cprintf("/n The subject is exist!Continue?(y/n)");
while(isspace(ch=getchar()));
if(ch=='y'||ch=='Y')
goto inx;
else goto inEND;
}
if(p2->first==NULL)
{ /* 插入作为链头 */
p3->next=NULL;
p2->first=p3;
p2->subjects=0;
}
else{
p31 = p2->first;
if(p31->number
{
p3->next=p2->first;
p2->first=p3;
}
p32 = p31;
while (p31->next != NULL)
{
p31 = p31->next;
if (p31->number < p3->number) /*插在中间*/
break;
else
p32 = p32->next;
}
p3->next=p32->next;
p32->next=p3;
}
cprintf("/n Input subject name and credit:");
scanf("%s%u",p3->name,&p3->credit);
cprintf(" /tInput ps_score,tx_score,un_score:");
scanf("%u%u%u",&p3->ps_score,&p3->tx_score,&p3->un_score);
p2->subjects++;
for(p3=p2->first;p3!=NULL;p3=p3->next)
{sum+=p3->un_score*p3->credit;
credit+=p3->credit;
}
p2->average=(float)sum/credit;
clrscr( );
SUCESSES();
inEND: return(headp);
}
void sort(struct CLASS *headp)
{ int clanum,m,n,i,j;
struct CLASS *p1;
struct STUD *p2,*last,*next,*tmp;
cprintf("Input the CLASS number:");
scanf("%d",&clanum);
for(p1=headp->next;p1!=NULL;p1=p1->next)
{
if(p1->no==clanum) break;/*找到班级入口*/
else continue;
}
if(p1==NULL){WarnCLA();return;}
for(m=0;m
for(last=p2=p1->first,n=0;n
if(p2->average
{
next=p2->next;
tmp=p2->next->next;
if(p2!=p1->first)
last->next=next;
else
p1->first=next;
next->next=p2;
p2->next=tmp;
p2=next;
}
inz: p2=p1->first,i=1;
inx: for(j=0;p2!=NULL&&j<10;i++,p2=p2->next)/*格式控制*/
{
cprintf("|/tName:%-20s|/tNumber:%-13ld|/tNO:%-12d|/tScore:%-5.2f|",p2->name,p2->number,i,p2->average);
cprintf("|------------------------------------------------------------------------------|");
}
iny: while(bioskey(1)==0);
key=bioskey(0);
key=key&0xff?0:key>>8; /*翻页显示*/
if(key==81){ /*下翻*/
if(i
else {
cprintf("/t That's all!Reread,pageup! ");
goto iny;
}
}
if(key==73) /*上翻*/
{ if(i>10){goto inx;}
else{
cprintf("/t For more information,pagedown! ");
goto iny;
}
}
}
void introduce(void) /*函数功能介绍*/
{
cprintf("/n/t Save :Write data into files! ");
cprintf("/n/t Open :Open files ! ");
cprintf("/n/t Create : Create files! ");
cprintf("/n/t Output :Put out information according to your command! ");
cprintf("/n/t Sort : Arrang the students by average score! ");
cprintf("/n/t Impass : Show the students who didn't pass the exam! ");
cprintf("/n/t Incredit : See about the credits you have got! ");
cprintf("/n/t Average :See about the average score of class! ");
}
void method() /*快捷介绍*/
{
window(1,23,80,25);
textbackground(GREEN);
textcolor(RED);
clrscr();
gotoxy(1,1);
cprintf("/t file:alt+f /t search:alt+s /t insert:alt+i /t modify:alt+m /t delete:alt+d /t tongji:alt+t /t help:alt+h");
cprintf(" //* WELCOME INTO HERE *// ");
}
void screen(int x,int dx,int m,char *p[])/*画菜单的函数*/
{
window(1,1,80,2);
textbackground(BLACK);
textcolor(WHITE);
gotoxy(x,1);
cprintf("%s",chp[m]);
gettext(4+dx,2,15+dx,7,buf); /* save the content */
window(4+dx,2,15+dx,7);
textbackground(WHITE);
textcolor(BLACK);
clrscr( );
window(4+dx,2,15+dx,9);
gotoxy(1,1);
putch(0xda);
for(i=2;i<12;i++) putch(0xc4); /*print '-'*/
putch(0xbf);
for(i=2;i<6;i++)
{
gotoxy(1,i);putch(0xb3); /*print '|'*/
gotoxy(12,i);putch(0xb3);
}
gotoxy(1,6);
putch(0xc0);
for(i=2;i<12;i++) putch(0xc4); /*画菜单边框*/ /*print '-'*/
putch(0xd9);
for(i=2;i<6;i++)
{
gotoxy(2,i);
cprintf("%s",p[i-2]);
}
gettext(2+dx,2,14+dx,3,buf1);
textbackground(RED);
textcolor(YELLOW);
gotoxy(2,2);
cprintf("%s",p[0]);
y=2;
key0=key1=0;
while(key0!=27&&key1!=45&&key0!=13&&key1!=77&&key1!=75)
{
while(bioskey(1)==0);
key0=key1=bioskey(0);
key0=key0&0xff;
key1=key1&0xff?0:key1>>8;
if(key1==72||key1==80)
{
puttext(2+dx,y,14+dx,y+1,buf1);
if(key1==72) y=y==2?5:y-1; /*上下控制*/
if(key1==80) y=y==5?2:y+1;
gettext(2+dx,y,14+dx,y+1,buf1);
textbackground(RED);
textcolor(YELLOW);
gotoxy(2,y);
cprintf("%s",p[y-2]);
}
test=y-1;
} /*菜单之间的转换*/
if(key1==75){ /*左移*/
if(x==4) key=24;
if(x==11) key=33;
if(x==20) key=31;
if(x==29) key=23;
if(x==38) key=50;
if(x==47) key=32;
if(x==56) key=20;
if(x==63) key=35;
window(1,1,80,2);
puttext(4+dx,2,15+dx,7,buf);
textbackground(WHITE);
textcolor(BLACK);
gotoxy(x,1);
cprintf("%s",chp[m]);
window(1,2,80,22);
textbackground(LIGHTGREEN);
textcolor(YELLOW);
clrscr();
return;
}
if(key1==77){ /*右移*/
if(x==4) key=31;
if(x==11) key=23;
if(x==20) key=50;
if(x==29) key=32;
if(x==38) key=20;
if(x==47) key=35;
if(x==56) key=24;
if(x==63) key=33;
window(1,1,80,2);
puttext(4+dx,2,15+dx,7,buf);
textbackground(WHITE);
textcolor(BLACK);
gotoxy(x,1);
cprintf("%s",chp[m]);
window(1,2,80,22);
textbackground(LIGHTGREEN);
textcolor(YELLOW);
clrscr();
return;
}
if(key0==45) exit(0); /* alt + x */
if(key0==13) /* enter key */
{
window(1,1,80,2);
puttext(4+dx,2,15+dx,7,buf);
textbackground(WHITE);
textcolor(BLACK);
gotoxy(x,1);
cprintf("%s",chp[m]);
window(1,2,80,22);
textbackground(LIGHTGREEN);
textcolor(YELLOW);
clrscr();
gotoxy(1,1);
}
}
void WarnCLA() /*出错提示的各弹出式对话框*/
{ clrscr( );
window(20,10,60,14);
textbackground(WHITE);
textcolor(BLACK);
clrscr( );
window(29,11,74,12);
cprintf("/nThe Class is not exist!");
}
void WarnSTU()
{ clrscr( );
window(20,10,60,14);
textbackground(WHITE);
textcolor(BLACK);
clrscr( );
window(28,11,74,12);
cprintf("/nThe student is not exist!");
}
void WarnSUB()
{ clrscr( );
window(20,10,60,14);
textbackground(WHITE);
textcolor(BLACK);
clrscr( );
window(28,11,74,12);
cprintf("/nThe Subject is not exist!");
}
void SUCESSES()
{ clrscr( );
window(20,10,60,14);
textbackground(WHITE);
textcolor(BLACK);
clrscr( );
window(36,11,74,12);
cprintf("/nSUCSSES!");
}