该系统是本人课程设计作业,因为时间关系,只用了两天多的时间编成。所以有很多地方没有得到增强。版本为1.0。现作以下升级。
增加NEW,OPEN版本。
提高输入容错。判断输入的对错。
时间关系,搜索功能为线性搜索,现增强如下:f_search:费氏查找法;btree:二叉树查找法;l_search:线性查找法; r_search:递归折半查找法;zcsear:杂凑碰撞查找法;o_sear:插补查找加强法; 排序是冒泡法,现增强为:heaps:累堆排序;binary:二叉树排序;xieer:谢耳排序;sinsert:插入排序;quicks:快速排序;select:选择排序法;
有时间不仿试试。
/*-----------------------------------------------------------------------------------------------------*/
共享代码是这个编程世界的主题!
/*-----------------------------------------------------------------------------------------------------*/
/*------------------------------宏定义-------------------------------------*/
#include<graphics.h> #include<conio.h> #include<stdio.h> #include<dos.h>
/*-----------------------------函数声明--------------------------------------*/ void Showms(int); /*显示个数和页数*/ void SHOW(int,int ); /*显示记录*/ void Init(); /*初始化图形模式*/ void Drawwin(int,int,int,int,int); /*画图*/ void Load(); /*初始化数据*/ void Paswrd(); /*输入密码*/ void Kernel(); /*核心算法*/ void Draw(); /*画图*/ void Win(int x,int y,int l,int w); /*画3D*/ void HELP(); /*帮助函数*/ void EDIT(); /*编辑函数*/ void DELETE(); /*删除函数*/ int ADD(); /*添加函数*/ void SORT(); /*排序函数*/ void SEARCH(); /*搜索函数*/ void Loadfile(); /*初始化文件*/ void Savesm() ; /*记录总数*/ void Quick( ); /*冒泡排序*/ int PAGEUP(int page,int); /*翻页函数*/ int PAGEDM(int page,int );
#define Move printf("\n\n\n\n\n\n\n\n\n") /*换行*/ #define ON 1 /*定义开关*/ #define OFF 0 /*-------------------------------定义热键----------------------------------*/ #define ESC 27 #define F2 60 #define A 97 #define S 115 #define O 111 #define H 104 #define E 101 #define D 100 #define Pageup 73 #define Pagedm 81 #define ALL 100 /*文件个数*/
char *red[]={" A","D","E","S","o","H"}; /*热键显示*/ char *f[]={" Add","Delete","Edit","Search","Sort","Help"}; /*显示菜单*/ char *Hel[]={"ESC: QUIT", /*Help内容*/ "A : ADD", "D : DELETE", "E : EDIT", "S : SEARCH", "O : SORT", "H : HELP", "PAGEDOWN: ", "PAGEUP: ", "Fuction sort: ", " ESC: restore" }; typedef struct Telms /*建立数组*/ { char name[15]; char telnum[15]; char Email[20]; char workpl[30];
}Message;
int sum[1],pg=1; /*文件个数*/ void *buffer,*buff; /*记录画面指针*/
Message msg[ALL],msgtem[ALL]; /*msg为记录文件数组,msgtem为暂时记录排序数组*/
/*-------------------------------主函数---------------------------------*/ main() { Paswrd(); /*读入并检验密码*/ Init(); /*初始文件和界面*/ Kernel(); /*核心*/
}
/*-----------------------------初始化图形模式-----------------------------------*/ void Init() { int driver=DETECT,mode,code; int i;
registerbgidriver(EGAVGA_driver); /*初始化图形模式*/
initgraph(&driver,&mode,"");
code=graphresult(); if(code!=grOk) { printf("\nGraphics System Error:%s\n",grapherrormsg(code)); getch(); exit(0); }
Drawwin(100,100,439,250,ON); /*画图*/ Drawwin(120,120,399,210,OFF); Drawwin(350,150,150,150,ON);
setcolor(DARKGRAY); settextstyle(0,0,8); outtextxy(145,179,"TBS");
setcolor(RED); outtextxy(140,173,"TBS");
setcolor(LIGHTBLUE); settextstyle(0,0,2); outtextxy(145,310,"Telephone Book System"); setcolor(RED); settextstyle(0,0,1); outtextxy(260,245,"Version 1.0"); setcolor(BLUE); settextstyle(0,0,1); outtextxy(360,175,"Foshan University"); outtextxy(380,190,"03 Computer 2"); outtextxy(387,205,"2003314241"); outtextxy(380,220,"Liang Weijian"); Load(); /*初始化数据*/ while(!kbhit()); /*按键退出*/ closegraph(); /*关闭图形模式*/ }
/*-----------------------------3D界面------------------------------------------------*/ void Drawwin(int x,int y,int l,int w,int sta) {
setfillstyle(1,LIGHTGRAY); bar(x+1,y+1,x+l-1,y+w-1);
setcolor((sta==ON)?WHITE:DARKGRAY); moveto(x,y+w); lineto(x,y); lineto(x+l,y);
setcolor((sta==OFF)?WHITE:DARKGRAY); moveto(x,y+w); lineto(x+l,y+w); lineto(x+l,y);
}
/*-------------------------------文件读入-----------------------------------------*/ void Load() {
int i,tem=0; FILE* fp;
setcolor(RED); outtextxy(365,265,"Load......"); setfillstyle(1,GREEN); bar(351,280,498,290);
if((fp=fopen("sum.dat","rb"))==NULL) /*打开sum[0]文件,无,建立*/ { fp=fopen("sum.dat","wb"); sum[0]=0; fwrite(&sum,sizeof(sum[0]),1,fp); fp=fopen("sum.dat","rb"); } fread(&sum[0],sizeof(sum),1,fp); fclose(fp);
if((fp=fopen("TBS.dat","rb"))==NULL) /*打开TBS文件,无,建立*/ { fp=fopen("TBS.dat","wb"); fp=fopen("TBS.dat","rb"); }
for(i=0;i<147;i++) { setfillstyle(1,LIGHTGREEN); bar(351,280,351+i,290); delay(1000+tem*100); if(tem<sum[0]) { fread(&msg[tem],sizeof(msg),1,fp); /*初始化数据*/ tem++; } } fclose(fp); setfillstyle(1,LIGHTGRAY); bar(351,260,498,290); settextstyle(0,0,1);
setcolor(RED); outtextxy(375,260,"Press any key!"); while(!kbhit());
} /*--------------------------------输入密码---------------------------------*/ void Paswrd() { char *passwrd,*Right="handy"; char temp[9]; int i=0;
Move; /*换行*/
printf(" Thank you for using this system!\n\n"); passwrd=getpass(" Input a password (Not show):"); strcpy(temp,passwrd);
while(1) { Move;
if(strcmp(temp,Right)!=0) { i++; clrscr(); Move; passwrd=getpass(" Worry!Input again:"); strcpy(temp,passwrd); } else { clrscr(); break; } clrscr(); if(i==3) { Move; printf(" Sorry!You have enter three times password!\n"); printf(" Press any key!"); getch(); exit(0); }
}
}
/*-------------------------------核心算法----------------------------------*/ void Kernel() {
char Key; /*记录按键*/ int page=1,i; FILE *fp; Draw(); /*画图*/ buffer=(void *)malloc(2*80*23); gettext(1,1,80,23,buffer); /*记录画面*/ buff=(void *)malloc(2*80*2); gettext(1,23,80,23,buff); if(sum[0]%19==0&&sum[0]!=0) /*计算总页数*/ pg=sum[0]/19; /*刚好满页*/ else pg=sum[0]/19+1; /*不够一页,当一页*/
SHOW(page,ON); /*显示信息,ON为msg,OFF为排序用的*/ while(1) /*进入循环*/ { SHOW(page,ON); Showms(page);
while(!kbhit()); /*获取按键*/ Key=getch();
switch(Key) { case A:page=ADD();break; case D:DELETE();break; case S:SEARCH();break; case SORT();break; case E:EDIT();break; case H:HELP();break; case Pageup:page=PAGEUP(page,ON);break; case Pagedm:page=PAGEDM(page,ON);break; case ESC: fp=fopen("TBS.dat","wb"); for(i=0;i<sum[0];i++) fwrite(&msg[i],sizeof(Message),1,fp); fclose(fp); free(buffer); free(buff); clrscr(); exit(0); break; }
}
}
/*----------------------------文本模式下的画面----------------------------*/ void Draw() { int x,y,i,l; textmode(C80); textbackground(BLACK); window(1,1,80,23); textbackground(WHITE); window(1,24,80,24); clrscr();
for(i=0;i<6;i++) { x=wherex(); y=wherey();
textcolor(BLACK); cprintf("%s",f[i]); l=strlen(f[i]); gotoxy(x,y); textcolor(RED); if(i==4) { gotoxy(x+1,y); cprintf("%s",red[i]); } else cprintf("%s",red[i]); x=x+l+8; gotoxy(x,y); } textbackground(BLACK); window(1,1,80,23); Win(1,1,78,21);
textcolor(YELLOW); gotoxy(7,2); cprintf("Name"); gotoxy(22,2); cprintf("Telphone"); gotoxy(43,2); cprintf("QQ"); gotoxy(60,2); cprintf("Workplace"); textcolor(WHITE);
} /*---------------------------文本模式下的作图-------------------------------*/ void Win(int x,int y,int l,int w) { int i,j; gotoxy(x,y); putch(213); for(j=0;j<2;j++) { for(i=0;i<15;i++) putch(205); putch(209); } for(i=0;i<20;i++) putch(205); putch(209); for(i=0;i<25;i++) putch(205); putch(184);
for(i=0;i<20;i++) { gotoxy(x,y+1+i); putch(179); gotoxy(17,y+1+i); putch(179); gotoxy(33,y+1+i); putch(179); gotoxy(54,y+1+i); putch(179); gotoxy(x+l+1,y+1+i); putch(179); }
gotoxy(x,y+w); putch(192); for(j=0;j<2;j++) { for(i=0;i<15;i++) putch(196); putch(193); } for(i=0;i<20;i++) putch(196); putch(193); for(i=0;i<25;i++) putch(196); putch(217); textcolor(WHITE); }
/*--------------------------------显示帮助信息-----------------------------*/ void HELP() { void *buf; int i;
buf=(void *)malloc(2*80*24); gettext(1,1,80,23,buf); puttext(1,1,80,23,buffer);
textcolor(YELLOW); textbackground(BLUE); for(i=0;i<11;i++) { gotoxy(27,7+i); cprintf("%s",Hel[i]); }
while(!kbhit()); textbackground(BLACK);
puttext(1,1,80,23,buf); textcolor(WHITE);
free(buf);
}
[attach]763[/attach][此贴子已经被作者于2004-09-05 16:13:47编辑过]