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

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.      ...
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 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...
Implement a recursive program to draw a binary tree so that the root appears at the...
Implement a recursive program to draw a binary tree so that the root appears at the center of the page, the root of the left subtree is at the center of the left half of the page, etc. Alternative formulation: implement a recursive preorder binary tree traversal so that, when each node is displayed on the page, if the node is a left child it is shown to the left of the node displayed above it, and if it is...
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....
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
You should implement a syntax checking program that is similar to a function of compiler. Compliers...
You should implement a syntax checking program that is similar to a function of compiler. Compliers check programs for syntax errors, but frequently a lack of one symbol (such as a missing brace or com-ment starter) will cause the complier to spill out a hundred lines of diagnostics without identifying the real error. A useful tool in this situation is a program that checks whether everything is balanced. Thus, every right brace, bracket, and parenthesis must correspond to its left...
In this Java program you will implement your own doubly linked lists. Implement the following operations...
In this Java program you will implement your own doubly linked lists. Implement the following operations that Java7 LinkedLists have. 1. public DList() This creates the empty list 2. public void addFirst(String element) adds the element to the front of the list 3. public void addLast(String element) adds the element to the end of the list 4. public String getFirst() 5. public String getLast() 6. public String removeLast() removes & returns the last element of the list. 7. public String...
Write and test a C program to implement Bubble Sort. . In your C program, you...
Write and test a C program to implement Bubble Sort. . In your C program, you should do: Implement the array use an integer pointer, get the size of the array from standard input and use the malloc function to allocate the required memory for it. Read the array elements from standard input. Print out the sorted array, and don’t forget to free the memory. Debug your program using Eclipse C/C++ CDT.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT