Re: Assignment in C++
<g_sharad@yahoo.com> wrote:
Hi Everyone I have a object oriented C++ assignment which is due this
week and I have no idea as to how start it.................
<snip>
Start by defining a struct to hold the needed data. Start *that*by making a
list of nouns from the sample, there are about 11 of them Then list the
actions, there are about six of them.
There are a huge number of ways to represent this.Each entity (noun) is
associated with from 1 to 6 verbs. One way might be (pseudocode)
struct Entity
string name; // eg :pigeon
vector<int> verb_list; // eg 2, 5
Where verb_list identifies, via an index, all the valid verbs for this
entity.[Note 1]
string verb[6]; // I fully realize that this is an "old-fashioned" array
instead of a vector.
if verb[2] is "fly", then there is a 2 in the verb list for pigeon.
Now form a vector of entities.
vector<Entity> db; // data base
You could build the data in to the program or use an input file, I am not
sure which is quicker and easier. Note that there must be human involveent
to make the verb list.
Use a rand() to select the next question.
You can use clock() to generate the time delays. This will cause a lot of
bitching by the ivory tower set on this froup, but I am quite sure that is
what you instructor expects you to use.
You will need a supplemental library to respond to a simple 'y' or 'n'. C++
is quite deaf until you type [Enter]. Look up <conio> or <curses> or
something of that sort for Windows and *nix respectively. Maybe even
require the user to press [Enter] in addition to 'y' or 'n' while testing.
If there is time left, fix it later. Ignore the 'Y' ,'N' requirements until
near the end of your allotted time.
Don't get bogged down in the command line and the next player requirements.
Otherwise you will look at the clock and realize it is Friday morning and
you don't have a program. Write a program for one player who is asked
exactly 20 questions. Anything else is gravy. You don't have time for
gravy!!
There may be non-trivial problems with this, look at it with a skeptical
frame of mind.
Compile often, at least 50-100 compilations for this
-----
Note 1. This is not a really good design. This is a kind of underhanded
way of correlating the verb_list with the actual verbs. It is just what I
came up with. In olden days, programmers used to use something called
"parallel arrays". This is kind of like that. I would go with it anyway,
time is running out.