Question

In: Computer Science

You are to implement a program to play “Guess an Animal.”  Your program should construct a tree...

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++

Solutions

Expert Solution

This answer for your code will be suitable one


Related Solutions

C++ tree program (do NOT use STRUCT, use classes)    Program 1 Implement a Binary tree...
C++ tree program (do NOT use STRUCT, use classes)    Program 1 Implement a Binary tree using an array    Program 2 Implement a tree using linked list - pointer Binary Tree    Program 3 - Convert program 1 to a template
Write a program with at least 2 functions that play the game of “guess the number”...
Write a program with at least 2 functions that play the game of “guess the number” as follows: Your program chooses the number to be guessed by selecting an integer at random in the range 1 to 1000. The program then displays the following: I have a number between 1 and 1000. Can you guess my number? Please type in your first guess. The player then types the first guess. The program then responds with one of the following: 1.      ...
Write a Java program that lets the user play a game where they must guess a...
Write a Java program that lets the user play a game where they must guess a number between zero and one hundred (0-100). The program should generate a random number between 0 and 100 and then the user will try to guess the number. The program should help the user guess the number (see details below). The program must allow the user five attempts to guess the number. Further Instruction: (a) Declare a variable diff and assign to it the...
Write a program in C++ to implement Lamport’s logical clocks. Your program should take as input...
Write a program in C++ to implement Lamport’s logical clocks. Your program should take as input a description of several process schedules (i.e., lists of send, receive or print operations). The output of your program will be a linearization of these events in the order actually performed, annotated with Lamport clock values. The input of the program will be a collection of processes, each with a list of operations to perform. The processes are named p1...pn for some n (you...
C++(screenshot output please) Part 2 - Tree programs Program 1 Implement a tree using an array...
C++(screenshot output please) Part 2 - Tree programs Program 1 Implement a tree using an array Program 2 Implement a tree using linked list - pointer Binary Tree Program 3 - Convert program 1 to a template
MATLAB Program a Matlab version of Guess the Word. The word should be determined by user...
MATLAB Program a Matlab version of Guess the Word. The word should be determined by user input. Once the word is determined, the game should begin by displaying blanks (-) where all the letters of the word are. The game should then continue to prompt the player to guess a letter in the word. If the player guesses a letter that is in the word and not already displayed, that letter should be displayed everywhere it appears in the word....
Java program that uses binary tree and recursions to implement Tower of Hanoi game where there...
Java program that uses binary tree and recursions to implement Tower of Hanoi game where there can be any amount of disks and there are either 3,4, or 5 pegs to store the disks(# of pegs and disks is manually inputted by user), in Tower of Hanoi game, the object of the game is move all the pieces from the 1st peg to the right most peg or the opposite side. You can place disks on top of each other...
C++ tree program (please do NOT use struct Node, use classes) Program 1 Implement a Binary...
C++ tree program (please do NOT use struct Node, use classes) Program 1 Implement a Binary tree using an array Program 2 Implement a tree using linked list - pointer Binary Tree Program 3 - Convert program 1 to a template (include screenshots please of output)
C++ tree program (please do NOT use struct Node, use classes) Program 1 Implement a Binary...
C++ tree program (please do NOT use struct Node, use classes) Program 1 Implement a Binary tree using an array Program 2 Implement a tree using linked list - pointer Binary Tree Program 3 - Convert program 1 to a template
It is time to play X-O. You should complete the program for this game. Part of...
It is time to play X-O. You should complete the program for this game. Part of this program is provided to you in two files: d4q2.py (it is complete, no need to be modified) and d4q2Lib.py (you have to complete). The annex has examples of messages displayed during the game. 1) The main program controls the game. a. It asks the user to start a game : if the response is not o or O, the program ends; If the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT