用c++代码做一个动物识别专家系统
时间: 2024-01-29 14:03:20 浏览: 40
好的,以下是一个简单的动物识别专家系统的C++代码示例:
```c++
#include <iostream>
#include <string>
using namespace std;
int main() {
string answer1, answer2, answer3;
cout << "Welcome to the Animal Identification Expert System!" << endl;
cout << "Please answer the following questions with 'yes' or 'no'." << endl;
cout << "Does the animal live in water?" << endl;
cin >> answer1;
if (answer1 == "yes") {
cout << "Does the animal have fins?" << endl;
cin >> answer2;
if (answer2 == "yes") {
cout << "The animal is a fish." << endl;
}
else {
cout << "The animal is a whale." << endl;
}
}
else {
cout << "Does the animal have four legs?" << endl;
cin >> answer2;
if (answer2 == "yes") {
cout << "Does the animal have fur?" << endl;
cin >> answer3;
if (answer3 == "yes") {
cout << "The animal is a dog." << endl;
}
else {
cout << "The animal is a crocodile." << endl;
}
}
else {
cout << "The animal is a snake." << endl;
}
}
return 0;
}
```
这个程序基于一系列简单的问题来识别动物种类。用户需要回答每个问题,然后程序会根据答案给出动物的种类。这只是一个简单的示例,实际上,一个更复杂的专家系统需要更多的问题和更复杂的判断逻辑。