Due 11:59pm on Monday 7 April 2008.
You must submit two files, using the electronic submission system
.
The first file should be called Guess.cpp, and should complete the code you need to solve the problem described below at Task 1. The second file should be called QuestionNode.h and should complete the code you need to solve the problem described below at Task 2.
The formats you should use for your files are specified below.
If you do not use the filenames stated above, or you do not use the file format specified below, then you will receive 0 (zero) marks.
Submit your work by the due date and time stated above.
To understand how the format relates to a game tree, try playing the game –without adding nodes– while you have the file animalData in front of you, and see whether you can “follow” the the program through the file in the file as you respond to the questions the program asks. Answering the starred tutorial exercises will also help you to understand this format.
Your first task is to complete the function Play in Guess.cpp so that your program plays the game in the same way that the given executable GuessGame does.
To help your understanding of the QuestionNode data structure, complete the starred Tutorial and Practical exercises in Weeks 3 and 4. Then interpret the following pseudocode to complete this task. (UPPER-CASE portions are for you to fill in.)
Remember to compile your code, have all the files QuestionNode.h, Animal.h and Guess.cpp
in the same folder and use g++ Guess.cpp.
We use tags T: to denote a text node, and N: to denote NULL. The depth within the game tree is denoted by the indentation so that a node appears at depth d just when its tag is preceded on the line by d-1 spaces. Thus at depth 1 (no spaces) there are three nodes (one for animal, one for vegetable and one for mineral).
All other nodes either have two children, or no children, or are NULL, and they are all at depth greater than 1. After a T: there is text which is either a question (for a question node) or a guess (for a guess node). Its left branch (for "yes") appears on the next line(s) below, indented by one more space, followed by its representation of the subtree.
To check that your code is producing the correct result, copy the game whose log of interactive responses are
saved in the
file gameRun. Start from scratch (i.e. without a file animalData), and when you've played that game save it to file.
Your program's output should be exactly the same as in the file animalData1.
Overview
A database is an arrangement of stored data which is set up so that the data can be queried easily. Almost every “information system” has inside it some kind of database. In some applications the database is not static, but rather must change dynamically whenever its content needs to be updated. A typical scenario could be to store data in an automated enquiry service, which is becoming typical of today’s telephone-enquiry services. The data base would store a selection of questions having “yes/no” answers in order to identify the category of the enquiry, with the system then giving the user some useful information most related to the identified category. The most advanced enquiry services allow the system actually to update itself in the case it “learns” a new category.
In Assignment 1 and Assignment 2 you will be practise the basics of how to program a database system which can learn new categories and update itself automatically.
This Assignment
In this assignment you will be asked to program a pointer-based tree implementation of a simple “Animal/Vegetable/Mineral” game. You have been provided with a number of program and specification files, and one executable. The executable called Guess will run on titanic and gives you an idea of what your programs should do when they are correctly implemented, compiled and executed. The other files are as follows:
To play the game using the executable GuessGame, download it and the file animalData
and make sure that they are in the same directory. Then type the command ./GuessGame.
You can add more data as you play the game, and save it at the end of the game.
Task 1 (10 marks)
void Play(QuestionNode *&qN) { // Must be reference to allow a new node possibly to be grafted on in this call.
if (THE CURRENT NODE qN IS A GUESS NODE) { // OTHERWISE IT'S A QUESTION
GUESS THE ANSWER;
if (THE PROGRAM GUESSED CORRECTLY) then PRINT "GREAT! LET'S PLAY AGAIN";
else { // THE PROGRAM GUESSED INCORRECTLY
ASK THE USER FOR THE ANSWER, VIA STANDARD OUTPUT/INPUT;
ASK THE USER FOR A QUESTION THAT WILL DISTINGUISH
THE ANSWER FROM THE GUESS;
MAKE A NEW NODE CONTAINING THAT QUESTION, FOR WHICH A "YES"
LEADS TO THE ACTUAL ANSWER, AND "NO" TO THE GUESS;
INSERT THAT NEW NODE AT THE CORRECT POINT IN THE TREE;
// (HINT: DO THE STARRED TUTORIAL EXERCISES FOR HELP WITH THIS)
}
}
else { // THE CURRENT NODE IS A QUESTION
ASK THE QUESTION; GET THE ANSWER; CONTINUE TO PLAY IN THE CORRECT SUB-TREE;
}
}
You will have correctly implemented this function if it does exactly the same as the game GuessGame. However you will
be marked separately for implementing (a) playing the game without additions, and (b) for correctly adding a new node.
Task 2 (5 marks)
The second task is to complete the Save function in QuestionNode.h which takes a game tree and saves it as a serial file, according to the following format:
The files
Animal class (fully implemented): Animal.h
QuestionNode class (partially implemented): QuestionNode.h
The game program (partially implemented): Guess.cpp
An example saved game: animalData
Another example saved game, which saves the game played out in gameRun: animalData1
An example log of an interactive session: gameRun
The executable: GuessGame
You may have your program “trialed” by the electronic marker before the due date. Trials will begin from 31 March onwards. Any files submitted after that time and before the deadline will be presented to the electronic marker every alternate day until the submission date.
The results of the trial runs will be emailed to you at your student account. These trial results will be completely disregarded for marking, so do not worry that mistakes in the trials will count against you: they will not. The feedback is to help you correct errors that may be lurking in your programs, and to make sure that your code is efficient enough.
You will receive the actual results for the electronically marked part of Assignment 1 after the final deadline for submission.
There are a number of common mistakes that students make which prevent them receiving full marks, even if they think they have thoroughly tested their programs!
This policy is for two reasons. Firstly (and obviously) we cannot run assignments on your home computers, and so we cannot check whether they work there. (We can’t even check if you bring in your laptop, because we can’t be sure what’s installed on it.)
The second, and more important reason, is that when you have graduated and are writing programs for clients, they will of course insist that your product run on their machines. If you say to them “Well, it ran on my own installation back at the office.” then you won’t be in business for long.
Remember that there will be several opportunities to check that your programs survive the electronic marker before the final submission date.
In spite of all these warnings, sometimes
programs are submitted that, astonishingly, don’t even compile
with our departmental electronic marker. This means that their authors
not only ignored all the warnings above, but they did not even
once use the trial-marking system. Try not to be one of those
people.