📄 c动物识别.txt
字号:
//#ifndef ANIMAL_H
//#define ANIMAL_H
//#endif
#define True 1
#define False 0
#define DontKnow -1
#include<stdio.h>
#include<math.h>
#include<string.h>
//事实集(概念集)
char *str[]={"",
"chew_cud" /* 1 反刍*/, "hooves" /* 2 有蹄*/, "mammal" /* 3 哺乳类*/,
"forward_eyes"/* 4 眼前*/, "claws" /* 5 有爪*/, "pointed_teeth" /* 6 犬齿*/,
"eat_meat" /* 7 吃肉*/, "lay_eggs " /* 8 下蛋*/, "fly" /* 9 能飞*/,
"feathers" /* 10 羽毛*/, "ungulate" /* 11 有蹄类 */, "carnivore" /* 12 食肉类*/,
"bird" /* 13 鸟类*/, "give_milk" /* 14 有奶*/, "has_hair" /* 15 毛发*/,
"fly_well" /* 16 善飞*/, "black&while_color"/* 17 黑色白条纹*/,"can_swim" /* 18 游泳*/,
"long_legs" /* 19 长腿*/, "long_neck" /* 20 长脖子*/, "black_stripes" /* 21 黑条纹*/,
"dark_spots" /* 22 暗斑点*/, "tawny_color" /* 23 黄褐色*/, "albatross" /* 24 信天翁*/,
"penguin" /* 25 企鹅*/, "ostrich" /* 26 鸵鸟*/, "zebra" /* 27 斑马*/,
"giraffe" /* 28 长颈鹿*/, "tiger" /* 29 老虎*/, "cheetah" /* 30 印度豹*/,
"\0"
};
//规则之前件(条件)集,注意与下面对应
int rulep[][6]={
{22,23,12,3,0,0}, /*豹子 30*/ {21,23,12,3,0,0}, /*老虎 29*/ {22,19,20,11,0,0}, /*长颈鹿 28*/
{21,11,0,0,0,0}, /*斑马 27*/ {17,19,20,13,-9,0}, /*鸵鸟 26*/ {17,18,13,-9,0,0}, /*企鹅 25*/
{16,13,0,0,0,0}, /*信天翁 24*/ {15,0,0,0,0,0}, /*哺乳类 3*/ {14,0,0,0,0,0}, /*哺乳类 3*/
{10,0,0,0,0,0}, /*鸟类 13*/ {8,9,0,0,0,0}, /*鸟类 13*/ {7,0,0,0,0,0}, /*食肉类 12*/
{4,5,6,0,0,0}, /*食肉类 12*/ {2,3,0,0,0,0}, /*有蹄类 11*/ {1,3,0,0,0,0} /*有蹄类 11*/
};
//规则之后件(结论)集,注意与上面对应
int rulec[]={
30, 29, 28,
27, 26, 25,
24, 3, 3,
13, 13, 12,
12, 11, 11
}; //前7个是要识别的动物
//事实类
class fact{
private:
int Number; //事实ID
char Name[21]; //事实名
int Active; //激活标志
int Succ; //事实断言:真、假、不知道三种情况值
public:
fact *Next; //事实链表后继指针
/* <Function 事实类构造函数,由它激活事实对象集 />
<para> Num:事实ID </para>
<para> L:事实名 </para>
*/
fact(int Num,char *L) {
strcpy(Name,L); //保存名字
Number=Num; //事实ID
Active=False; //初始不激活
Succ=DontKnow; //初始断言不确定
Next=NULL; //初始后继为空
}
char *GetName() //获取事实名
{
char *L;
L=new char[21];
strcpy(L,Name);
return L;
}
int GetNumber(){return Number;} //获取事实ID
int GetAct(){return Active; } //获取事实激活标志
int GetSucc(){return Succ;} //获取事实断言值
//设置事实激活标志和断言值
void PutAct(const int Act0,int Suc0)
{
Active=Act0;
Succ=Suc0;
}
}; //end fact
fact *Fact; //事实链表
class list{ //前提(前提来源与事实集)链表类
private:
int Number; //前提ID,即事实ID
public:
list *Next; //前提链表后继指针
/*<Function 前提链表类构造函数 />
<para> Num:事实ID </para>
*/
list(int Num){
Number=Num;
Next=NULL;
}
int GetNumber(){return Number;} //获取前提ID(也就是事实ID)
}; //end list
//规则类
class rule{
char *Name; //规则名
list *Pre; //规则前件(前提、条件)链表头指针
int Conc; //规则后件(结论)ID(也是事实ID)
public:
rule *Next; //规则链表后继指针
rule(char *N,int P[],int C); //规则类构造函数
~rule(); //析构函数
int Query(); //推理机函数
void GetName(){ printf("%s%",Name);}//输出规则名
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -