功能模块概要说明:

1.输入函数:

char* uscanf(int,int,int) //图形模式下输入函数,大小写26个字母0-9数字外加空格键为有效输入,可以使用BACKSPACE。

2.开始界面,退出界面和主界面:

void starting() //开始界面

void end() //结束界面

char* index() //主选择界面函数,返回选择信息(字符串);

3.数据输入、创建链表模块

char* tinkey(char*,int,int) //输入切换处理

char* recourse(char*,int,int) //课程输入

int wdetect(struct person*,char*) //课程输入检测,检测课表一星期同一天同一时间段内课程安排是否重复,如果重复给出修改提示信息

char* infuse(char*,char*,int) //课表输入

struct course *ccreat(char*) //创建课程单向链表

struct person* pcreat(char *) //创建个人课表节点

char *infcreat(char**,struct person**,struct person**,char*)

//创建课表双向链表

4.课表输出

char *print(char*) //课表输出背景界面

char *pkey() //课表输出按纽界面及处理

int table(int,int,struct person*) //在指定区域一表格形式输出一个人的课表

int forebox(struct person*) //初略显示下三个人的课表提示

5.文件存储和装载

char* save(char *,struct person *) //保存为磁盘文件,在图形模式下进行文件读写操作之后,程序出现莫名其妙的异常显示情形

6.课表查询:

struct person *pdemand(struct person *,char *) //按人名字查询其课表安排。

struct person* wddemand(struct person*,int) //按星期几查询课程安排情况。

struct person *cdemand(struct person *,char *) //按课程查询老师或学生课程安排情况。

char *demand(struct person *) // 查询切换,并显示查询结果,按名字查询一次只能一个。按星期几和课程查询可以查询到多个,如查询到多个接果,按任意键可依次输出。

7.排序。

struct course *csort(struct course *) //按课程编号排序课表节点中课程链表

struct person *psort(struct person *) //按人学号或老师编号排序课表链表

char sort(struct person*) //排序切换,并提示排序结果

8.插入。

char *insert(char *,struct person **,struct person **)

//擦入课表节点

9.删除。

char *delete(struct person **,char *)

//按人名删除其课表节点

操作说明:

1. Infuse:选定这个键后按Enter进入学生输入菜单,你可以输入学生的学号,姓名,学生在一学期内的所学课程的课程名,课程号,学时,以及在一周内上课的地址。如果当输入某课程上课地址有重复时,系统自动发出报警信息,并提示出错的地方,以便修改,

当选定couse时,表明此学生所学的该课程的信息输入完成再输入另外所学课程的信息,如上所写照样输入,

当选定finish时,并按回车键后,表明此学生在这一学期内所学的课程信息输入完成。如要继续输入学生的信息如前所述。

当选定back时,并按下回车键后,返回TIME TABLE主菜单,选择主菜单里的功能对所输入的信息进行处理。

当选定exit时,并按下回车键后,返回程序。结束程序。

2.SAVE/LOAD 选定此并按回车。此键作用对所输入的信息进行格式输出/载入。输入你要保存信息的文件名,文件格式系统自动生成。利用键盘上的方向键和TAB键进行控制。

3.DEMAND:按ENTER键开始输入,按反向键进行查询切换。当按星期几和课程查询时候,如遇到查询到多个结果,按任意键可依次输出直到完。

4.INSERT:按ENTER键开始输入,按反向键进行查询切换。输入同INFURE项。

5. DELETE: 按ENTER键显示输入框开始输入。其他同上。

6.SORT:当提示框中SORT变为红色时候,表示被选中,按ENTER键开始插入,如成功给出提示信息。

7.PRINT:依次输出链表,如果输出链表为空则不进仍输出页面。NEXT为下一个,PRO为上一个。下面FORENOTICE 框显示后三个节点。

8.EXIT:退出系统。效果同按ESC。

六:源程序清单:(见附件)

七:测试结果:

1:在图形模式下,关于文件的读写操作影响整个程序的显示。

2:关于指针数组的初始化,有时候出现莫名其妙的没有初始化的现象。改成逐个赋值处理,现象消息。

3:关于返回字符串指针的函数所返回的指针输出,出现叠加的现象。

4:图形模式下函数的不稳定和相互制约的现象。

如:sprintf()与strcpy();

。。。。。。

//源程序代码

/*

功能:排课系统

作者:周志明

日期:28/8/2004

*/

/*****************************************************************/

/*                         课表排课系统                          */

/*****************************************************************/

/*头文件*/

#include

#include

#include

#include

/*宏定义*/

#define NULL    0

#define OK      1

#define ERROR  -1

#define ESC     0x011b

#define TAB  0x0f09

#define ENTER   0x1c0d

#define UP  0x4800

#define DOWN 0x5000

#define LEFT 0x4b00

#define RIGHT 0x4d00

#define BACKSPACE 0x0e08

#define SPACE   0x3920

/*结构体类型定义*/

struct weekday{

int wday;

char addr[5][10];

struct weekday *next;

};

struct course{

char cnumber[10];

char cname[10];

char  period[10];

struct weekday *whead;

struct course *next;

};

struct person{

char pnumber[10];

char pname[10];

int  pflag[7][5];

struct course *chead;

struct person *pro;

struct person *next;

};

/*****************************INPUT FUNCTION ****************************/

char* uscanf(sx,sy,max)  /*图形模式下输入函数*/

int sx,sy,max;

{

int bsx=sx,bsy=sy,n;

int key,keylow;

char *p,*ch;

ch=p=(char*)malloc(sizeof(char)*100);

n=0;

do{

setcolor(RED);

line(sx,sy+15,sx+8,sy+15);

key=bioskey(0);

keylow=key & 0xff;

if(key==BACKSPACE && sx>bsx){       /*退格纠错处理*/

if(n!=max) sx-=8; p--;

setfillstyle(1,7);setcolor(7);

if(n==max) bar(sx,sy+3,sx+8,sy+16);

else bar(sx,sy+3,sx+16,sy+16);

n-=1;

}

else if(keylow>=48 && keylow<=57 || keylow>=65 && keylow<=90

|| keylow>=97 && keylow<=122 || key==SPACE)       /*输入字符控制*/

if(n

sprintf(p,"%c",keylow);

setfillstyle(1,7);setcolor(7);

bar(sx,sy+3,sx+8,sy+16);

setcolor(RED);

moveto(sx,sy+5);  outtext(p);

n+=1;

p++;

sx+=8;

if(n==max) sx-=8;

}

}while(key!=ENTER && key!=TAB);

*p='/0';

setfillstyle(1,8); setcolor(8);

bar(bsx-1,bsy+1,bsx+68,bsy+17);

setcolor(7);

outtextxy(bsx,bsy+5,ch);

return(ch);

}/*uscanf*/

/******************************Function1***********************************/

void SETGRAPH(){     /*图形模式初始化*/

int driver,mode;

detectgraph(&driver,&mode);

initgraph(&driver,&mode,"");

}

void starting(){     /*开始界面*/

int i,times;

char ch='a';

char p[]={'W','/0','e','/0','l','/0','c','/0',

'o','/0','m','/0','e','/0','!','/0'};

setbkcolor(1);

setfillstyle(6,4);

floodfill(12,12,GREEN);

settextstyle(0,0,3); setcolor(14);

outtextxy(50,210,"Program Design Practise");

outtextxy(200,250,"Starting...");

setcolor(8); setlinestyle(1,0,THICK_WIDTH);

ellipse(320,240,0,360,318,239);

setfillstyle(1,8); delay(50000);

for(i=0;i<=360;i+=6){

delay(100);

sector(320,240,0,i,308,229);

}

setfillstyle(1,1); setcolor(2);

for(i=100;i<=350;i+=5){

delay(500);

bar3d(100,100,540,i,15,1);

}

settextstyle(0,0,4); setcolor(6);

outtextxy(150,130,"TIME-TABLE");

settextstyle(0,0,1); setcolor(12);

outtextxy(200,180,"time-table practice    ver 1.0");

outtextxy(400,300,"DESIGNER:zzm");

times=0;

do{

settextstyle(0,0,3);

for(i=0;i<8;i++){

delay(3000);

setcolor(2+i+times%8);

outtextxy(220+i*25,220,&p[2*i]);

}

settextstyle(0,0,1);

outtextxy(300,260,"");

times++;

if(times>2) ch=getch();

}while(ch!=0xd);

}/*starting*/

void end(){          /*退出界面*/

int i,times;

char p[]={'T','/0','H','/0','A','/0','N','/0',

'K','/0','-','/0','Y','/0','O','/0','U','/0'};

cleardevice();

setbkcolor(0);

setfillstyle(1,8); setcolor(1);

for(i=0;i<640;i+=5){

delay(100);

bar3d(0,100,i,350,0,1);

}

settextstyle(0,0,5); setcolor(YELLOW);

outtextxy(250,200,"END");

setfillstyle(1,1);

for(i=100;i<540;i+=4){

delay(200);

bar3d(100,100,i,350,0,1);

}

settextstyle(0,0,2); setcolor(6);

outtextxy(250,150,"TIME-TABLE");

settextstyle(0,0,1); setcolor(12);

outtextxy(220,180,"time-table practice    ver 1.0");

outtextxy(280,300,"DESIGNER: ZhouZhiming");

times=0;

settextstyle(0,0,6);

do{

for(i=0;i<9;i++){

delay(3000);

setcolor(2+i+times%9);

outtextxy(125+i*45,220,&p[2*i]);

}

times++;

}while(times<2);

setfillstyle(1,0);setcolor(0);

for(i=0;i<640;i+=5){

delay(500);

bar3d(0,100,639,100+i,0,1);

bar3d(0,350-i,639,350,0,1);

}

closegraph();

exit(0);

}/*END*/

void box(sx,sy,ex,ey,depth,size,linecolor,fillcolor,fontcolor,p)

int sx,sy,ex,ey,linecolor,fillcolor;

char *p;

{  settextstyle(0,0,size);

setfillstyle(1,fillcolor);setcolor(linecolor);

bar3d(sx,sy,ex,ey,depth,1);

setcolor(fontcolor);

outtextxy(sx+5,(sy+ey)/2-5,p);

}/*box*/

char* index(){   /*主选择页面*/

int i;

int key,sx,sy,ex,ey,xincre,yincre;

char **p;

char *sp[]={"Infuse","Load","Save","Demand","Insert","Delete","Sort","Print","Exit"};

char *temp;

setcolor(1);

setfillstyle(6,8);

for(i=0;i<=180;i+=5){

delay(10);

sector(320,240,0,i,500,242);

sector(320,240,180,180+i,320,242);

}

setfillstyle(1,8);

for(i=0;i<=90;i+=5){

delay(10);

sector(210,240,0,i,150,200);

sector(210,240,90,90+i,150,200);

sector(210,240,180,180+i,100,200);

sector(210,240,270,270+i,200,200);

sector(430,240,0,i,150,200);

sector(430,240,90,90+i,150,200);

sector(430,240,180,180+i,200,200);

sector(430,240,270,270+i,200,200);

}

setfillstyle(1,1);

for(i=10;i<=70;i+=5){

delay(500);

bar3d(190,20,450,i,5,1);

}

settextstyle(0,0,3); setcolor(6);

outtextxy(200,30,"TIME-TABLE");

settextstyle(0,0,1); setcolor(12);

outtextxy(195,60,"Couse Schedule Supervise System");

setfillstyle(1,1); setcolor(1);

for(i=100;i<=380;i+=10){

delay(100);

bar3d(120,100,300,i,15,1);

bar3d(340,100,520,i,15,1);

}

settextstyle(0,0,2); setcolor(6);

outtextxy(150,120,"STUDENT'S");

outtextxy(370,120,"TEACHER'S");

for(i=0;i<9;i++){

box(180,158+i*20,240,176+i*20,5,1,2,2,LIGHTGREEN,sp[i]);

box(400,158+i*20,460,176+i*20,5,1,2,2,LIGHTGREEN,sp[i]);

}

sx=180;sy=158;ex=240;ey=176; xincre=0;yincre=0;

p=sp;

do{

box(sx+xincre,sy+yincre,ex+xincre,ey+yincre,5,1,RED,RED,YELLOW,*p);

key=bioskey(0);

switch(key){

case LEFT:  if(xincre){

box(sx+xincre,sy+yincre,ex+xincre,ey+yincre,5,1,CYAN,CYAN,LIGHTGREEN,*p);

xincre-=220;}

break;

case RIGHT: if(!xincre){

box(sx+xincre,sy+yincre,ex+xincre,ey+yincre,5,1,CYAN,CYAN,LIGHTGREEN,*p);

xincre+=220;}

break;

case UP:    if(yincre){

box(sx+xincre,sy+yincre,ex+xincre,ey+yincre,5,1,CYAN,CYAN,LIGHTGREEN,*p);

p--;

yincre-=20;}

break;

case DOWN:  if(yincre<160){

box(sx+xincre,sy+yincre,ex+xincre,ey+yincre,5,1,CYAN,CYAN,LIGHTGREEN,*p);

p++;

yincre+=20; }

break;

case TAB:  if(!xincre){

box(sx+xincre,sy+yincre,ex+xincre,ey+yincre,5,1,CYAN,CYAN,LIGHTGREEN,*p);

xincre+=220;}

else if(yincre<160){

box(sx+xincre,sy+yincre,ex+xincre,ey+yincre,5,1,CYAN,CYAN,LIGHTGREEN,*p);

xincre-=220; yincre+=20;

p++; }

else{ box(sx+xincre,sy+yincre,ex+xincre,ey+yincre,5,1,CYAN,CYAN,LIGHTGREEN,*p);

xincre=0; yincre=0; p=sp;}

break;

case ESC: end();

}

}while(key!=ENTER);

/*   if(xincre) *p=strcat("Teachers-",*p);

else *p=strcat("Students-",*p);

return *p;

*/                                         /*WHY???*/

/*用上面的语句来替换下面语句的功能时,出现莫名其妙串连接情况*/

if(xincre){ if(strcmp(*p,"Infuse")==0) return "Teachers-Infuse";

else if(strcmp(*p,"Load")==0) return "Teachers-Load";

else if(strcmp(*p,"Save")==0) return "Teachers-Save";

else if(strcmp(*p,"Demand")==0) return "Teachers-Demand";

else if(strcmp(*p,"Insert")==0) return "Teachers-Insert";

else if(strcmp(*p,"Delete")==0) return "Teachers-Delete";

else if(strcmp(*p,"Sort")==0) return "Teachers-Sort";

else if(strcmp(*p,"Print")==0) return "Teachers-Print";

else if(strcmp(*p,"Exit")==0) return "Teachers-Exit";

}

else { if(strcmp(*p,"Infuse")==0) return "Students-Infuse";

else if(strcmp(*p,"Load")==0) return "Students-Load";

else if(strcmp(*p,"Save")==0) return "Students-Save";

else if(strcmp(*p,"Demand")==0) return "Students-Demand";

else if(strcmp(*p,"Insert")==0) return "Students-Insert";

else if(strcmp(*p,"Delete")==0) return "Students-Delete";

else if(strcmp(*p,"Sort")==0) return "Students-Sort";

else if(strcmp(*p,"Print")==0) return "Students-Print";

else if(strcmp(*p,"Exit")==0) return "Students-Exit";

}

}/*index*/

void rebkground(){     /*背景恢复*/

int i;

setfillstyle(6,4); setlinestyle(0,0,THICK_WIDTH);setcolor(8);

for(i=0;i<=60;i+=5){

sector(320,240,0,i,600,300); sector(320,240,60,60+i,600,300);

sector(320,240,120,120+i,600,300); sector(320,240,180,180+i,600,300);

sector(320,240,240,240+i,600,300); sector(320,240,300,300+i,600,300);

}

setlinestyle(0,0,NORM_WIDTH);

}/*rebkground*/

/***********************************Function 2******************************/

void bkground(char* p){

int i;

setfillstyle(6,8);setcolor(8);

for(i=0;i<=180;i+=5){

sector(320,240,180,180+i,500,242);

sector(320,240,0,i,500,244);

}

box(140,200,500,250,15,3,2,1,RED,p);

}/*bkground*/

void recbox(){

setfillstyle(1,1); setcolor(1);

bar3d(139,298,599,400,0,0);

setcolor(8);  setlinestyle(0,0,THICK_WIDTH);

rectangle(160,310,580,380);

settextstyle(0,0,1);

outtextxy(200,335,"Time-Table System  ver 1.0");

outtextxy(200,350,"Designer:zhouzhiming");

setlinestyle(0,0,NORM_WIDTH);

}/*recbox*/

void boxnn(ex,ey,num,p)

int ex,ey,num;

char **p;

{   int i;

setlinestyle(0,0,NORM_WIDTH); setcolor(2);

for(i=0;i

box(ex,ey+i*20,ex+130,ey+i*20+20,3,1,2,8,10,p[i]);

}

}/*boxnn*/

void infuse_first(){

int i,j;

setfillstyle(1,1); setlinestyle(0,0,NORM_WIDTH);setcolor(2);

for(i=40,j=40;i<=440&&j<=600;i+=5,j+=7){

delay(500);

bar3d(40,40,j,i,2,0);

}

}/*infuse_first*/

void attenbox(){      /*输入页面提示框*/

setfillstyle(1,8); setcolor(8);

bar3d(280,100,540,260,15,0);

setcolor(YELLOW);

outtextxy(375,110,"ATTENTION");

rectangle(290,120,530,250);

}/*attenbox*/

void subtable(pflag)      /*输入页面提示框处理*/

int pflag[7][5];

{  int i,j;

char ftemp[7][5][2];

char *wd[]={"Mo","Tu","We","Th","Fr","Sa","Su"};

char *chp[]={"1-2","3-4","5-6","7-8","9-10"};

void outatten();

attenbox();

outatten(305,130,27,13,"ERROR:two courses have been planned at the same time.");

outatten(305,240,27,13,"Press any key to cotinue!");

setcolor(1);

rectangle(310,160,518,238);

for(i=1;i<=5;i++){

line(310,160+i*13,518,160+i*13);

outtextxy(312,160+i*13+2,chp[i-1]);

}

line(342,160,342,238);

for(i=1;i<=7;i++){

line(342+i*24,160,342+i*24,238);

outtextxy(342+(i-1)*24+2,160+2,wd[i-1]);

}

for(i=0;i<7;i++)

for(j=0;j<5;j++){

setcolor(2);

sprintf(ftemp[i][j],"%c",pflag[i][j]+'0');

ftemp[i][j][1]='/0';

if(pflag[i][j]==1) setcolor(13);

outtextxy(342+i*24+2,173+j*13+2,ftemp[i][j]);

}

getch();getch();

}/*subtable*/

char* recourse(istore,mode,wderror)    /*课程输入*/

char istore[8][5][20];

int mode,wderror;

{   int i,j;

char *chp2[]={"Number:","Name  :","Period:"};

char* tinkey();

if(wderror==ERROR)  ;

else {  if(mode==1){ for(i=2;i<5;i++)

istore[0][i][0]='/0';

for(i=1;i<8;i++)

for(j=0;j<5;j++)

istore[i][j][0]='/0';

}

else for(i=0;i<8;i++)

for(j=0;j<5;j++)

istore[i][j][0]='/0';

}

outtextxy(120,180,"Course");

boxnn(120,200,3,chp2);

setcolor(7);

for(i=2;i<5;i++)

outtextxy(182,200+(i-2)*20+5,istore[0][i]);

box(80,300,135,315,3,1,2,2,10,"Course");

box(80,320,135,335,3,1,2,2,10,"Finish");

box(80,350,135,365,3,1,2,10,12,"Back");

box(80,370,135,385,3,1,2,10,12,"Exit");

recbox();

return tinkey(istore,mode,wderror);

}/*recourse*/

char* infuse(char* p,char istore[8][5][20],int mode){   /*录入界面及处理*/

int i,j;

char *tp;

char *chp[]={"Mon.","Tue.","Wed.","Thu.","Fri.","Sat.","Sun."};

char *chp2[]={"Number:","Name  :","Period:"};

chp[0]="Mon.";chp[1]="Tue.";chp[2]="Wed.";chp[3]="Thu.";chp[4]="Fri.";

chp[5]="Sat.";chp[6]="Sun."; /*whY???*/

setfillstyle(1,1); setlinestyle(0,0,NORM_WIDTH);setcolor(2);

bar3d(40,40,600,440,2,0);

if(*p=='T') tp="Teacher";

else tp="Student";

settextstyle(0,0,3);setcolor(6);

outtextxy(140,50,p);

settextstyle(0,0,1); setcolor(12);

outtextxy(120,100,tp);

boxnn(120,120,2,chp2);

setcolor(12);

setcolor(12);

outtextxy(120,280,"WeekDay");

for(i=0;i<7;i++)

box(180+i*55,280,230+i*55,295,3,1,2,2,10,chp[i]);

return recourse(istore,mode,OK);

}/*infuse*/

void redblank(int sx,int sy){

setlinestyle(0,0,THICK_WIDTH);setcolor(4);

rectangle(sx+62,sy+3,sx+128,sy+16);

setlinestyle(0,0,NORM_WIDTH);

}/*redblank*/

void whiteblank(int sx,int sy){

setfillstyle(1,7);setcolor(2);

bar(sx+61,sy+3,sx+129,sy+16);

}/*whiteblank*/

void reblank(int sx,int sy){

setfillstyle(1,8),setcolor(2);

bar(sx+61,sy+1,sx+129,sy+17);

}/*reblank*/

void outatten(sx,sy,lchnum,color,p)     /*录入时警告并提示检测处理*/

int sx,sy,color,lchnum;

char *p;

{ int i=0,j,length;

char ch[2];

settextstyle(0,0,1);setcolor(color);

length=strlen(p);

do{

if(length<=lchnum){ outtextxy(sx,sy+i*15,p); break;}

else for(j=0;j

sprintf(ch,"%c",*p);

ch[1]='/0';

outtextxy(sx+8*j,sy+i*15,ch);

p++; }

i++; length-=lchnum;

}while(1);

}/*outatten*/

char* tinkey(istore,mode,wderror)    /*录入数据键切换处理*/

char istore[8][5][20];

int mode,wderror;

{

char *p="Mon.",*bp="Mon.";

char *pp[]={"1-2 :","3-4 :","5-6 :","7-8 :","9-10:"};

char *chp[]={"Mon.","Tue.","Wed.","Thu.","Fri.","Sat.","Sun."};

char *ptemp=NULL,*keyback=NULL;

char *temp[8][5];

int sx,sy,ex,ey,bsx,bsy,bex,bey;

int i,j;

int flag,key=0;

for(i=0;i<8;i++)

for(j=0;j<5;j++)

temp[i][j]=istore[i][j];

if(mode==1){ bsx=sx=120; bsy=sy=200; bex=ex=250; bey=ey=220;}

else{  bsx=sx=120;bsy=sy=120;bex=ex=250;bey=ey=140;  }

flag=0;

do{

if(flag==0) if(key!=ENTER){

switch(sy){

case 120: ptemp=temp[0][1]; break;

case 140: if(bsy==120) ptemp=temp[0][0];

else if(bsy==200) ptemp=temp[0][2];

break;

case 200: if(bsy==140) ptemp=temp[0][1];

else ptemp=temp[0][3];

break;

case 220: ptemp=temp[0][(bsy-200)/20+2]; break;

case 240: if(bsy==220) ptemp=temp[0][3]; break;

case 300: case 320: case 340: case 360:

case 380: ptemp=temp[(bsx-140)/55+1][(bsy-300)/20]; break;

}/*swith*/

if(bsy==sy) ;

else{   reblank(bsx,bsy);

setcolor(7);

outtextxy(bsx+62,bsy+5,ptemp);

}

redblank(sx,sy);

if(wderror==OK){

attenbox();

outatten(305,130,27,12,"ENTER to input infodata.andthen press ENTER end.TAB orDIRECTION-KEY to switch!");

outatten(305,175,27,2,":finish a course infusing.Be to infuse next");

outatten(305,205,27,12,":finish a person infusing.Be to infuse next");

}

}/*if*/

else ;

else if(sy==280){ if(bsy==240){ reblank(bsx,bsy);

ptemp=temp[0][4];

setcolor(7); outtextxy(bsx+62,bsy+5,ptemp);

}

recbox();

box(sx,sy,ex,ey,3,1,4,4,YELLOW,p);

boxnn(sx-40,300,5,pp);

setcolor(7);

for(i=0;i<5;i++){

ptemp=temp[(sx-40-140)/55+1][i];

outtextxy(sx-40+62,300+i*20+5,ptemp); }

}

else box(sx,sy,ex,ey,3,1,4,4,YELLOW,p);

key=bioskey(0);

switch(sy){

case 120:

case 140:  switch(key){

case TAB:

case DOWN: if(sy==140){ bsy=sy;bey=ey; sy=200; ey=220;}

else{ bsy=sy;bey=ey; sy+=20; ey+=20;}

break;

case UP: if(sy!=120){ bsy=sy;bey=ey; sy-=20; ey-=20;

}

break;

case ENTER: whiteblank(sx,sy);

temp[0][(sy-120)/20]=uscanf(sx+62,sy,8);

attenbox();setcolor(7);

outtextxy(300,130,temp[0][(sy-120)/20]);

strcpy(istore[0][(sy-120)/20],temp[0][(sy-120)/20]);

free(temp[0][(sy-120)/20]);

temp[0][(sy-120)/20]=istore[0][(sy-120)/20];

break;

}

break;

case 200:  case 220:

case 240:  switch(key){

case TAB:

case DOWN:if(sy==240){ bsx=sx;bsy=sy;bex=ex;bey=ey;

sx=180; sy=280; ex=230; ey=295;p="Mon.";

flag=1; }

else{ bsy=sy; bey=ey;  sy+=20; ey+=20;}

break;

case UP: if(sy==200){ bsy=sy;bey=ey; sy=140; ey=160;}

else{ bsy=sy;bey=ey; sy-=20; ey-=20;}

break;

case ENTER: whiteblank(sx,sy);

temp[0][(sy-200)/20+2]=uscanf(sx+62,sy,8);

attenbox();setcolor(7);

outtextxy(300,130,temp[0][(sy-200)/20+2]);

strcpy(istore[0][(sy-200)/20+2],temp[0][(sy-200)/20+2]);

free(temp[0][(sy-200)/20+2]);

temp[0][(sy-200)/20+2]=istore[0][(sy-200)/20+2];

break;

}

break;

case 280: switch(key){

case LEFT: if(sx==180){ bsx=sx;bsy=sy;bex=ex;bey=ey; bp="Mon.";

box(bsx,bsy,bex,bey,3,1,2,2,10,bp);

recbox();

sx=80;sy=300; ex=135;ey=315; p="Course";

}

else{ bsx=sx;bsy=sy;bex=ex;bey=ey; bp=chp[(bsx-180)/55];

box(bsx,bsy,bex,bey,3,1,2,2,10,bp);

sx-=55;ex-=55; p=chp[(sx-180)/55];

}

break;

case TAB:

case RIGHT: if(sx!=510){

bsx=sx;bsy=sy;bex=ex;bey=ey; bp=chp[(bsx-180)/55];

box(bsx,bsy,bex,bey,3,1,2,2,10,bp);

sx+=55;ex+=55; p=chp[(sx-180)/55];

}

else {    recbox();

bsx=sx;bsy=sy;bex=ex;bey=ey; bp=chp[(bsx-180)/55];

box(bsx,bsy,bex,bey,3,1,2,2,10,bp);

sx=80;sy=300; ex=135;ey=315; p="Course"; }

break;

case UP:

bp=chp[(sx-180)/55];

box(sx,sy,ex,ey,3,1,2,2,10,bp);

recbox();

sx=120;sy=240; ex=120;ey=260;

bsx=sx;bsy=sy;bex=ex;bey=ey;

flag=0;

break;

case DOWN:

sx=sx-40; sy=300; ex=sx+130; ey=320;

bsx=sx;bsy=sy;bex=ex;bey=ey;

flag=0;

break;

}

break;

case 300:  case 320:  case 340:  case 360:

case 380: if(sx==80)

switch(key){

case UP: if(sy==320){

bsx=sx;bsy=sy;bex=ex;bey=ey; bp="Finish";

box(bsx,bsy,bex,bey,3,1,2,2,10,bp);

sy=300;ey=315;p="Course"; break; }

case RIGHT:

bsx=sx;bsy=sy;bex=ex;bey=ey;

if(sy==300)  bp="Course";

else bp="Finish";

box(bsx,bsy,bex,bey,3,1,2,2,10,bp);

sx=180;sy=280; ex=230;ey=295; p="Mon.";

break;

case TAB:

case DOWN:

if(sy==320){

bsx=sx;bsy=sy;bex=ex;bey=ey; bp="Finish";

box(bsx,bsy,bex,bey,3,1,2,2,10,bp);

sy=350;ey=365;p="Back";}

else { bsx=sx;bsy=sy;bex=ex;bey=ey; bp="Course";

box(bsx,bsy,bex,bey,3,1,2,2,10,bp);

sy=320; ey=335; p="Finish";}

break;

case ENTER:  if(sy==300) keyback="Course";

else keyback="Finish";

return (keyback);

}

else switch(key){

case TAB:

case DOWN: if(sy==380){

bsx=sx;bsy=sy;bex=ex;bey=ey;

sy=300; ey=320; }

else {  bsx=sx;bsy=sy;bex=ex;bey=ey;

sy+=20; ey+=20; }

break;

case UP: if(sy==300){ bsx=sx;bsy=sy;bex=ex;bey=ey;

sy=380; ey=400; }

else { bsx=sx;bsy=sy;bex=ex;bey=ey;

sy-=20; ey-=20; }

break;

case LEFT: if(sx==140){

/*bsx=sx;bsy=sy;bex=ex;bey=ey;*/

recbox();

box(180,280,230,295,3,1,2,2,10,"Mon.");

sx=80; sy=300; ex=135; ey=315;

flag=1; p="Course"; }

else{

/* bsx=sx;bsy=sy;bex=ex;bey=ey;*/

bp=chp[(sx+40-180)/55];

box(sx+40,280,sx+90,295,3,1,2,2,10,bp);

sx-=15;sy=280; ex=sx+50;ey=295;

flag=1; p=chp[(sx-180)/55];

}

break;

case RIGHT: if(sx!=470){

/* bsx=sx;bsy=sy;bex=ex;bey=ey; */

bp=chp[(sx+40-180)/55];

box(sx+40,280,sx+90,295,3,1,2,2,10,bp);

sx+=95; sy=280; ex=sx+50;ey=295;

flag=1; p=chp[(sx-180)/55];

}

else{ recbox();

box(510,280,560,295,3,1,2,2,10,"Sun");

sx=80;sy=300;ex=135;ey=315;

flag=1; p="Course";

}

break;

case ENTER: whiteblank(sx,sy);

temp[(sx-140)/55+1][(sy-300)/20]=uscanf(sx+62,sy,8);

if(wderror==OK){

attenbox();setcolor(7);

outtextxy(300,130,temp[(sx-140)/55+1][(sy-300)/20]);

}

strcpy(istore[(sx-140)/55+1][(sy-300)/20],temp[(sx-140)/55+1][(sy-300)/20]);

free(temp[(sx-140)/55+1][(sy-300)/20]);

temp[(sx-140)/55+1][(sy-300)/20]=istore[(sx-140)/55+1][(sy-300)/20];

break;

case ESC:   recbox();

}

break;

case 350: switch(key){

case UP:  box(sx,sy,ex,ey,3,1,2,2,10,"Back");

sy=320; ey=335; p="Finish";

break;

case TAB:

case DOWN: bsx=sx;bsy=sy;bex=ex;bey=ey; bp="Back";

box(bsx,bsy,bex,bey,3,1,2,2,10,bp);

sy=370; ey=385; p="Exit";

break;

case ENTER: keyback="Back";

return(keyback);

}

break;

case 370: switch(key){

case TAB:

case UP:

box(sx,sy,ex,ey,3,1,2,2,10,"Exit");

sy=350;ey=365; p="Back";

break;

case ENTER: keyback="Exit"; return keyback;

}

}/*switch*/

}while(key!=ESC);

}/*tinkey*/

/*******************************Function 3**********************************/

struct course *ccreat(istore)          /*课程链表创建(单向)*/

char istore[8][5][20];

{  int i,j;

int flag;

struct weekday *whead,*wdp1,*wdp2;

struct course *cp;

flag=0;             /*星期几单向链表 创建*/

whead=wdp1=wdp2=(struct weekday*)malloc(sizeof(struct weekday));

if(wdp1==NULL){ clearviewport();setcolor(4);settextstyle(0,0,3);

outtextxy(200,100,"Out of error!"); delay(5000);exit(0); }

for(i=0;i<5;i++)

wdp1->addr[i][0]='/0';

for(i=1;i<8;i++){

for(j=0;j<5;j++)

if(istore[i][j][0] !='/0'){ flag=1; break;}

if(flag==1){

wdp1->wday=i;

for(j=0;j<5;j++)

sprintf(wdp1->addr[j],"%s",istore[i][j]);

wdp2=wdp1;

wdp1=(struct weekday*)malloc(sizeof(struct weekday));

if(wdp1==NULL){ clearviewport();setcolor(4);settextstyle(0,0,3);

outtextxy(200,100,"Out of error!"); delay(5000);exit(0); }

wdp2->next=wdp1;

flag=0;

}

}

wdp2->next=NULL;

free(wdp1);

cp=(struct course*)malloc(sizeof(struct course));

if(cp==NULL){ clearviewport();setcolor(4);settextstyle(0,0,3);

outtextxy(200,100,"Out of error!"); delay(5000);exit(0);}

sprintf(cp->cnumber,"%s",istore[0][2]);

sprintf(cp->cname,"%s",istore[0][3]);

sprintf(cp->period,"%s",istore[0][4]);

cp->whead=whead;

cp->next=NULL;

settextstyle(0,0,1);

return (cp);

}/*ccreat*/

struct person* pcreat(istore)           /*个人课表创建*/

char istore[8][5][20];

{  int i,j;

struct person *pp;

pp=(struct person*)malloc(sizeof(struct person));

if(pp==NULL){ clearviewport();setcolor(4);settextstyle(0,0,3);

outtextxy(200,100,"Out of memery!"); delay(5000);exit(0);}

sprintf(pp->pnumber,"%s",istore[0][0]);

sprintf(pp->pname,"%s",istore[0][1]);

for(i=0;i<8;i++)

for(j=0;j<5;j++)

pp->pflag[i][j]=0;

pp->chead=NULL;

pp->pro=pp->next=NULL;

return (pp);

}/*pcreat*/

int wdetect(pp,istore)     /*课程安排时间重复检测*/

struct person *pp;

char istore[8][5][20];

{

struct weekday *wtemp;

int i,j;

for(i=1;i<8;i++)

for(j=0;j<5;j++)

if( (istore[i][j][0]!='/0') && (pp->pflag[i-1][j]==1) )

return ERROR;

for(i=1;i<8;i++)

for(j=0;j<5;j++)

if( (istore[i][j][0]!='/0') && (pp->pflag[i-1][j]==0) )

pp->pflag[i-1][j]=1;

return OK;

}/*wdetect*/

/****************************Function 4************************************/

/*输出*/

void pbkground(){

int i;

setcolor(8); setfillstyle(6,8);

for(i=0;i<=180;i+=5){

sector(320,240,0,i,320,320);

sector(320,240,180,180+i,320,320);

}

}/*pbkground*/

char *print(tittle)

char *tittle;

{

int i,j;

setfillstyle(1,1); setcolor(2);

for(j=0,i=0;j<=294&&i<=210;i+=5,j+=7){

bar3d(320-j,240-i,320+j,240+i,15,0);

}

settextstyle(0,0,3);setcolor(13);

outtextxy(140,50,tittle);

settextstyle(0,0,1); setcolor(8);

line(130,75,510,75);

line(70,300,70,420);

line(570,300,570,420);

}/*print*/

int forebox(pp)       /*输出FOREBOX框及下三个人课表提示*/

struct person *pp;

{ int i,j;

struct course *cp;

setlinestyle(0,0,THICK_WIDTH);setcolor(8);

rectangle(75,380,565,440);

setlinestyle(0,0,NORM_WIDTH);

outtextxy(280,385,"FORENOTICE");

for(i=0;i<3;i++)

if(pp!=NULL){

setcolor(8);

outtextxy(90,400+i*13,pp->pnumber);outtextxy(160,400+i*13,pp->pname);

cp=pp->chead;

for(j=0;j<2;j++)

if(cp!=NULL){  outtextxy(230+j*140,400+i*13,cp->cnumber);

outtextxy(300+j*140,400+i*13,cp->cname);

cp=cp->next;

}

else break;

if(j==2) outtextxy(510,400+i*13,"...");

pp=pp->next;

}/*if*/

}/*forebox*/

char *pkey(){          /*操作键处理*/

char *chp[]={"Next","Pro","Back","Exit"};

int sy,by;

int key;

box(30,350,65,365,3,1,4,4,YELLOW,"Next");

box(30,370,65,385,3,1,2,2,10,"Pro");

box(30,390,65,405,3,1,2,2,10,"Back");

box(30,410,65,425,3,1,2,2,10,"Exit");

by=sy=350;

do{ key=bioskey(0);

switch(key){

case   UP: if(sy==350){by=sy; sy=410;}

else { by=sy; sy-=20; }

break;

case TAB:

case DOWN: if(sy==410) { by=sy;sy=350; }

else { by=sy;sy+=20;  }

break;

}

box(30,by,65,by+15,3,1,2,2,10,chp[(by-350)/20]);

box(30,sy,65,sy+15,3,1,4,4,YELLOW,chp[(sy-350)/20]);

}while(key!=ENTER);

return chp[(sy-350)/20];

}/*pkey*/

int table(sx,sy,pp)    /*课表输出框,依次输出个人课表*/

int sx,sy;

struct person *pp;

{

struct course *ctemp=NULL;

struct weekday *wdtemp=NULL;

int i,j;

char *wdp[]={"Mon.","Tue.","Wed.","Thu.","Fri.","Sat.","Sun"};

char *chp[]={"1-2 :","3-4 :","5-6 :","7-8 :","9-10:"};

setfillstyle(11,8);setcolor(2);

bar3d(sx,sy,sx+70,sy+15,3,0); bar3d(sx+80,sy,sx+150,sy+15,3,0);

setfillstyle(1,8);

bar3d(sx,sy+20,640-sx,sy+20+240,5,0);

setfillstyle(6,8);setcolor(2);

bar3d(sx,sy+20,sx+40,sy+20+240,0,0);

bar3d(sx,sy+20,640-sx,sy+20+15,0,0);

line(sx,sy+20,sx+40,sy+35);

for(i=1,j=0;i<=15;i++){

setcolor(2);

line(sx,sy+20+i*15,640-sx,sy+20+i*15);

if(i%3==0){setcolor(3); outtextxy(sx+3,sy+20+i*15+5,"peri:");}

else if(i%3==2){setcolor(2); outtextxy(sx+3,sy+20+i*15+5,"adrr:");}

else{ setcolor(13); outtextxy(sx+3,sy+20+i*15+5,chp[j++]);}

}

for(i=0;i<=6;i++){

setcolor(2);

line(sx+40+i*64,sy+20,sx+40+i*64,sy+20+240);

setcolor(13);

outtextxy(sx+40+i*64+2,sy+20+5,wdp[i]);

}

if(pp!=NULL){

setcolor(7);

outtextxy(sx+2,sy+5,pp->pnumber);

outtextxy(sx+80+2,sy+5,pp->pname);

ctemp=pp->chead;

while(ctemp!=NULL){

wdtemp=ctemp->whead;

while(wdtemp!=NULL){

j=wdtemp->wday;

for(i=0;i<5;i++)

if(wdtemp->addr[i][0]!='/0'){

setcolor(10);

outtextxy(sx+40+(j-1)*64+2,sy+50+i*45+5,wdtemp->addr[i]);

setcolor(12);

outtextxy(sx+40+(j-1)*64+2,sy+35+i*45+5,ctemp->cname);

setcolor(11);

outtextxy(sx+40+(j-1)*64+2,sy+65+i*45+5,ctemp->period);

}

wdtemp=wdtemp->next;

}

ctemp=ctemp->next;

}/*while*/

}/*if*/

}/*table*/

/*****************************Function 5************************************/

void savebkground(char *tittle){

int i,j;

char* chp[]={".DOC :",".XLS :",".TXT :"};

setfillstyle(6,8);setcolor(8);

for(i=0;i<=180;i+=4){

sector(320,240,0,i,450,250);

sector(320,240,180,180+i,350,240);

}

setfillstyle(1,8);setcolor(8);

for(i=0;i<=220;i+=4){

bar3d(60,60,100+i,400,0,0);

bar3d(580,60,540-i,400,0,0);

}

setfillstyle(1,1);

bar3d(160,150,480,360,15,0);

settextstyle(0,0,3);setcolor(13);

outtextxy(100,120,tittle);

settextstyle(0,0,1); setcolor(2);

outtextxy(180,180,"FileType FileName");

boxnn(180,200,3,chp);

box(360,200,420,215,3,1,2,2,10,"Ok");

box(360,220,420,235,3,1,2,2,10,"Back");

box(360,240,420,255,3,1,2,2,10,"Exit");

setcolor(8);

rectangle(180,270,460,340);

}/*savebkground*/

char *fnscanf(){     /*接受人工输入*/

int i;

int sy,by;

int key;

char *filename;

char *temp=NULL;

filename=(char*)malloc(sizeof(char)*15);

redblank(180,200);

by=sy=200;

do{

key=bioskey(0);

switch(key){

case UP: temp=NULL;

if(sy==200) ;

else{ by=sy; sy-=20; }

reblank(180,by); redblank(180,sy);

break;

case TAB:

case DOWN: temp=NULL;

if(sy==240){ by=sy; sy=200;}

else{ by=sy; sy+=20; }

reblank(180,by); redblank(180,sy);

break;

case ENTER: whiteblank(180,sy);

temp=uscanf(180+62,sy,8);

break;

case RIGHT:  if(temp!=NULL){

for(i=0;i<20;i++)

filename[i]='/0';

sprintf(filename,"%s",temp);

if(sy==200) strcat(filename,".doc");

else if(sy==220) strcat(filename,".xls");

else strcat(filename,".txt");

return  filename;

}

}/*switch*/

}while(1);

}/*fnscanf*/

char *skey(){     /*操作键处理*/

int sy,by;

int key;

char *chp[]={"Ok","Back","Exit"};

chp[0]="Ok";chp[1]="Back";chp[2]="Exit";

box(360,200,420,215,3,1,4,4,10,"Ok");

by=sy=200;

do{

key=bioskey(0);

switch(key){

case UP: if(sy==200) ;

else{ by=sy; sy-=20; }

break;

case TAB:

case DOWN: if(sy==240){ by=sy; sy=200;}

else{ by=sy; sy+=20; }

break;

case LEFT: box(360,sy,420,sy+15,3,1,2,2,10,chp[(sy-200)/20]);

return NULL;

}/*switch*/

box(360,by,420,by+15,3,1,2,2,10,chp[(by-200)/20]);

box(360,sy,420,sy+15,3,1,4,4,10,chp[(sy-200)/20]);

}while(key!=ENTER);

return chp[(sy-200)/20];

}/*skey*/

char* save(char *filename,struct person *head){    /*以指定的格式保存文件*/

FILE *fp;

char array[21][8][10];

char *chp1[]={"","Mon.","Tue.","Wed.","Thu.","Fri.","Sat.","Sun."};

char *chp2[]={"1-2 :","3-4 :","5-6 :","7-8 :","9-10:"};

struct person *ptemp=NULL;

struct course *ctemp=NULL;

struct weekday *wtemp=NULL;

int i,j,day;

if(head==NULL) return "Failure!";

for(i=0;i<21;i++)

for(j=0;j<8;j++)

array[i][j][0]='/0';

for(i=0;i<8;i++)

strcpy(array[0][i],chp1[i]);

for(i=0;i<20;i++){

strcpy(array[1+i*4][0],"Cnumber:");

strcpy(array[2+i*4][0],chp2[i]);

strcpy(array[3+i*4][0],"addr :");

strcpy(array[4+i*4][0],"period:");

/*sprintf()与strcpy():使用SPRINTF()会出现异常现象*/

/*     sprintf(array[1+i*4][0],"%s","Cnumber:");

sprintf(array[2+i*4][0],"%s",chp2[i]);

sprintf(array[3+i*4][0],"%s","addr :");

sprintf(array[4+i*4][0],"%s","period:");*/

}

ptemp=head;

do{

for(i=1;i<21;i++)

for(j=1;j<8;j++)

array[i][j][0]='/0';

ctemp=ptemp->chead;

while(ctemp!=NULL){

wtemp=ctemp->whead;

while(wtemp!=NULL){

for(j=0;j<5;j++)

if(wtemp->addr[j][0]!='/0'){

strcpy(array[1+j*4][wtemp->wday],ctemp->cnumber);

strcpy(array[2+j*4][wtemp->wday],ctemp->cname);

strcpy(array[3+j*4][wtemp->wday],wtemp->addr[j]);

strcpy(array[4+j*4][wtemp->wday],ctemp->period);

}

wtemp=wtemp->next;

}

ctemp=ctemp->next;

}

if((fp=fopen(filename,"w"))==NULL){

clearviewport();setcolor(4);outtextxy(100,100,"Open file error!");

}

fprintf(fp,"/n/n/t/t/t/t%s/n/n","Time-Table");

fprintf(fp,"/tNum:%-10s",ptemp->pnumber);

fprintf(fp,"Name:%-10s",ptemp->pname);

for(i=0;i<21;i++){

fprintf(fp,"/n/t");

for(j=0;j<8;j++)

fprintf(fp,"%-10s",array[i][j]);

}

ptemp=ptemp->next;

}while(ptemp!=NULL);

fclose(fp);

return "Success!";

}/*save*/

/********************************Function 6********************************/

void dmbkground(char *tittle){

int i,j;

char *chp[]={"Name","Wkday","Course"};

setfillstyle(1,1); setcolor(2);

for(j=0,i=0;j<=294&&i<=210;i+=5,j+=7){

bar3d(320-j,240-i,320+j,240+i,15,0);

}

setcolor(13); settextstyle(0,0,3);

outtextxy(150,60,tittle);

settextstyle(0,0,1);

setcolor(8); rectangle(70,100,570,370);

outtextxy(110,390,"Demand-As:");

setfillstyle(1,2);

for(i=0;i<3;i++){

setcolor(2);

sector(200+i*60,390,0,360,5,5);

setcolor(8);

outtextxy(210+i*60,390,chp[i]);

}

setcolor(2);sector(450,390,0,360,5,5);

setcolor(8);outtextxy(460,390,"Back");

setcolor(2);sector(450,410,0,360,5,5);

setcolor(8);outtextxy(460,410,"Exit");

getch();getch();

}/*dmbkgound*/

void dmname(char *subject){

setfillstyle(1,1);setcolor(8);

bar3d(70,100,570,370,0,0);

outtextxy(240,200,"Input demand information");

outtextxy(250,250,subject);

line(300,260,400,260);

}/**/

void dmkey(int bx,int sx){

char *chp[]={"Name","Wkday","Course"};

if(sx<=320&&bx<=320){

dmname(chp[(sx-200)/60]);

setfillstyle(1,1);setcolor(1); sector(bx,390,0,360,5,8);

setfillstyle(1,2);setcolor(2); sector(bx,390,0,360,5,5);

setfillstyle(1,4);setcolor(4); sector(sx,390,0,360,5,8);

}

}/*dmkey*/

struct person *pdemand(struct person *phead,char *temp){   /*课表查询按姓名*/

struct person* ptemp;

if(phead==NULL || temp==NULL) return NULL;

ptemp=phead;

while(ptemp!=NULL){

if(strcmp(ptemp->pname,temp)==0)  return ptemp;

ptemp=ptemp->next;

}

return NULL;

}/*pdemand*/

struct person* wddemand(struct person* phead,int wday){   /*课表查询按星期几*/

struct person *ptemp;

struct weekday *wtemp;

struct course *ctemp;

if(phead==NULL)  return NULL;

ptemp=phead;

while(ptemp!=NULL){

ctemp=ptemp->chead;

while(ctemp!=NULL){

wtemp=ctemp->whead;

while(wtemp!=NULL){

if(wday==wtemp->wday)  return ptemp;

wtemp=wtemp->next;

}

ctemp=ctemp->next;

}

ptemp=ptemp->next;

}

return NULL;

}/*wddemand*/

struct person *cdemand(struct person *phead,char *course){     /*课表查询按课程名*/

struct person *ptemp;

struct course *ctemp;

if(phead==NULL)  return NULL;

ptemp=phead;

while(ptemp!=NULL){

ctemp=ptemp->chead;

while(ctemp!=NULL){

if(strcmp(ctemp->cname,course)==0)  return ptemp;

ctemp=ctemp->next;

}

ptemp=ptemp->next;

}

return NULL;

}/*cdemand*/

int chartoint(char* wday){

int i,day;

char *chp[]={"Mon","Tue","Wed","Thu","Fri","Sat","Sun"};

char *chp2[]={"Monday","Tuesday","Wednesday","Friday","Saturday","Sunday"};

for(i=0;i<7;i++)

if((strcmp(wday,chp[i])==0) || (strcmp(wday,chp2[i])==0))

return (i+1);

return 0;

}/*chartoint*/

void demanderror(){      /*查询结果处理*/

setfillstyle(1,1);setcolor(1);

bar3d(220,180,450,280,0,0);

settextstyle(0,0,2);setcolor(4);

outtextxy(220,200,"No Info-Datas");

settextstyle(0,0,1);

}/*demanderror*/

char *demand(struct person *phead){    /*查询*/

int sx,sy,bx,by;

int key,day;

char *temp;

struct person *ptemp;

setfillstyle(1,4);setcolor(4);

sector(200,390,0,360,5,8);

dmname("name");

sx=bx=200;sy=by=390;

do{ key=bioskey(0);

switch(sx){

case 200: switch(key){

case RIGHT: bx=sx; sx=260;break;

case ENTER: setfillstyle(1,7);setcolor(8);

bar3d(310,240,390,260,0,0);

temp=uscanf(315,240,8);

ptemp=pdemand(phead,temp);

if(ptemp==NULL)

demanderror();

else table(75,110,ptemp);

getch();getch();

break;

}

dmkey(bx,sx);

break;

case 260: switch(key){

case LEFT: bx=sx;  sx=200; break;

case RIGHT:bx=sx; sx=320; break;

case ENTER:setfillstyle(1,7);setcolor(8);

bar3d(310,240,390,260,0,0);

temp=uscanf(315,240,9);

day=chartoint(temp);

if(day==0){ demanderror(); getch();getch(); }

else{

ptemp=wddemand(phead,day);

if(ptemp==NULL)

{ demanderror();getch();getch();}

while(ptemp!=NULL){

table(75,110,ptemp);

getch();getch();

ptemp=wddemand(ptemp->next,day);

}

}/*else*/

break;

}

dmkey(bx,sx);

break;

case 320: switch(key){

case LEFT: bx=sx; sx=260; break;

case RIGHT:bx=sx; sx=450;

setfillstyle(1,4);setcolor(4); sector(450,390,0,360,5,8);

setfillstyle(1,1);setcolor(1); sector(320,390,0,360,5,8);

setfillstyle(1,2);setcolor(2); sector(320,390,0,360,5,5);

break;

case ENTER: setfillstyle(1,7);setcolor(8);

bar3d(310,240,390,260,0,0);

temp=uscanf(315,240,8);

if(temp==NULL)

{ demanderror();getch();getch();}

else{

ptemp=cdemand(phead,temp);

if(ptemp==NULL)

{ demanderror(); getch();getch();}

while(ptemp!=NULL){

table(75,110,ptemp);

getch();getch();

ptemp=cdemand(ptemp->next,temp);

}

}/*else*/

break;

}

dmkey(bx,sx);

break;

case 450:  switch(key){

case LEFT: sx=320;

setfillstyle(1,4);setcolor(4); sector(320,390,0,360,5,8);

setfillstyle(1,1);setcolor(1); sector(450,sy,0,360,5,8);

setfillstyle(1,2);setcolor(2); sector(450,sy,0,360,5,5);

break;

case UP:   if(sy==410){ by=sy; sy=390; break;}

case DOWN: if(sy==390){ by=sy;sy=410; break;}

else { by=sy; sy=390; break;}

case ENTER: if(sy==390) return "Back";

else  return "Exit";

}

if(sx!=320){

setfillstyle(1,1);setcolor(1); sector(450,by,0,360,5,8);

setfillstyle(1,2);setcolor(2); sector(450,by,0,360,5,5);

setfillstyle(1,4);setcolor(4); sector(450,sy,0,360,5,8);

}

break;

}/*swith*/

}while(1);

}/*demand*/

/*******************************Fuction 7**********************************/

void sortbkground(char *tittle){

int i,j;

setcolor(8); setfillstyle(1,8);

for(i=0;i<=180;i+=5){

sector(320,240,0,i,300,300);

sector(320,240,180,180+i,300,300);

}

setcolor(2); setfillstyle(1,1);

rectangle(120,100,520,380);

bar3d(140,120,500,360,5,0);

settextstyle(0,0,3); setcolor(3);

outtextxy(150,60,tittle);

settextstyle(0,0,2); setcolor(4);

outtextxy(290,220,"SORT");

line(260,240,380,240);

settextstyle(0,0,1); setfillstyle(1,2);

setcolor(2);sector(250,300,0,360,5,5);

setcolor(8);outtextxy(260,300,"Back");

setcolor(2);sector(360,300,0,360,5,5);

setcolor(8);outtextxy(370,300,"Exit");

}/*sortbkgound*/

struct course *csort(struct course *chead){     /*课程链排序(单向)*/

struct course *cp1,*cp2;

struct course *head,*newnode,*temp,*temppro;

int flag=0;

if(chead==NULL) return NULL;

do{

temp=chead;

cp2=chead;cp1=chead->next;

while(cp1!=NULL){

if(strcmp(temp->cnumber,cp1->cnumber)>0){

temp=cp1;

temppro=cp2;

}

cp2=cp1;

cp1=cp1->next;

}

if(temp==chead){ chead=chead->next;

temp->next=NULL; }

else{  temppro->next=temp->next;

temp->next=NULL; }

if(flag==0){ head=newnode=temp; flag=1; }

else{ newnode->next=temp;

newnode=newnode->next;

}

}while(chead!=NULL);

return head;

}/*csort*/

struct person *psort(struct person *phead){       /*课表链排序(双向)*/

struct person *pp1,*pp2;

struct person *head,*newnode,*temp,*temppro;

int flag=0;

if(phead==NULL)  return NULL;

do{

pp2=phead; pp1=pp2->next;

temp=phead;

while(pp1!=NULL){

if(strcmp(temp->pnumber,pp1->pnumber)>0){

temp=pp1;

temppro=pp2; }

pp2=pp1;

pp1=pp1->next;

}

if(temp==phead){ phead=phead->next;

phead->pro=NULL;

temp->next=NULL;

temp->pro=NULL;

temp->chead=csort(temp->chead);

}

else{  temppro->next=temp->next;

temp->next->pro=temppro;

temp->next=NULL;

temp->pro=NULL;

temp->chead=csort(temp->chead);

}

if(flag==0){  head=newnode=temp; flag=1; }

else{  newnode->next=temp;

temp->pro=newnode;

newnode=newnode->next; }

}while(phead!=NULL);

return head;

}/*psort*/

char *sort(phead)         /*排序*/

struct person **phead;

{

int sx,bx,sy;

int key;

sy=220;

do{ key=bioskey(0);

switch(sy){

case 220: switch(key){

case DOWN:   bx=sx=250; sy=300;

setfillstyle(1,1); setcolor(1);

bar3d(250,210,390,250,0,0);

settextstyle(0,0,2); setcolor(2);

outtextxy(290,220,"SORT");

line(260,240,380,240);

settextstyle(0,0,1); setfillstyle(1,4);

setcolor(4);sector(250,300,0,360,5,8);

break;

case ENTER:  *phead=psort(*phead);

setfillstyle(1,1); setcolor(1);

bar3d(260,210,380,250,0,0);

settextstyle(0,0,2);setcolor(12);

outtextxy(270,220,"SUCESS!");

line(260,240,380,240);

settextstyle(0,0,1);

}

break;

case 300: switch(key){

case UP: sy=220;

setfillstyle(1,1); setcolor(1);

bar3d(250,210,390,250,0,0);

settextstyle(0,0,2); setcolor(4);

outtextxy(290,220,"SORT");

line(260,240,380,240);

settextstyle(0,0,1);

setfillstyle(1,1);setcolor(1);

sector(sx,300,0,360,5,8);

setfillstyle(1,2);setcolor(2);

sector(sx,300,0,360,5,5);

break;

case LEFT:  if(sx==360)  bx=360;sx=250;

break;

case RIGHT: if(sx==250) bx=250;sx=360;

break;

case ENTER: if(sx==250) return "Back";

else  return "Exit";

}/*switch*/

if(sy==300){

settextstyle(0,0,1);

setfillstyle(1,1);setcolor(1);

sector(bx,300,0,360,5,8);

setfillstyle(1,2);setcolor(2);

sector(bx,300,0,360,5,5);

setfillstyle(1,4);setcolor(4);

sector(sx,300 ,0,360,5,8);

}

}/*switch*/

}while(1);

}/*sort*/

/******************************Function 8**********************************/

void idbkground(char *tittle,char *str){

int i,j;

setfillstyle(1,8); setcolor(2);

for(j=0,i=0;j<=280&&i<=200;i+=5,j+=7){

bar3d(320-j,240-i,320+j,240+i,15,0);

}

setfillstyle(1,1);setcolor(1);

for(i=0;i<=90;i+=6){

sector(320,240,0,i,200,100); sector(320,240,90,90+i,200,100);

sector(320,240,180,180+i,200,150); sector(320,240,270,270+i,200,150);

}

settextstyle(0,0,3); setcolor(13); outtextxy(160,70,tittle);

settextstyle(0,0,2); setcolor(4);  outtextxy(280,230,str);

settextstyle(0,0,1); setfillstyle(1,2);

setcolor(2);sector(250,300,0,360,5,5);

setcolor(8);outtextxy(260,300,"Back");

setcolor(2);sector(360,300,0,360,5,5);

setcolor(8);outtextxy(370,300,"Exit");

}/*insertbkground*/

char *insert(char *tittle,struct person **shead,struct person **thead){  /*插入*/

char istore[8][5][20];

char *keytemp,*keyindex=tittle;

struct person *shtemp,*thtemp,*ptemp;

char *infcreat();

shtemp=thtemp=NULL;

keytemp=infcreat(&keyindex,&shtemp,&thtemp,istore);

if(shtemp!=NULL){  ptemp=shtemp;

while(ptemp->next!=NULL)

ptemp=ptemp->next;

ptemp->next=*shead;

(*shead)->pro=ptemp;

*shead=shtemp;

}

if(thtemp!=NULL){  ptemp=thtemp;

while(ptemp->next!=NULL)

ptemp=ptemp->next;

ptemp->next=*thead;

(*thead)->pro=ptemp;

*thead=thtemp;

}

return keytemp;

}/*insert*/

char *delete(struct person **phead,char *pname){     /*删除*/

struct person *ptemp,*pp1;

ptemp=pp1=*phead;

if((ptemp==NULL)||(pname==NULL)) return "Failure";

while(ptemp!=NULL){

if(strcmp(ptemp->pname,pname)==0) break;

pp1=ptemp;

ptemp=ptemp->next;

}

if(ptemp==NULL)  return "No Data";

if(pp1==*phead){ *phead=pp1->next;  (*phead)->pro=NULL; }

else{  pp1->next=ptemp->next; ptemp->next->pro=pp1; free(ptemp);  }

return "Success";

}/*delete*/

char* insdel(char* tittle,char *str,struct person **shead,struct person **thead)

/*插入或删除,同一个界面,不同的处理*/

{

int sx,bx,sy;

int key;

char *keytemp;

sy=230;

do{

key=bioskey(0);

switch(sy){

case  230: switch(key){

case DOWN: sy=300; sx=250;

setfillstyle(1,1);setcolor(1);

bar3d(250,200,400,250,0,0);

settextstyle(0,0,2);setcolor(2);

outtextxy(280,230,str);

settextstyle(0,0,1); setfillstyle(1,4);

setcolor(4);sector(250,300,0,360,5,8);

break;

case ENTER:  if(strcmp(str,"Insert?")==0)    /*分别处理*/

return   insert(tittle,shead,thead);

if(strcmp(str,"Delete?")==0){

settextstyle(0,0,2);setcolor(1);

outtextxy(280,230,str);

settextstyle(0,0,1);

setfillstyle(1,7); setcolor(2);

outtextxy(260,210,"Input Name:");

bar3d(275,230,350,247,0,0);

keytemp=uscanf(280,230,8);

if(strcmp(tittle,"Student")==0)

keytemp=delete(shead,keytemp);

else{ keytemp=delete(thead,keytemp);}

key=NULL; sy=300; sx=250;

setfillstyle(1,1);setcolor(1);

bar3d(250,200,400,250,0,0);

settextstyle(0,0,2);setcolor(2);

outtextxy(280,230,keytemp);

settextstyle(0,0,1); setfillstyle(1,4);

setcolor(4);sector(250,300,0,360,5,8);

}/*if*/

}

break;

case  300: switch(key){

case LEFT: if(sx==360){ bx=360;sx=250;}

break;

case TAB:

case RIGHT:if(sx==250){ bx=250;sx=360;}

break;

case UP:  setfillstyle(1,1);setcolor(1);

bar3d(250,200,400,250,0,0);

settextstyle(0,0,2);setcolor(4);

outtextxy(280,230,str);

if(sx==250){ bx=sx=250; sy=230;}

else{ bx=sx=360; sy=230; }

break;

case ENTER:if(sx==250)  return "Back";

else  return "Exit";

}

setfillstyle(1,4);setcolor(4); sector(sx,300,0,360,5,8);

setfillstyle(1,1);setcolor(1); sector(bx,300,0,360,5,8);

setfillstyle(1,2);setcolor(2); sector(bx,300,0,360,5,5);

break;

}/*swith*/

}while(key!=ENTER);

}/*insdel*/

/******************************Funtion 9***********************************/

char *infcreat(keyindex,shead,thead,istore)     /*接FUCTION 3创建课表链*/

char **keyindex;

struct person **thead,**shead;

char istore[8][5][20];

{  struct person *tp1,*tp2,*sp1,*sp2;

struct course *chead,*cp1,*cp2;

char *keyinfuse;

int  wderror=OK;

rebkground();

bkground(*keyindex); infuse_first();

keyinfuse=infuse(*keyindex,istore,0);

chead=cp1=cp2=ccreat(istore);

if(**keyindex=='T'){

*thead=tp1=tp2=pcreat(istore);

tp1->chead=chead;

wdetect(tp1,istore);

}

else{

*shead=sp1=sp2=pcreat(istore);

sp1->chead=chead;

wdetect(sp1,istore);

}

do{

if((strcmp(keyinfuse,"Course"))==0){

keyinfuse=recourse(istore,1,wderror);

wderror=OK;

if(strcmp(keyinfuse,"Course")==0)

if((**keyindex=='S')&&(wdetect(sp1,istore)==ERROR))

{ wderror=ERROR; subtable(sp1->pflag); }

else if((**keyindex=='T')&&(wdetect(tp1,istore)==ERROR))

{ wderror=ERROR; subtable(tp1->pflag); }

else { cp1=ccreat(istore);

cp2->next=cp1;

cp2=cp1;

}

}/*if*/

else if((strcmp(keyinfuse,"Finish"))==0){

keyinfuse=infuse(*keyindex,istore,0);

if((strcmp(keyinfuse,"Course")==0)||(strcmp(keyinfuse,"Finish")==0))

{  chead=cp1=cp2=ccreat(istore);

if(**keyindex=='T'){

tp1=pcreat(istore);

tp1->chead=chead;

tp1->pro=tp2;

tp2->next=tp1;

tp2=tp1;

wdetect(tp1,istore);

}

else { sp1=pcreat(istore);

sp1->chead=chead;

sp1->pro=sp2;

sp2->next=sp1;

sp2=sp1;

wdetect(sp1,istore);

}

}/*if*/

}/*if*/

else if(strcmp(keyinfuse,"Back")==0)

return "Back";

else return "Exit";

}while((strcmp(keyinfuse,"Course")==0)||(strcmp(keyinfuse,"Finish")==0)

||(strcmp(keyinfuse,"Back")==0)||(strcmp(keyinfuse,"Exit")==0));

}/*infcreat*/

/**************************************************************************/

main(){

char *keyindex,*keytemp;

char *keyinfuse,*keyrecourse;

char *keyload,*keysave,*sfname;

char *keyprint;

char *keydemand;

char *keyinsdel;

char *keysort;

char *chp[9][2]={"Students-Infuse","Teachers-Infuse","Students-Load","Teachers-Load",

"Students-Save","Teachers-Save","Students-Demand","Teachers-Demand",

"Students-Insert","Teachers-Insert","Students-Delete","Teachers-Delete",

"Students-Sort","Teachers-Sort","Students-Print","Teachers-Print",

"Students-Exit","Teachers-Exit"};

char istore[8][5][20];

int tindex,flag;

int i,j;

struct person *thead,*shead;

struct person *ptemp;

thead=shead=NULL;

SETGRAPH();

starting();

rebkground();

keyindex=index();

do{

flag=0; tindex=0;

for(i=0;i<9;i++)

for(j=0;j<2;j++)

if((strcmp(keyindex,chp[i][j]))==0)

tindex=(i+1)*10+j+1;

switch(tindex){

case 11:

case 12: keytemp=infcreat(&keyindex,&shead,&thead,istore);

if(strcmp(keytemp,"Back")==0){  rebkground();

keyindex=NULL;

keyindex=index();

flag=1;}

else end();

break;

case 21:

case 22: rebkground();

savebkground("Load-AS");

sfname=fnscanf();

keyload=NULL;

keyload=skey();

if(strcmp(keyload,"Ok")==0){  ; }

else if(strcmp(keyload,"Back")==0){

rebkground();

keyindex=NULL;

keyindex=index();

flag=1;

}

else if(strcmp(keyload,"Exit")==0) end();

getch();getch();

break;

case 31:

case 32: rebkground();

savebkground("Save-As");

sfname=fnscanf();

keysave=NULL;

keysave=skey();

if(strcmp(keysave,"Ok")==0){

if(tindex==31) save(sfname,shead);

else save(sfname,thead);

/***     加上下列语句出现异常显示情况

closegraph();

SETGRAPH();

rebkground();

keyindex=NULL;

keyindex=index();

flag=1;   ***/     /*WHY???*/

}

else if(strcmp(keysave,"Back")==0){

rebkground();

keyindex=NULL;

keyindex=index();

flag=1;

}

else if(strcmp(keysave,"Exit")==0) end();

break;

case 41:

case 42: rebkground();

if(tindex==41){ dmbkground("Students-Demand");

keydemand=demand(shead); }

else { dmbkground("Teachers-Demand");

keydemand=demand(thead); }

if(strcmp(keydemand,"Back")==0){

rebkground();

keyindex=NULL;

keyindex=index();

flag=1;

}

else if(strcmp(keydemand,"Exit")==0)  end();

break;

case 51:  case 52:  case 61:

case 62: rebkground();

if(tindex==51){ idbkground("Student-Insert","Insert?");

keyinsdel=insdel("Student-Insert","Insert?",&shead,&thead);

}

else if(tindex==52){ idbkground("Teacher-Insert","Insert?");

keyinsdel=insdel("Teacher-Insert","Insert?",&shead,&thead);

}

else if(tindex==61){ idbkground("Student-Delete","Delete?");

keyinsdel=insdel("Student","Delete?",&shead,&thead);

}

else{  idbkground("Teacher-Delete","Delete?");

keyinsdel=insdel("Teacher","Delete?",&shead,&thead);

}

if(strcmp(keyinsdel,"Back")==0){

rebkground();

keyindex=NULL;

keyindex=index();

flag=1; }

else  end();

break;

case 71:

case 72: rebkground();

if(tindex==71){ sortbkground("Students-Sort");

keysort=sort(&shead);

}

else{ sortbkground("Teachers-Sort");

keysort=sort(&thead);

}

if(strcmp(keysort,"Back")==0){ rebkground();

keyindex=NULL;

keyindex=index();

flag=1;

}

else  end();

break;

case 81:

case 82: if(tindex==81) ptemp=shead;

else ptemp=thead;

if(ptemp==NULL){ keyindex=index(); flag=1;}

else{

rebkground();

pbkground();

while(ptemp!=NULL){

if(tindex==81) print("Students-Print");

else print("Teachers-Print");

table(75,110,ptemp);

forebox(ptemp->next);

keyprint=pkey();

if(strcmp(keyprint,"Next")==0){

if(ptemp->next==NULL) ;

else ptemp=ptemp->next;

}

else if(strcmp(keyprint,"Pro")==0){

if(ptemp->pro==NULL) ;

else ptemp=ptemp->pro;

}

else if(strcmp(keyprint,"Back")==0) {

rebkground();

keyindex=NULL;

keyindex=index();

flag=1;break; }

else end();

}/*while*/

}/*else*/

break;

case 91:

case 92: end();

}/*switch*/

}while(flag==1);

delay(10000);

end();

}/*main*/

c语言 排课系统 利用栈,C语言-课表排课系统相关推荐

  1. c语言 排课系统 利用栈,如何用c语言去实现排课系统的开发,

    排课系统的开发是基于遗传算法的这里有遗传算法框架,可运行的!!就是不懂得排课系统的分析需求!如何改造适应度函数,求高手指点-- #include #include #include #include ...

  2. 学生档案c语言编程,学生档案管理完整(C语言).doc

    目 录 TOC \o "1-3" \h \z \u HYPERLINK \l "_Toc280949959" 摘 要 PAGEREF _Toc280949959 ...

  3. C语言-课表排课系统

    程序用C语言实现,看文档日期是04年中旬写的.程序有WORD文档但流程图和结构图我拷不上来,我在下面帖一些程序的主要模块.主要函数以及程序操作说明,方面了解程序的整个流程,以供学习: 基本操作: 输入 ...

  4. c语言编程排课系统,C语言-课表排课系统.docx

    C语言-课表排课系统 基本操作: 输入并创建链表(单向和双向)"参见:infcreato:装载"算法与存储一致 存储//图形模式下,进行文件读写操作后有无故的异常显示 查询//算法 ...

  5. c语言贪心算法排课,*排课软件常用算法介绍*兴文排课*学校经常用的免费自动排课软件...

    将需要求解的课表问题逐层分解,直到得到一个最小单元的不可在分解.可以直接求出答案的子问题.分解出来的所有子问题按层次关系构成一颗子问题树.树根是课程表问题.课程表问题的解依赖于子问题树中所有子问题的解 ...

  6. 用python写排课系统_JSP基于WEB的网上选排课系统,源码下载

    大家好,我是全微毕设团队的创始人,本团队擅长JAVA(SSM,SSH,SPRINGBOOT).PYTHON.PHP.C#.安卓等多项技术. 今天将为大家分析一个网上选排课系统(高校排课系统要求十分严格 ...

  7. C语言中用栈实现进制转换,利用栈实现进制转换问题

    进制转换问题 建立顺序栈或链栈,编写程序实现十进制数到二进制数的转换. 输入 输入只有一行,就是十进制整数. 输出 转换后的二进制数. 样例输入 10 样例输出 1010 十进制怎么转为二进制?十进制 ...

  8. c语言编写队列元素逆置,数据结构与算法实验—利用栈逆置队列元素.doc

    数据结构与算法实验-利用栈逆置队列元素 利用栈逆置队列元素实验报告 通信1204班 谢崇赟 实验名称 利用堆栈将队列中的元素逆置 实验目的 会定义顺序栈和链栈的结点类型. 掌握栈的插入和删除结点在操作 ...

  9. 利用栈进行数制转换和括号匹配(C语言)

    数制转换:将十进制数转换为任意进制数.由数制转换的计算公式 N = (N / d) × d + N % d (其中N为想转换的十进制数,d为想转换的进制) 我们可以知道其转换后的结果是逆序输出,故可以 ...

最新文章

  1. 《实施Cisco统一通信管理器(CIPT1)》一2.4 使用分布式呼叫处理的多站点WAN部署模型...
  2. Android 10 中有关限制非 SDK 接口的更新
  3. golang goroutine的调度模型:MPG模式
  4. php军事网站源码,军事网站的设计与实现(PHP+MYSQL)(含录像)
  5. 软件测试作业2:在敏捷宣言遵循的12条原则中挑选1条你感兴趣的原则进行风险评估
  6. Netty4.x中文教程系列(二) Hello World !
  7. RocketMQ如何解决分布式事务
  8. JavaScript:三大家族
  9. 【转】运用jieba库分词
  10. 使用tushare数据进行backtrader回测
  11. 西门子200PLC指令详解——位逻辑指令
  12. Python科学绘图 南丁格尔图/玫瑰图
  13. html 防网页假死,htmlweb开发:防止浏览器假死的方法.doc
  14. 【Hexo搭建个人博客】:yilia主题配置(一) - 基础配置
  15. (海伦公式)已知三角形三条边长,求面积
  16. 设计网站中的精品,你可能需要它--第五期(Logo设计,助你提升效率)
  17. 创新型中小企业如何认定?
  18. 下面哪个python库不能用于提取网页信息_利用python的webscraping库采集抓取爱帮网电话号码...
  19. 计算机科学大师唐纳德,现代计算机科学的鼻祖,编程界的上帝,视全世界的码农当作艺术家...
  20. 交易猫 转转 闲鱼后台源码

热门文章

  1. 榆林市科技馆项目的变电所运维
  2. 重要提醒,万能五笔变身超级大流氓升级超级流氓团组团静默安装!
  3. AltiumDesigner绘制PCB(二)
  4. 一张图弄明白:从零维到十维空间……给大神跪了!
  5. Apache Tomcat unexpected file deletion and/or alteration
  6. pixhawk 模拟飞行
  7. windows设置默认打开方式
  8. inotifywait+rsync 实时同步脚本
  9. 小凯的疑惑 原题+Plus 证明
  10. 如何配置一部4块Titan X GPU的深度学习机器