Sunteți pe pagina 1din 3

LAB # 04

OBJECTIVE:
 What is a state diagram?
 Sub states
 History States t
 Entry and Exit Points
 Why state diagrams Important?

LAB TASKS
TASK # 1
Draw the state diagram for ATM machine; the requirements are the same as specified in Lab # 2.

TASK # 2
Suppose you're designing a toaster. Create a state diagram for the toaster. Include necessary
triggering events, actions, and guard conditions. Develop the diagrams in three steps

TASK # 3
CASE STUDY: CD PLAYER

Consider the behavior of a simple CD player which consists of a drawer to hold the CD, if any,
that is currently being played, and an interface consisting of three burtons:

 Load
 Play
 Stop

The load button causes the drawer to open if it is currently shut, and to shut if it is open. The stop
button causes the player to stop playing. If the stop button is pressed when no CD is playing, it
has no effect; finally, the play button causes the CD contained in the drawer to be played. If it is
pressed when the drawer is open, the drawer shuts before playing starts.
When the drawer is open, pressing the 'load' button shuts it, and when it is shut, pressing load'
causes it to open. Furthermore, if a CD is playing, pressing the stop button causes playing to
stop, but if no CD is playing, this action has no effect.

We can identify at least three distinct states that the CD player can be in:

 Open State
 Closed State
 Playing State

The different effects of pressing 'load' indicate that we need to distinguish an 'open' and a
'closed' state, and the different effects of pressing 'stop' suggest that there is a third state, which
might be labeled 'playing', which is distinct from either of these.

It is also noteworthy that the CD player may change state in response to events. For example,
pressing the 'load' button repeatedly will cause the CD player to switch between the open and
closed states. A simple state machine for a CD player is given below:

The diagram shown above describes the functioning of the CD player when it is in use, but it
does not say what happens when the machine is switched on and off.

We will assume that when the machine is switched off it exhibits no behavior i-e the control
program is terminated and the machine will not respond to any events until it has been switched
again, that when it is powered on it always goes straight to the closed state.

Expand this diagram and draw a complete state chart for the CD player including the:
 Initial State
 Final State
 Guard Conditions
 Actions
 Activities
 Composite States
 History State
Task 4:
In this state machine, when a washing machine is running, it will progress from "Washing"
through "Rinsing" to "Spinning". If there is a power cut, the washing machine will stop running
and will go to the "Power Off" state. Then when the power is restored, the Running state is
entered at the "History State" symbol meaning that it should resume where it last left-off

S-ar putea să vă placă și