主题:教务管理系统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个回复)
沙发
greenkugua [专家分:70] 发布于 2005-04-22 21:45:00
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;
}
板凳
greenkugua [专家分:70] 发布于 2005-04-22 21:46:00
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();
}
}
3 楼
greenkugua [专家分:70] 发布于 2005-04-22 21:52:00
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();
}
}
}
}
4 楼
greenkugua [专家分:70] 发布于 2005-04-22 21:53:00
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);
}
5 楼
greenkugua [专家分:70] 发布于 2005-04-22 21:54:00
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<i) goto inx;
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();
}
6 楼
greenkugua [专家分:70] 发布于 2005-04-22 21:56:00
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<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);
}
}
}
7 楼
greenkugua [专家分:70] 发布于 2005-04-22 21:57:00
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;
}
}
}
8 楼
greenkugua [专家分:70] 发布于 2005-04-22 22:02:00
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();
}
9 楼
greenkugua [专家分:70] 发布于 2005-04-22 22:06:00
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;
}
10 楼
greenkugua [专家分:70] 发布于 2005-04-22 22:07:00
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);
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<strlen(p2->add);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);
}
我来回复