Solved

[c++]  event driven programming

Posted on 2007-11-26
5
877 Views
Last Modified: 2011-10-03
I don't exactly know what this term means,


for instance, to write a program to simulate a mouse trying to go through a maze, and I treat the mouse with sensors,  how do I write the thing that keeps reading the data coming in from it's sensors and then decide on what to do next?

0
Comment
Question by:Troudeloup
5 Comments
 
LVL 1

Assisted Solution

by:yyyc186
yyyc186 earned 150 total points
ID: 20354563
Please define what you mean by "simulate a mouse trying to go through a maze" and "sensors".

Is this a homework problem?
0
 
LVL 4

Assisted Solution

by:Ichijo
Ichijo earned 100 total points
ID: 20354683
An example of an event-driven maze traversal program for a sensor-equipped mouse would be, instead of telling the mouse to move one step and then check to see if it has bumped into something, you just tell it to walk straight until told otherwise. Then you have an event handler procedure that will run automatically whenever a collision event occurs (when the mouse bumps into a wall). Your event handler might tell the mouse to change direction, or take some other action of your choice.
0
 
LVL 1

Assisted Solution

by:yyyc186
yyyc186 earned 150 total points
ID: 20354727
You also need to check for possible turns reading those "sensors" or you will never get out of the maze if there is a turn not at a wall.

----------| |----------
|                             |
-------------------------

Once you get into something that looks like the above, you cannot get out.
0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 100 total points
ID: 20355417
You basically nee to implement the concept of a "state machine" (see e.g. http://en.wikipedia.org/wiki/State_machine), that is software that given to a current state (e.g. "moving right") reacts to a signal ("wall approaching") with a predefined reaction (e.g. "turning left"). How that is done in detail is up to the constraints you are facing, thus it is hard to give any more specific advise.
0
 
LVL 53

Accepted Solution

by:
Infinity08 earned 150 total points
ID: 20356348
>> event driven programming
>> I don't exactly know what this term means,

It's a programming technique that defines the flow of the program based on user actions or other (usually external) events (like messages, etc.). For example, if the user clicks a mouse, then some routine is executed to handle the mouse click event.

Or in other words, there's no execution from beginning to end, like a classic program would do ... instead the program is just sitting there, waiting for events, and whenever an event occurs, the proper action is taken to handle that event.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now