| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1018 人关注过本帖
标题:请大家空闲的时候看一看这个程序
只看楼主 加入收藏
wangzhenyu
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-5-31
收藏
 问题点数:0 回复次数:1 
请大家空闲的时候看一看这个程序

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
#include <math.h>
#include <string.h>
/* 事实链表的结构描述 */
struct CAUSE_TYPE{
char* cause; /* 事实字符串指针 */
struct CAUSE_TYPE* next; /* 指向下一个节点 */
};
/* 规则链表的结构描述 */
struct RULE_TYPE{
char* result; /* 结论字符串指针 */
int lastflag; /* 结论规则标志 */
struct CAUSE_TYPE* cause_chain; /* 事实链表指针 */
struct RULE_TYPE* next; /* 指向下一个节点 */
};
/* ===================== */
struct CAUSE_TYPE* DataBase; /* 已知事实链表的头指针 */
struct CAUSE_TYPE* Conclusion; /* 结论链表的头指针 */
struct RULE_TYPE* KnowledgeBase; /* 知识库规则链表的头指针 */
struct RULE_TYPE* Used; /* 已使用规则链表的头指针 */
/* ====================== */
void freeKB(struct RULE_TYPE* ); /* 释放规则链表子程序 */
void freeDB(struct CAUSE_TYPE* ); /* 释放事实链表子程序 */
int FindCause(char* ); /* 查证事实是否已知子程序 */
void markKB( ); /* 标记结论性规则子程序 */
void creatKB( ); /* 创建知识库的子程序 */
void inputDB( ); /* 输入已知事实的子程序 */
void think( ); /* 推理机子程序 */
void explain( ); /* 解释子程序 */

long FAR PASCAL _WndFun(HWND hWnd,UINT mes, WPARAM wParam,LPARAM lParam);
HANDLE hCurInst;
int PASCAL WinMain( HANDLE hInst,
HANDLE hPreInst,
LPSTR lpCmd,
int nStyle)
{ char Name[ ] = "动物识别专家系统";
HWND hWnd;
MSG msg;
WNDCLASS wc;
hCurInst=hInst;
if(! hPreInst)
{
wc.lpszClassName = Name ;
wc.hInstance = hInst ;
wc.lpfnWndProc = _WndFun ;
wc.hCursor = LoadCursor( 0, IDC_ARROW) ;
wc.hIcon = LoadIcon( 0, IDI_APPLICATION) ;
wc.lpszMenuName = 0 ;
wc.hbrBackground = GetStockObject( WHITE_BRUSH) ;
wc.style = CS_HREDRAW|CS_VREDRAW ;
wc.cbClsExtra = 0 ;
wc.cbWndExtra = 0 ;
if (!RegisterClass(&wc))
return FALSE;
}
hWnd=CreateWindow( Name,
Name,
WS_OVERLAPPEDWINDOW,
180,
120,
220,
250,
0,
0,
hInst,
NULL);
ShowWindow( hWnd,nStyle);
UpdateWindow(hWnd);
while( GetMessage(&msg, 0, 0, 0))
{
TranslateMessage( &msg);
DispatchMessage( &msg);
}
return msg.wParam;
}
long FAR PASCAL _Wndfun(HWND hWnd,UINT mes, WPARAM wParam,LPARAM lParam)
{static HWND hcre,hin,hth,hex,hqu;
RECT w;
for(;;)
{
switch(mes)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_COMMAND:
{
if(LOWORD(lParam)==hcre) creatKB( );
if(LOWORD(lParam)==hin) inputDB( );
if(LOWORD(lParam)==hth) think( );
if(LOWORD(lParam)==hex) explain( );
if(LOWORD(lParam)==hqu)
{
freeKB(KnowledgeBase);
freeKB(Used);
freeDB(DataBase);
freeDB(Conclusion);
DestroyWindow(hWnd);
PostQuitMessage(0);
}
return(0);
}
case WM_CREATE:
GetClientRect(hWnd,&w);
hcre=CreateWindow("BUTTON",
"创建知识库",
WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
40,
30,
100,
25,
hWnd,
0,
hCurInst,
0);
hin=CreateWindow("BUTTON",
"输入已知事实",
WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
40,
60,
100,
25,
hWnd,
1,
hCurInst,
0);
hth=CreateWindow("BUTTON","进行推理",WS_CHILD|
WS_VISIBLE|BS_PUSHBUTTON,40,90,100,25,hWnd,2,hCurInst,0);
hex=CreateWindow("BUTTON","解释",WS_CHILD|
WS_VISIBLE|BS_PUSHBUTTON,40,120,100,25,hWnd,3,hCurInst,0);
hqu=CreateWindow("BUTTON","退出",WS_CHILD|
WS_VISIBLE|BS_PUSHBUTTON,40,150,100,25,hWnd,4,hCurInst,0);
return 0;
default:
return DefWindowProc(hWnd,mes,wParam,lParam);
}
}
}
/* 释放条件链表 */
void freeDB(struct CAUSE_TYPE* cPoint)
{
struct CAUSE_TYPE* cp;
while(cPoint)
{
cp=cPoint->next;
free(cPoint->cause);
cPoint->cause=NULL;
cPoint->next=NULL;
free(cPoint);
cPoint=cp;
}
}
/* 释放规则链表 */
void freeKB(struct RULE_TYPE* rPoint)
{
struct RULE_TYPE* rp;
while(rPoint)
{
rp=rPoint->next;
freeDB(rPoint->cause_chain);
rPoint->cause_chain=NULL;
free(rPoint->result);
rPoint->result=NULL;
rPoint->next=NULL;
free(rPoint);
rPoint=rp;
}
}
/* 整理输入的规则,找出结论性的规则并打上标记 */
void markKB()
{
struct RULE_TYPE* rp1,* rp2;
struct CAUSE_TYPE* cp;
rp1=KnowledgeBase;
while(rp1)
{
cp=rp1->cause_chain;
rp1->lastflag=1;
while(cp)
{
rp2=KnowledgeBase;
while(rp2)
{
/* 若该规则结论是某规则的条件,则将该规则置为非结论规则 */
if(strcmp(rp2->result,cp->cause)==0)
rp2->lastflag=0;
rp2=rp2->next;
}
cp=cp->next;
}
rp1=rp1->next;
}
}
/* 创建知识库 */
void creatKB()
{
FILE* fp;
struct CAUSE_TYPE* cp=NULL;
struct RULE_TYPE* rp=NULL;
int i,j;
char sp[80];
char ch;
/* 释放知识库规则链表及已使用规则链表 */
freeKB(KnowledgeBase);
freeKB(Used);
KnowledgeBase=Used=NULL;
if((fp=fopen(".\\rule.dat","r"))==NULL)
{
printf("\n 知识库不存在! \n");
printf(" 请输入新的规则,以创建知识库! \n");
/* 输入新知识库的规则 */
for(i=1;;i++)
{
printf("\n * * * * * * * * 第(%d)条规则 * * * * * * * * ", i);
printf("\n * * 结论:(是/会/有)");
/* 输入规则的结论部分 */
gets(sp);
if(*sp=='\0') break;
rp=(struct RULE_TYPE*)malloc(sizeof(rp));
rp->result=(char*)malloc(sizeof(sp));
strcpy(rp->result,sp);
rp->cause_chain=NULL;
rp->next=KnowledgeBase;
KnowledgeBase=rp;
/*输入规则的条件部分 */
for(j=1;;j++)
{
printf("\n * * * 条件(%d):(是/会/有)",j);
/* 输入第J个事实 */
gets(sp);
if(*sp=='\0') break;
cp=(struct CAUSE_TYPE*)malloc(sizeof(cp));
cp->cause=(char*)malloc(sizeof(sp));
strcpy(cp->cause,sp);
cp->next=rp->cause_chain;
rp->cause_chain=cp;
}
}
if(!KnowledgeBase)
{
printf("\n 警告! 知识库中没有任何规则!! \n");
return;
}
printf("\n 需要保存已建立的知识库吗? (Y/N)?");
while(!strchr("YyNn",ch=getchar( )));
if(ch=='Y'|ch=='y')
if((fp=fopen(".\\rule.dat","w"))==NULL)
{
printf("\n 写文件有错误! \n");
exit(1);
}
else {
/* 保存已建立的知识库 */
rp=KnowledgeBase;
while(rp)
{
fputs(rp->result,fp);
fputc('\n',fp); /* "\n"为结论或事实的终结符 */
cp=rp->cause_chain;
while(cp)
{
fputs(cp->cause,fp);
fputc('\n',fp);
cp=cp->next;
}
fputs("\\\n",fp); /* "\ \ \ n"为一条规则的终结符 */
rp=rp->next;
}
fclose(fp);
}
}
else{
/* 若知识库文件存在,则读入所有的规则,建立知识库 */
while(!feof(fp))
{
fgets(sp,80,fp);
if(*sp=='\\') break;
rp=(struct RULE_TYPE*)malloc(sizeof(rp));
rp->result=(char*)malloc(i=strlen(sp));
sp[i-1]='\0';
strcpy(rp->result,sp);
rp->cause_chain=NULL;
rp->next=KnowledgeBase;
KnowledgeBase=rp;
fgets(sp,80,fp);
while(*sp!='\\')
{
cp=(struct CAUSE_TYPE*)malloc(sizeof(cp));
cp->cause=(char*)malloc(i=strlen(sp));
sp[i-1]='\0';
strcpy(cp->cause,sp);
cp->next=rp->cause_chain;
rp->cause_chain=cp;
fgets(sp,80,fp);
}
}
fclose(fp);
}
/* 给知识库中的所有结论规则打上标记 */
markKB();
}
/* 输入已知条件的子程序 */
void inputDB()
{
int i;
char sp[80];
struct CAUSE_TYPE* cp;
/* 释放条件链表和推出结论链表 */
freeDB(DataBase);
freeDB(Conclusion);
DataBase=Conclusion=NULL;
printf("\n * * * * * 请输入已知事实: \n");
for(i=1;;i++)
{
printf("\n * * 条件(%d):(是/会/有)",i);
gets(sp);
if(*sp=='\0') break;
cp=(struct CAUSE_TYPE*)malloc(sizeof(cp));
cp->cause=(char*)malloc(sizeof(sp));
strcpy(cp->cause,sp);
cp->next=DataBase;
DataBase=cp;
}
}
/* 在条件链表及结论链表中查证字符串sp是否存在
若存在返回!,否则返回0 */
int FindCause(char *sp)
{
struct CAUSE_TYPE* cp2;
/* 在条件链表中查找 */
cp2=DataBase;
while(cp2)
if(strcmp(sp,cp2->cause)==0) return(1);
else cp2=cp2->next;
/* 在结论链表中查找 */
cp2=Conclusion;
while(cp2)
if(strcmp(sp,cp2->cause)==0) return(1);
else cp2=cp2->next;
return(0);
}
/* 推理机子程序 */
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Program Files\Microsoft Visual Studio\MyProjects\动物2\动物.cpp(40) : error C2731: 'WinMain' : function cannot be overloaded
C:\Program Files\Microsoft Visual Studio\MyProjects\动物2\动物.cpp(36) : see declaration of 'WinMain'
C:\Program Files\Microsoft Visual Studio\MyProjects\动物2\动物.cpp(53) : error C2440: '=' : cannot convert from 'void *' to 'struct HBRUSH__ *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
C:\Program Files\Microsoft Visual Studio\MyProjects\动物2\动物.cpp(70) : error C2664: 'CreateWindowExA' : cannot convert parameter 11 from 'void *' to 'struct HINSTANCE__ *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
C:\Program Files\Microsoft Visual Studio\MyProjects\动物2\动物.cpp(92) : error C2040: '==' : 'int' differs in levels of indirection from 'struct HWND__ *'
C:\Program Files\Microsoft Visual Studio\MyProjects\动物2\动物.cpp(93) : error C2446: '==' : no conversion from 'struct HWND__ *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\Program Files\Microsoft Visual Studio\MyProjects\动物2\动物.cpp(93) : error C2040: '==' : 'int' differs in levels of indirection from 'struct HWND__ *'
C:\Program Files\Microsoft Visual Studio\MyProjects\动物2\动物.cpp(134) : error C2664: 'CreateWindowExA' : cannot convert parameter 10 from 'const int' to 'struct HMENU__ *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
C:\Program Files\Microsoft Visual Studio\MyProjects\动物2\动物.cpp(250) : warning C4554: '|' : check operator precedence for possible error; use parentheses to clarify precedence
执行 cl.exe 时出错.

动物.obj - 1 error(s), 0 warning(s)

请问我这个程序如何改啊~~~~~~~~~~~

搜索更多相关主题的帖子: include windows struct TYPE 
2006-05-31 18:01
cz522321
Rank: 1
等 级:禁止访问
威 望:2
帖 子:569
专家分:5
注 册:2006-3-13
收藏
得分:0 
我的头都看晕了,呵呵,有点儿难

2006-06-03 12:52
快速回复:请大家空闲的时候看一看这个程序
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016494 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved