In C++ Create a yes/no expert system using a tree structure. The questions have
ID: 655653 • Letter: I
Question
In C++ Create a yes/no expert system using a tree structure. The questions have to be based on if you were asking someone questions on Computer Assistance topics. I.E. Is it on? Are you connected to the internet? Etc. This is the code that I have so far:
class treenode{
public:
basedata value;
string qa;
treenode *lchild, *rchild;
template
void bttree::inserttree(treenode *&p, basedata d, string qas){
if(p ==NULL){
p = new treenode;
p->value = d;
p->qa = qas;
p->lchild = NULL;
p->rchild = NULL;
}else{
if(p->value > d)
inserttree(p->lchild,d,qas);
else
inserttree(p->rchild,d,qas);
}
};
template
void bttree::insertdata(basedata x, string a){
inserttree(root,x,a);
};
template
void bttree::yesno(void){
current = root;
bool solved = false;
char c;
cout<qa<
while(!solved){
cout<<"Enter a Y or N";
cin>> c;
if(c == 'Y' ||c == 'N'){
if(c == 'Y'){
current = current->lchild;
}
if(c == 'N'){
current = current->rchild;
}
cout<qa<
if(current->lchild == NULL){
solved = true;
cout<<"You have your answer "<
}
}
}
};
bttree mytree;
string QandA[7];
int Tpos[7];
QandA[0] = "First questions?";
QandA[1] = "Second questions?";
QandA[2] = "Third questions?";
QandA[3] = "First answer.";
QandA[4] = "First answer.";
QandA[5] = "First answer.";
QandA[6] = "First answer";
Tpos[0] = 50;
Tpos[1] = 40;
Tpos[2] = 60;
Tpos[3] = 20;
Tpos[4] = 45;
Tpos[5] = 70;
Tpos[6] = 55;
for(int i = 0; i<=6; i++){
mytree.insertdata(Tpos[i],QandA[i]);
}
mytree.yesno();
cout<
return 0;
}
Explanation / Answer
As in above question all the code for various stapes are being give in question nly you need to add yes no type questior