题目内容
依照规则库设计一个植物专家系统。也可以改成动物专家系统什么的。
用C++做了一个极其简易的程序出来,姑且能满足所有规则库。
结构图
按这个步骤搜索,不然搜不出来。
规则库
代码
十分粗暴且杂乱的源码
#include<iostream>
#include<string>
using namespace std;
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
string trait[]={"种子的胚有两个子叶","种子的胚只有一个子叶","叶脈为网状","叶脉平行","花托为杯形","花托为圆柱形","花瓣有五枚","果实为核果","果实为梨果","果实有毛","果实无毛","果实外有纵沟","果实无石细胞","果实有石细胞","果肉乳黄色","果肉质脆","果肉为白色","果实扁圆形"};
void draw()
{
int size=sizeof(trait)/sizeof(trait[0]);
cout<<"以下是植物的特点:"<<endl;
for(int i=0;i<size;i++)
{
cout<<i+1<<".";
cout<<trait[i]<<"\t";
if((i+1)%4==0)
{
cout<<endl;
}
}
}
void judge()
{
int tap;
cout<<"请输入植物特征"<<endl;
begin:
cin>>tap;
if(tap==1||tap==3) //R1
{
cout<<"它是双子叶植物"<<endl;
cin>>tap;
if(tap==5||tap==6) //R5 R7
{
cout<<"它是蔷薇科植物"<<endl;
qiangwei:
cin>>tap;
if(tap==9) //R9
{
cout<<"它是苹果亚科植物"<<endl;
cin>>tap;
if(tap==13) //R13
{
cout<<"它是苹果"<<endl;
}
else if(tap==14) //R14
{
cout<<"它是梨"<<endl;
}
}
else if(tap==8) //R8
{
cout<<"它是李亚科植物"<<endl;
cin>>tap;
if(tap==10) //R10
{
cout<<"它是桃"<<endl;
return;
}
else if(tap==11) //R11
{
cout<<"它是李"<<endl;
return;
}
else
{
goto error;
}
}
else if(tap==15) //R15
{
cin>>tap;
if(tap==16)
{
cout<<"它是苹果"<<endl;
return;
}
}
else
{
goto error;
}
}
}
else if((tap==2)||(tap==4)) //R2 R4
{
cout<<"它是单子叶植物"<<endl;
return;
}
else if(tap==6||tap==7) //R6
{
cout<<"它是蔷薇科植物"<<endl;
goto qiangwei;
}
else if(tap==17) //R3
{
cout<<"它是梨"<<endl;
}
else if(tap==12) //R12
{
cin>>tap;
if(tap==18)
{
cout<<"它是桃"<<endl;
return;
}
}
else
{
error:
system("cls");
draw();
cout<<endl<<"未找到该植物!请重新查找"<<endl;
goto begin;
}
}
int main()
{
first:
system("cls");
draw();
judge();
cout<<"查询完毕!"<<endl<<"继续查询请按1,退出程序请按2"<<endl;
int t=0;
cin>>t;
switch(t)
{
case 1:
goto first;
case 2:
break;
}
system("pause");
return 0;
}