C++实现简单的专家识别系统

C++实现简单的植物识别专家系统

题目内容

依照规则库设计一个植物专家系统。也可以改成动物专家系统什么的。
用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;
}
  • 6
    点赞
  • 49
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值