主题:教务管理系统C语言源代码
greenkugua
[专家分:70] 发布于 2005-04-22 21:43:00
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include <stdlib.h>
#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 ",
};
回复列表 (共57个回复)
11 楼
greenkugua [专家分:70] 发布于 2005-04-22 22:09:00
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<strlen(p3->name);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;
}
12 楼
greenkugua [专家分:70] 发布于 2005-04-22 22:13:00
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<strlen(p3->name);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);
13 楼
greenkugua [专家分:70] 发布于 2005-04-22 22:17:00
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<strlen(p3->name);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);
}
14 楼
greenkugua [专家分:70] 发布于 2005-04-22 22:18:00
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<strlen(p2->STUkey);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);
}
15 楼
greenkugua [专家分:70] 发布于 2005-04-22 22:19:00
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);
}
16 楼
greenkugua [专家分:70] 发布于 2005-04-22 22:20:00
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);
}
17 楼
greenkugua [专家分:70] 发布于 2005-04-22 22:21:00
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->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;
}
18 楼
greenkugua [专家分:70] 发布于 2005-04-22 22:22:00
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<p1->students-1;m++)
for(last=p2=p1->first,n=0;n<p1->students-m-1;n++,last=p2,p2=p2->next)
if(p2->average<p2->next->average&&p2->next!=NULL)/*交换节点在链表中的位置*/
{
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<p1->students){ goto inz;}
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 *// ");
}
19 楼
greenkugua [专家分:70] 发布于 2005-04-22 22:27:00
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!");
}
以上代码可以直接运行,只是写的代码不好看,大家看在我传了半天的份上,多多指教!!!!
20 楼
奴隶 [专家分:40] 发布于 2005-04-22 23:10:00
果然是精华贴。
我来回复