Solved

[c++]  event driven programming

Posted on 2007-11-26
5
876 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
>> 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

744 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

17 Experts available now in Live!

Get 1:1 Help Now