Sunday, December 27, 2009

Can anyone help me with a programming problem?

The question asks, Assuming you wake at 6am and have to be at work by 9am, write pseudocode that would describing your preparation for work. Include at least two decisions and two loops. If anyone could help me write any part of this it would be greatly appreciated.Can anyone help me with a programming problem?
Pseudocode is just an english version of programming. Think of the steps you would do if you were a farmer getting ready to feed the horses. Shutting off the alarm, what to wear (a decision), what to eat, etc.





A couple of loops could be waiting until the bacon is cooked before you eat. Or waiting until the water is warm before stepping in the shower.





In the last one it would be:


turn on shower


Undress


while water is not warm


test water.





Does that help you?Can anyone help me with a programming problem?
1. Sleep until Alarm goes off


2. Check clock


3. Is the time before 6:00am?


4. If yes, hit snooze and go to step 1.


5. If no, get out of bed


6. Prepare for work


(this can be decomposed into smaller steps as desired)


7. Leave for work


8. Drive toward work


9. Calculate approximate arrival time @ current speed


10. Is the projected arrival time after 9:00am?


11. If yes, then SPEED UP and go to step 8


12. If no, then continue at current speed


13. Are you at work?


14. If no, then go to step 8.


15. If yes, then stop driving.


16. Leave car, enter building, etc.


17. Start working





Notice the different types of loop structures. Step 1 is itself a loop (Sleep until...) implying that you cannot get to Step 2 until the condition to the right of ';until'; is met.





Step 4 is an example of a larger logical loop between steps 1 and 4 that more specifically decomposes the problem ';Sleep until 6:00am';. ';If...Else'; is perhaps the most common branching/looping structure across almost all major languages.





Sometimes in pseudocode you may want to break down a step into smaller steps, or -- in this case -- a loop of steps.





And of course 10-13 and 13-15 represent similar (adjacent!) loops.





Hope this helped!

No comments:

Post a Comment