天天看點

c語言 排課系統 利用棧,C語言-課表排課系統

功能子產品概要說明:

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時,并按Enter鍵後,表明此學生在這一學期内所學的課程資訊輸入完成。如要繼續輸入學生的資訊如前所述。

當選定back時,并按下Enter鍵後,傳回TIME TABLE主菜單,選擇主菜單裡的功能對所輸入的資訊進行處理。

當選定exit時,并按下Enter鍵後,傳回程式。結束程式。

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();

。。。。。。

//源程式代碼

#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;

};

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);

}

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);

}

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);

}

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);

}

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){ 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";

}

}

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);

}

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);

}

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);

}

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]);

}

}

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);

}

}

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);

}

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();

}

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);

}

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.";

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);

}

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);

}

void whiteblank(int sx,int sy){

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

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

}

void reblank(int sx,int sy){

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

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

}

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);

}

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;

}

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");

}

}

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){

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{

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){

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;

}

}

}while(key!=ESC);

}

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);

}

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);

}

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;

}

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);

}

}

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);

}

int forebox(pp)      

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;

}

}

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];

}

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;

}

}

}

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);

}

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;

}

}

}while(1);

}

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;

}

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];

}

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:");

}

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!";

}

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();

}

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);

}

}

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;

}

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;

}

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;

}

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;

}

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);

}

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);

}

}

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);

}

}

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;

}

}while(1);

}

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");

}

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;

}

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;

}

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";

}

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);

}

}

}while(1);

}

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");

}

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;

}

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";

}

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);

}

}

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;

}

}while(key!=ENTER);

}

char *infcreat(keyindex,shead,thead,istore)    

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;

}

}

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);

}

}

}

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));

}

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);

}

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();

}

}

break;

case 91:

case 92: end();

}

}while(flag==1);

delay(10000);

end();

}