In: Computer Science
You are to implement a program to play “Guess an Animal.” Your program should construct a tree with a string at each node. This tree stores the knowledge that your program currently knows. At leaf nodes, the strings should contain the names of animals, while interior nodes should contain yes/no questions. The program should start at the root and ask the question stored at the root. If the user answers the question no, the program traverses the left branch of the tree, while if the user answers the question yes, the program traverses the right branch of the tree. Your program will end up at a leaf node, and when it does, it should ask the user if the animal named there is the one he is thinking of. If it isn’t, your program should ask the user for a question that distinguishes the leaf node animal from the animal that the user was thinking of. This question should have a yes answer for his animal, and no for the animal currently at the leaf node. Your program should then store the question at this leaf node, and make the animal at that leaf node the left leaf node for the new question node, and the user’s animal, the animal at the right leaf node.
After finishing a round, your program should ask the user if he wants to play again, and if he does, should repeat the process. If the user says he wants to exit, your program should print out the number of animals that it guessed correctly, and the number of new animals that the program learned. (Optional Extra Credit) It should then write out the tree to a file and exit.
When your program is run, (Optional Extra Credit) it should read a file that contains the tree that was saved, and use this as its original animal knowledge. For the first run, this file will be empty.
Coding in c++