Question 1 Figure 2 shows the state transition diagram of a fi nite

advertisement
Question 1
Figure 2 shows the state transition diagram of a fi nite state machine (FSM) used to
control a vending machine.
The vending machine dispenses a drink when a customer has inserted exactly 50 pence.
A transaction is cancelled and coins returned to the customer if more than 50 pence is
inserted or the reject button (R) is pressed. The vending machine accepts 10, 20 and 50
pence coins. Only one type of drink is available.
The only acceptable inputs for the FSM are 10, 20, 50 and R.
An FSM can be represented as a state transition diagram or as a state transition
table. Table 2 is an incomplete state transition table for part of Figure 2.
Complete the missing sections of the four rows of Table 2.
Table 2
Original State
S0
S0
S0
S0
Input
10
Next State
S10
(3 Marks)
Question 2
There are different ways that a customer can provide exactly three inputs that will result
in the vending machine dispensing a drink. Three possible permutations are "20, 10, 20",
"10, R, 50" and "10, 50, 50".
List four other possible permutations of exactly three inputs that will be accepted by the
FSM shown in Figure 2.
(4 marks)
1.
2.
3.
4.
Question 3
Figure 2 shows the contents of a memory location.
Figure 2
What is the denary equivalent of the contents of this memory location if it represents an
unsigned binary integer?
(1 Mark)
Question 4
What is the denary equivalent of the contents of this memory location if it represents
an unsigned binary fixed point number, with 4 bits before and 4 bits after the binary
point?
(2 Mark)
Question 5
What is the denary equivalent of the contents of this memory location if it represents a
Two’s complement binary integer?
(2 mark)
Question 6
What is the hexadecimal equivalent of the binary pattern shown in Figure 2?
(1 Mark)
Question 7
State three features of well-written program code that help to make it understandable
without the need to include lots of comments.
(3 Mark)
1.
2.
3.
Question 8
Explain what is meant by an algorithm.
(2 marks)
Question 9
One way of checking that an algorithm is correct is to complete a dry run.
Dry run the algorithm in Figure 3 by completing Table 2.
Assume that x has a value of 7.
The MOD operator calculates the remainder resulting from an integer division.
Answer
True
Count
2
Remainder
1
(6 Mark)
Question 10
Create a folder/directory Question10 for your new program.
The variable table, Table 2, and the Structured English algorithm, Figure 4, describe a
simplified version of a noughts and crosses match. A match consists of a user-specified
number of games. In this simplified version, the two players complete each game on
paper and then enter information about the result of each game into a program that
totals the number of games won by each player. Assume that all games have a winner .
there are no drawn games.
Figure 4
PlayerOneScore ◄ 0
PlayerTwoScore ◄ 0
OUTPUT ◄How many games?◄
INPUT NoOfGamesInMatch
FOR NoOfGamesPlayed ◄ 1 TO NoOfGamesInMatch Do
OUTPUT ◄Did Player One win the game (enter Y or N)?◄
INPUT PlayerOneWinsGame
IF PlayerOneWinsGame = ’Y’THEN
PlayerOneScore ◄ PlayerOneScore + 1
ELSE
PlayerTwoScore ◄ PlayerTwoScore + 1
ENDIF
ENDFOR
OUTPUT PlayerOneScore
OUTPUT PlayerTwoScore
What you need to do
Write a program for the above algorithm.
Test the program by showing the results of a match consisting of three games where
Player One wins the 1st game and Player Two wins the second and third games.
Save the program in your new Question10 folder/directory.
Copy or print screen your source code below
(9 marks)
Question 11
Add screen captures for the three tests described above
(4 Marks)
Download