水电出版社的《C语言程序设计实训》源代码

源代码在线查看: 5-1.c

软件大小: 40 K
上传用户: Lxb500
关键词: 水电 出版社 C语言 程序设计
下载地址: 免注册下载 普通下载 VIP

相关代码

				/*5-1.c*/
				#include
				#include"menu.h"
				#define HADD 185
				#define LADD -95
				#include"ruler.h"
				#include"mouse.h"
				#define G 5;
				 char *filename;
				struct RULER{
				   int number;
				   char result[10];
				   char premise[10];
				   float prob;
				   };
				struct RULER brul[100];
				int rulsum;
				void inform()                                    /*信息显示窗口*/
				{
				int i;
				Box(5,22,630,260);
				ReBox(10,25,620,230);
				for(i=0;i				{Box(30+i*180,260,60,20);
				 }
				 zwsc16(35,262,5,DARKGRAY,"下一页");           /*选择按钮*/
				 zwsc16(215,263,5,DARKGRAY,"上一页");
				setcolor(DARKGRAY);
				for(i=1;i				 {
				   outtextxy(13,33+(i-1)*20,fcode[i-1]);
				   zwsc16(100,28+(i-1)*20,0,DARKGRAY,fstate[i-1]);
				 }
				}
				void view(int i,int ib)                       /*已生成的规则信息的显示*/
				{
				 char mids[6];
				 int j=0;
					setfillstyle(1,WHITE);
					bar(200+LADD,115+HADD,240+LADD,125+HADD);
				   bar(170+LADD,130+HADD,240+LADD,145+HADD);
				   bar(170+LADD,170+HADD,240+LADD,185+HADD);
				   bar(170+LADD,210+HADD,240+LADD,225+HADD);
				   setcolor(DARKGRAY);
				
				   if(i				   {
					  itoa(brul[i].number,mids,10);
				   outtextxy(210+LADD,115+HADD,mids);
				 
					outtextxy(180+LADD,135+HADD,brul[i].premise);
					outtextxy(180+LADD,175+HADD,brul[i].result);
					
					 sprintf(mids,"%1.3f",brul[i].prob);
					outtextxy(180+LADD,215+HADD,mids);
					}
				   else
				   {
				   brul[i].number=i+1;
					  itoa(brul[i].number,mids,10);
				   outtextxy(210+LADD,115+HADD,mids);
				   }
				  Box(235,285,400,170);
				  ReBox(240,290,390,160);
				  zwsc16(245,295,0,DARKGRAY,"如果");
				  zwsc16(245,330,0,DARKGRAY,"那么");
				  zwsc16(245,365,0,DARKGRAY,"可信度");
				 if(strstr(filename,"f"))
				  for(j=0;j				   {
					if(!strcmp(brul[i].premise,fcode[j]))
				  zwsc16(285,295,0,YELLOW,fstate[j]);
						if(!strcmp(brul[i].result,fcode[j]))
				  zwsc16(285,330,0,YELLOW,fstate[j]);
				   }
				  else
				   if(strstr(filename,"r"))
					 for(j=0;j				   {
					if(!strcmp(brul[i].premise,rcode[j]))
				  zwsc16(285,295,0,YELLOW,rstate[j]);
						if(!strcmp(brul[i].result,rcode[j]))
				  zwsc16(285,330,0,YELLOW,rstate[j]);
				   }
					outtextxy(295,370,mids);
				}
				void main()
				{
				 int gd=DETECT,gm;
				  FILE *fp1;
				 int i=0,pionti;
				 int btn,mx,my;
				 int hang=6,hm,sum;
				
				  char mids[6];
				 char ns[6];
				 char *str=" ";
				
				 int ib=0;
				 int k,listi;
				 int pagei=1;
				 system("c:\\ucdos\\ucdos.bat");
				 printf("\n请输入要编辑的知识库名:");
				 scanf("%s",filename);
				initgraph(&gd,&gm,"c:\\bc\\bin\\bgi");
				
				 Box(100+LADD,100+HADD,200,170);
				 zwsc16(150+LADD,110+HADD,10,YELLOW,"规则");
				zwsc16(110+LADD,130+HADD,0,YELLOW,"如果");
				   zwsc16(110+LADD,170+HADD,0,YELLOW,"就");
				   zwsc16(110+LADD,210+HADD,0,YELLOW,"置信度");
				 for(i=0;i				 Box(250+LADD,110+HADD+25*i,40,20);
				
				/*直接写出菜单各项的选项信息*/
				zwsc16(252+LADD,112+HADD,2,DARKGRAY,"删除");
				zwsc16(252+LADD,112+25+HADD,2,DARKGRAY,"重写");
				zwsc16(252+LADD,112+50+HADD,2,DARKGRAY,"下页");
				zwsc16(252+LADD,112+75+HADD,2,DARKGRAY,"上页");
				zwsc16(252+LADD,112+100+HADD,2,DARKGRAY,"添加");
				zwsc16(252+LADD,112+125+HADD,2,DARKGRAY,"退出");
				
				  if((fp1=fopen(filename,"rt"))==NULL)
				 {
				  printf("Can not open file\n");
				  exit(0);
				  }
				
				/*从文件读出规则信息到结构体数组中*/
					while(fscanf(fp1,"%d",&brul[ib].number)!=EOF)
					 {
					 fscanf(fp1,"%s",brul[ib].premise);
					 fscanf(fp1,"%s",brul[ib].result);
					 fscanf(fp1,"%s",mids);
					 brul[ib].prob=atof(mids);
					 ib++;
					 }
				  
				rewind(fp1);
				 i=0;
				 hm=1;
				inform();
					 InitMs();                       /*初始化鼠标*/
				ShowMs();
				view(i,ib);                          /*显示鼠标光标*/
				
				/*进入循环测试鼠标状态循环*/
				 for(;;)
				 {
				  ReadMs(&btn,&mx,&my);
				  if(btn==1&&MsInBox(30,260,90,280,mx,my))  /*选中信息窗口向下翻页*/
				  {
							ReBox(10,25,620,230);
						 setcolor(DARKGRAY);
						 pagei++;
					
					 if(pagei					 for(listi=(1+pagei*10);listi					   {
				   outtextxy(13,33+(listi-1-10*pagei)*20,fcode[listi-1]);
				   zwsc16(100,28+(listi-1-10*pagei)*20,0,DARKGRAY,fstate[listi-1]);
						}
					  else
					  {
					   if(pagei>22)
						  pagei=22;
						 for(listi=(1+(pagei-6)*10);listi					   {
				   outtextxy(13,33+(listi-1-10*(pagei-6))*20,rcode[listi-1]);
				   zwsc16(100,28+(listi-1-10*(pagei-6))*20,0,DARKGRAY,rstate[listi-1]);
						}
					  }
				  }
					if(btn==1&&MsInBox(210,260,270,280,mx,my))   /*选中信息窗口向上翻页*/
					{
							ReBox(10,25,620,230);
							 setcolor(DARKGRAY);
					pagei--;
					if(pagei					 if(pagei0)
					 for(listi=(1+pagei*10);listi					   {
					 outtextxy(13,33+(listi-1-10*pagei)*20,fcode[listi-1]);
					  zwsc16(100,28+(listi-1-10*pagei)*20,0,DARKGRAY,fstate[listi-1]);
						}
					  else
						 for(listi=(1+(pagei-6)*10);listi					   {
				   outtextxy(13,33+(listi-1-10*(pagei-6))*20,rcode[listi-1]);
				   zwsc16(100,28+(listi-1-10*(pagei-6))*20,0,DARKGRAY,rstate[listi-1]);
						}
					}
						if(btn==1&&MsInBox(248+LADD,133-25+HADD,245+46+LADD,133-25+24+HADD,mx,my))
				/*选中规则库操作的删除选项*/
							{
							   pionti=i;
								sum=ib-1;
							   for(k=pionti;k							  {
							   brul[k].prob=brul[k+1].prob;
							   strcpy(brul[k].premise,brul[k+1].premise);
							   strcpy(brul[k].result,brul[k+1].result);
							  }
								brul[k].prob=0;
							   strcpy(brul[k].premise,str);
							   strcpy(brul[k].result,str);
							view(i,ib);
							delay(200);
							}
				if(btn==1&&MsInBox(248+LADD,133-25+(2-1)*25+HADD,245+46+LADD,133-25+24+HADD+(2-1)*25,mx,my))         /*选中规则库操作的重写选项*/
				
				   {
				   setfillstyle(1,WHITE);
				   bar(170+LADD,130+HADD,240+LADD,145+HADD);
				   bar(170+LADD,170+HADD,240+LADD,185+HADD);
				   bar(170+LADD,210+HADD,240+LADD,225+HADD);
				   getstr(180+LADD,135+HADD,brul[i].premise);
					getstr(180+LADD,175+HADD,brul[i].result);
					getstr(180+LADD,215+HADD,mids);
				   brul[i].prob=atof(mids);
							
								 if(i>=ib)
									ib++;
									view(i,ib);
									 delay(200);
						 }
				if(btn==1&&MsInBox(248+LADD,133-25+(3-1)*25+HADD,245+46+LADD,133-25+24+HADD+(3-1)*25,mx,my))                     /*选中规则库操作的下页选项*/
				
								 {
								 i++;
								 view(i,ib);
								 delay(200);
								 }
				if(btn==1&&MsInBox(248+LADD,133-25+(4-1)*25+HADD,245+46+LADD,133-25+24+HADD+(4-1)*25,mx,my))                      /*选中规则库操作的上页选项*/
				
								{
								 i--;
							   if(i							   i=0;
							   view(i,ib);
								delay(200);
								 }
				if(btn==1&&MsInBox(248+LADD,133-25+(5-1)*25+HADD,245+46+LADD,133-25+24+HADD+(5-1)*25,mx,my))                      /*选中规则库操作的添加选项*/
				
								  {
								  i=ib;
								  view(i,ib);
								  delay(200);
							
								  }
				 if(btn==1&&MsInBox(248+LADD,133-25+(6-1)*25+HADD,245+46+LADD,133-25+24+HADD+(6-1)*25,mx,my))                     /*选中规则库操作的退出选项*/
				
								   {
									closegraph();
									  fclose(fp1);
					if((fp1=fopen(filename,"wt"))==NULL)
				 {
				  printf("Can not open file\n");
				  exit(0);
				  }
					  for(i=0;i					  {
					  if(brul[i].prob!=0)
					  fprintf(fp1,"%d %s %s %1.3f\n",brul[i].number,brul[i].premise,
					  brul[i].result,brul[i].prob);
					  }
					  fclose(fp1);
					 system("c:\\ucdos\\quit.com");
					 exit(0);
								   }
				 }
				}
							

相关资源