"The Last Ottoman" writes:
I'm a student in Turkey, and my C++ project was quite hard for me.
Since I have never write any program in C++ (although I'm so good at
C), I have no idea what to do.
if I understand only a little part of the problem, I think I can solve
it.
Here is a small part of the problem...
There is a multidimensional array 10 x 10. There are doctors and humans
on the array with the sign 'D' and 'H'... Humans are sick, so they want
to move ahead to Doctors. but Doctors move randomly.. I have to design
a class system for humans to find the nearest doctor and move toward
him.
Just I said before, Since I don't know much about classes, I don't know
what to do.
The first problem is to analyze the thing logically, only then can you start
writing a program. You say the doctors move randomly. If this is so the
best approach is probably for a human to stay where he is and wait for a
doctor to bump into him. I assume you misspoke and actually meant the
doctors are located at random positions. If that is so, I guess the best
thing for a human to do is search in a spiral starting in his current
location. Which means keeping track of where he has been so he doesn't go
there again. When he hits the edge of a board, he will have to "unwind" in
the next outer layer.
I would start with a board populated by one human and one doctor. Indeed,
the whole point of using classes here seems to be the possibility that you
can have multiple "actors". If my guess, as to what the problem definition
is, is correct there is not much for a doctor to do. He just sits at some
x,y coordinate waiting for a patient. A human has to keep track of his
origin and his current position. If he goes in a clockwise direction until
he hits an edge and then goes CCW to the next edge, ISTM his entire history
is captured in those two factoids. So:
class Human
{
public:
Human(int xa, int ya);
bool move(); // move one unit and report success or failure
void show(); // for debugging
private:
int xorigin;
int yorigin;
int x; // current location
int y;
};
I would use a global variable for the board. This is much frowned upon by
most regulars on this newsgroup. Which makes me wonder: Are these the same
people that leave the turkey in the kitchen at Thanksgiving? (A little bit
of American humor, there.)
You may get advise to use vectors instead of arrays. It is clear that such
advise is inconsistent with your instructors chosen teaching sequence -
ignore such advise.