Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this project, you will implement a 20 questions game as described in class. Your program will read a data file to build the 20

For this project, you will implement a 20 questions game as described in class. Your program will read a data file to build the 20 questions binary tree, play one or more games, each of which might grow the tree to include more names and phrases, and, after the user decides not to play another game, write the tree to the same data file it initially read from to remember what it has learned. The next time the game is played with that data file, then, it will still remember all the names it has seen in the past. This program will give you experience with binary trees, binary search, recursion (both for writing the tree to the data file and for building the tree from the data file), and, last but not least, dealing with pointers (references). The actual amount of code youll write is not huge, but there are some conceptual hurdles youll have to clear. Your application architecture should have a BinTree class to implement the binary tree, a Node class to implement a node in a binary tree, and a Play20Q class to play a single game. Well talk about the design of these classes in class, and Ill drop some hints. To enforce this architecture, Im giving you the Main() method you should use for your final version, which calls stuff in the BinTree and Play20Q classes. Youll need to implement those classes to fit the interface implied by these calls. That code is in MainClass.txt. The format for the data file is important to understand, since your program will have to write it and read it correctly. Each line of the data file will contain the information for a single node in the tree. The first character of each line will be either I or L where I stands for an Interior node (a node with children) and L stands for a Leaf node (a node with no children). The rest of each line is the string that should be stored in the node, which can include blanks. You should implement this as a text file so that you can look at its contents easily with your favorite text editor. You may assume a few things that will make the program easier to write. First, you dont have to actually get to 20 questions or even count the number of questions (we dont want to work with trees that are anywhere near that big). Second, the data file will be correct, that is, it has been created by a correct WriteTree() method (one of the methods youll implement in your BinTree class). Third, the data file will have at least one interior node and two leaf nodes. Specifically, the following is a legal data file: Bliving LBill Gates LChester Carlson Assume that this file is read to build the BinTree object and that the following conversation occurs while running the program: Welcome to 20 questions! I'll try to guess your person. Is this person living? y Is it Bill Gates? y Hurray! I win! How about another game? y Is this person living? n Is it Chester Carlson? y Hurray! I win! How about another game? y

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Database Modeling With Neo4j

Authors: Ajit Singh

2nd Edition

B0BDWT2XLR, 979-8351798783

More Books

Students also viewed these Databases questions

Question

How does the concept of hegemony relate to culture?

Answered: 1 week ago