Question

Help me ... THANKS You are trying to open a safe. It has a knob that...

Help me ... THANKS

You are trying to open a safe. It has a knob that you can turn in small steps. Above the knob is a number which changes as you turn the knob. Experimentation shows that the number increases for each step you turn the knob clockwise, and decreases for anti-clockwise. The numbers go from 0 to 37. There is also a handle to open the door.

You are given the following instructions to open the safe:

1. Turn the handle reset the lock. The knob will reset to 0.

2. Turn the knob 58 steps clockwise.

3. Turn the knob 119 steps anti-clockwise.

4. Turn the knob 90 steps clockwise.

5. Turn the handle to open the door.

a) What number will be displayed above the knob after each step in the instructions? (1 mark)

b) A colleague tells you that turning the knob a full rotation (38 steps) does nothing. So, for example, turning the knob 40 steps clockwise is the same as turning the knob 2 steps clockwise. Modify the instructions to reduce the number of steps the knob turned to the minimum for each instruction, keeping the direction the same. (1 mark)

c) Consider the following problem: you have implemented a ring buffer to store some incoming data. You are using an array of 56 bytes, and each item of data is 8 bytes long. To add data you are using the following pseudo-code:

for j=0 to 7:

buffer[i + j] = newData[j]

i = (i + 8) % 56

Later, the data specification has changed to 9 bytes long, so you change your code as follows

for j=0 to 8:

buffer[i + j] = newData[j]

i = (i + 9) % 56

but the program is producing garbage. Explain what has gone wrong.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The data shows that number goes from 0 to 37 which implies that it is like a circular arrangement with 0-18 numbers on one side and 19-0 number on other side.

a) Number displayed above the knob

1) 0 as you are resetting the knob

2) 58 steps clockwise,

one full rotation - 38 steps so knob will display 58 - 38 = 20 display

3) 119 anticlockwise.

119-(38*3) = 119 - 114 = 5 anticlockwise from 20. It will display 15

4) 90 steps clockwise 90 - (38*2) = 14 steps clockwise from 15

It will display 29.

Opend for number = 29

b) As per values calculated above,

1. Turn the handle reset the lock. The knob will reset to 0.

2. Turn the knob 20 steps clockwise.

3. Turn the knob 5 steps anti-clockwise.

4. Turn the knob 14 steps clockwise.

5. Turn the handle to open the door.

c)i is not initialized to any value, i should be initialized to 0 before the for loop in both the cases

Add a comment
Know the answer?
Add Answer to:
Help me ... THANKS You are trying to open a safe. It has a knob that...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT