• Congratulations to the Class of 2024 on your results!
    Let us know how you went here
    Got a question about your uni preferences? Ask us here

Thread to put any algorithm problems you have encountered and attempeted. (1 Viewer)

chris42

Member
Joined
Oct 4, 2003
Messages
649
Location
Sydney
Gender
Male
HSC
2004
Hey,

I thought this could be a good place to put algorithm questions we've encountered and put the answers we've done up.

And then can help make each others algorithms better, if there are any faults in them.
 

chris42

Member
Joined
Oct 4, 2003
Messages
649
Location
Sydney
Gender
Male
HSC
2004
I'll start it off with one from the HSC 2001 paper question 22

BEGIN Main Program
UpdateInventory
END
------------------------------------------------------------------------------------

BEGIN Update Inventory

Open Inventory File
Open Transaction File

REPEAT
Get transaction.stocknumber(x)
Find Transaction.stocknumber

IF Transaction.stocknumber(x) = Inventory.Stocknumber(x) THEN
Transaction.quantity = Inventory.quanity + Transaction.quantity

ELSE

IF Transaction.stocknumber(x) <> inventory.stocknumber(x) THEN
NoMatchFound
ENDIF

IF inventory.quantity < 3 THEN
Error Message
ENDIF
END IF

UNTIL there are no more transactions

END
------------------------------------------------------------------------------------

BEGIN Find Transaction.stocknumber

REPEAT

Inventory.stocknumber(x) = Inventory.stocknumber(1)
IF Inventory.stocknumber(x) = Transaction.stocknumber(x) THEN
Foundit = True
ELSE
Inventory.stocknumber(x) = Inventory.stocknumber(x + 1)

Until Foundit = True
END
------------------------------------------------------------------------------------

BEGIN NoMatchFound
Print Message No match between inventory.stocknumber(x) AND transaction.stocknumber(x).
END
------------------------------------------------------------------------------------

BEGIN ErrorMessage
Print Message Warning there is less then then 3 of stocknumber(x) in inventory
END
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top