Friday, April 24, 2009

clau.pseudo-code

Although I tried many times that the format looked nicer (using/not using tab) with the Format for blogging, I couldn´t achieve it. I don´t know what is the mistake. But here is the exercise.

Buy a train ticket to Berlin in a ticket-vending machine.
For humans
Go to the ticket machine
Press the button Ticket- Reservation
Select the departure and destination cities
Select the date and time
Select the number of travelers
Select the means of transport
Press search button
Select the journey that fit best with your request
Press purchase button and proceed to buy the ticket


For computer
function informationRequest:
with ticketMachine
press ticketMachine.monitor
select ticketReservation.button
press departure.button
with the keyboard on the monitor
write Dessau
press DessauHbf.button
press destination.Key
with the keyboard on the monitor
write Berlin
press BerlinHbf.button
desiredDay = Today
desiredTime = 23:00
desiredTravelers = Adult
desiredTravelers.number = 1
desiredTravel.class= secondClass
desiredMeansTransport = localTransport
press search.button
execute function informationRequest

function selectionJourney:
on standardFare.column and
along dep 23.17 arr 01:06.row
press purchase.button
execute selectionJourney

function buyTicket:
get credit.Card
with credit.Card
move 20 cm right
move 5 cm up
insert credit.Card inside ticketMachine.slot

when hear “beep” sound
remove creditCard
put creditCard in initial position
with keyboard near ticketMachine.slot
write creditCard.pinCode
press B button
wait monitor change image
move 60 cm down
open window
remove ticket
execute buyTicket
else:
finish

3 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. Nice. You actually tried to create a pseudo-code for something which is pure code inside the machine! But there is a problem with your code flow: you are calling the functions within themselves! This means each function will only be called if the function itself is called. A bit strange no? take a look at the other codes here at the blog: most of them create what we can call a "chain" of functions, with one function calling the other until the whole task is terminated.

    ReplyDelete
  3. hello daniel, i returned today from my study trip. I understand the comment you made for my exercise but i don´t really understand the mistake. I will analyze other exercises and i will try to improve mine. thanks

    ReplyDelete