This was question 22(a)(iii) in the 2001 paper, can someone please tell me if its correct? (i really hate algorithms btw)
Link to question
Link to question
Code:
BEGIN Bikes
OPEN trans_file
OPEN inv_file
index = 1
count = 0
WHILE more transactions in trans_file
READ trans_file.stocknumber(index)
found = false
WHILE found = false and not end of inv_file
count = count + 1
IF inv_file.stocknumber(count) = trans_file.stocknumber(index) THEN
found = true
END IF
END WHILE
IF found = true THEN
inv_file.quantity(count) = inv_file.quantity(count) + trans_file.quantity(index)
ELSE
Print "could not find stock number"
END IF
index = index + 1
END WHILE
index = 1
REPEAT
IF inv_file.quantity(index) < 3 THEN
Print "Less than 3 items in stock"
END IF
index = index + 1
UNTIL no more items in inv_file
CLOSE trans_file
CLOSE inv_file
END Bikes
Last edited: