I’m working on an animal game in C++; I want you to complete the codes by following the comments inthe codes.
I will provide you the main code.
Topics we talk about these topics so far to complete this program: classes ( private vs public ) ,
constructors, destructors, new/ delete and heap vs stack data.
And we talk about this in the class can you send an explanation and tutorial links about this example:
node < int > n;
Node < string > n2;
node < node < int >> n3;
I’m working on an animal game in C++; I want you to complete the codes by following the comments in
the codes.
I will provide you the main code.
Topics we talk about these topics so far to complete this program: classes ( private vs public ) ,
constructors, destructors, new/ delete and heap vs stack data.
And we talk about this in the class can you send an explanation and tutorial links about this example:
node < int > n;
Node < string > n2;
node < node < int >> n3;
Here is the code main which I will provide to you:
#include
#include
using namespace std;
class node {
string content;
node *yes;
node *no;
public:
// constructor (because it has the same name as the class)
// (we are causing the default constructor to be eliminated, since we are defining our own)
// (the default constructor has no inputs and doesn’t set any data values)
node(string content) {
this->content = content;
yes = nullptr;
no = nullptr;
}
node(string content, node *yes, node *no) {
this->content = content;
this->yes = yes;
this->no = no;
}
node() {
content = “NO DATA!”;
yes = nullptr;
no = nullptr;
}
node *getYes() {
return yes;
}
void setYes(node *dest) {
yes = dest;
}
node *getNo() {
return no;
}
void setNo(node *dest) {
no = dest;
}
string getContent() {
return content;
}
};
class animaltree {
node *root;
node *current;
public:
// animal should be ‘yes’ answer to the question
animaltree(string first_question, string first_animal) {
root = new node(first_question);
node *animal = new node(first_animal);
root->setYes(animal);
current = root;
}
string getContent() {
return current->getContent();
}
void followYes() {
current = current->getYes();
}
void followNo() {
current = current->getNo();
}
};
int main() {
string q1, a1;
cout