Assignment in C++

G

g_sharad

Hi Everyone I have a object oriented C++ assignment which is due this
week and I have no idea as to how start it.................

This program prints a motion verb ( fly, run, swim, crawl, walk, or
roll ), waits for a second,
then prints the name of an entity and repeats the verb (for example:
fly ..1s.. pigeon fly!.. ).
The player has ½ second to type 'y' for yes or 'n' for no. (case
insensitive)

- If the answer is correct, the player scores, if incorrect, or if
there was no answer within the ½ second, the
player looses a point. When correct, all the motions the entity can
perform are printed.

- When wrong, Ka..BOOM! is printed instead.

The default number of questions per player is 20, but the number can
be changed by passing a different
number on the command line when starting the program.


At the end of the run the player's score (and the score of previous
players if there were any) is printed, the
question: "Another player (Y/N): " is asked. The game exits if 'n' is
typed.

The output should look something like this:-

Player 1 starting.
You must answer with the letter 'y' for YES, or 'n' for NO.
Press [Enter] when ready to start:

1 - fly pigeon fly!.. y
- I walk - I fly
2 - swim Wheelbarrow swim.. n
- I roll
3 - crawl ball crawl!..
Ka...BOOM!
4 - fly plane fly!.. y
- I roll - I fly.
5 - run boat run!.. n
- I roll.
6 - walk engine walk!..
Ka..BOOM!
7 - roll stone roll!.. y
- I roll.
.. . .
16- crawl time crawl!.. y
- I crawl - I fly.
17- swim goose swim!.. n
Ka..BOOM!
18- run lizard run!.. y
- I run - I crawl.
19- run nose run.. y
- I run
20- fly goose fly!.. y
- fly - I walk - I run - I swim.

Player 1 *** score: 16 ***

Well done! Start another player (Y or N)? y

Player 2 starting
You must answer with the letter 'y' for YES, or 'n' for NO.
Press [Enter] when ready to start:

1 - crawl giraffe crawl!.. y
Ka..BOOM!
 
A

Andre Kostur

(e-mail address removed) wrote in @y2g2000prf.googlegroups.com:
Hi Everyone I have a object oriented C++ assignment which is due this
week and I have no idea as to how start it.................

Then you're really in trouble. Go talk to your teacher and explain your
difficulties. We do not do your homework here. When you have made your
own attempt and have specific C++ questions, feel free to ask here.
This program prints a motion verb ( fly, run, swim, crawl, walk, or
roll ), waits for a second,
then prints the name of an entity and repeats the verb (for example:
fly ..1s.. pigeon fly!.. ).
The player has ½ second to type 'y' for yes or 'n' for no. (case
insensitive)

Good luck. Offhand I can't think of any Standard C++ way to do timed
input.

[snip the rest of the homework assignment]
 
V

Victor Bazarov

Hi Everyone I have a object oriented C++ assignment which is due this
week and I have no idea as to how start it.................

This program [..]

Any program should essentially start with a very simple thing:

int main()
{
return 0;
}

As soon as you get this to compile, continue expanding it until
it does what you need it to do.

V
 
O

osmium

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.
 
J

James Kanze

Hi Everyone I have a object oriented C++ assignment which is due this
week and I have no idea as to how start it.................
This program [..]
Any program should essentially start with a very simple thing:
int main()
{
return 0;
}
As soon as you get this to compile, continue expanding it until
it does what you need it to do.

That's usually about the last thing I'd do. Given the need to
write an application, you start with some design, identifying
the necessary abstractions. Only once you have an idea as to
what classes you need, and what they will look like, do you
start any coding. And in production code, at least, the coding
starts with the classes, and their unit tests; only once all of
the classes are available (and tested) to you think about
putting them together.

For a student project (or any project as small as this), you
very likely will skip the unit tests; the application is small
enough that you can debug the individual classes directly in it.
But coding without first knowing what you need to code is wrong
even in this case. (For a student project, I'd insist on full
UML diagrams, on paper, before starting coding, although for
something this small, an experienced practitionner could
probable do them in his head.)

Of course, if he doesn't yet know how to invoke the compiler, I
would start with hello, world, to learn this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,294
Messages
2,571,511
Members
48,206
Latest member
EpifaniaMc

Latest Threads

Top