! Title : TrueBASIC Solution ! Author : John Walsh ! Date : 22 September 2000 ! ! Catalogue Shopping Program ! ! set aside space for arrays DIM item$ (10), price (10), code (10), stock (10) CALL initialise (reorder_level, no_of_items) CALL fill_arrays(item$ (), price (), code (), stock (), no_of_items) DO CLEAR CALL present_menu DECLARE FUNCTION get_value LET choice = get_value(1,5) SELECT CASE choice CASE 1 CALL search_by_name (item$ (), stock (), (no_of_items)) CASE 2 CALL search_by_code (item$ (), code (), stock (), (no_of_items)) CASE 3 CALL search_by_stock_level (code (), stock (), (reorder_level), (no_of_items)) CASE 4 CALL find_maximum_in_stock (item$ (), price (), stock (), (no_of_items)) CASE else END SELECT LOOP UNTIL choice = 5 PRINT "End of program" END ! SUB initialise (reorder_level, no_of_items) ! initialise variables LET no_of_items = 10 LET reorder_level = 5 END SUB ! SUB fill_arrays(item$ (), price (), code (), stock (), no_of_items) ! fill the arrays with data from the data statements FOR counter = 1 TO no_of_items READ item$ (counter), price (counter), code (counter), stock (counter) NEXT counter ! DATA Kettle, 12.99, 999, 21 DATA Duvet, 29.99, 871, 12 DATA Watch, 15.99, 312, 4 DATA Tea set, 49.99, 307, 3 DATA Lava lamp, 32.75, 302, 2 DATA Tea towel, 1.99, 901, 6 DATA Headphones, 13.75, 398, 4 DATA Batteries, 1.99, 546, 34 DATA Cafetiere, 19.99, 334, 15 DATA Video tapes, 2.99, 100, 25 ! END SUB ! FUNCTION get_value (minimum,maximum) ! only accept numbers within a given range INPUT number DO WHILE (number < minimum) OR (number > maximum) PRINT "Only values between ";minimum;" and ";maximum;" are accepted - please re-enter"; INPUT number LOOP LET get_value = number END FUNCTION ! SUB present_menu ! Display menu PRINT "Catalogue Shopping Program Menu" PRINT PRINT "1. Search by name for stock level" PRINT "2. Search by code number for stock level" PRINT "3. Search for items to be reordered" PRINT "4. Search for potential sale items" PRINT "5. Exit" PRINT PRINT "Enter 1,2,3,4 or 5" END SUB ! SUB continue ! Pause program DO PRINT PRINT "Press to continue" GET KEY space LOOP UNTIL space = 32 END SUB ! SUB search_by_name (item$ (), stock (), no_of_items) ! Search catalogue for items by name LET found = 0 PRINT "Search for item by name" PRINT PRINT "Please enter name of item" INPUT name$ FOR counter = 1 TO no_of_items IF name$ = item$ (counter) THEN LET found = 1 PRINT "Name Number in stock" PRINT item$ (counter), stock (counter) END IF NEXT counter IF found = 0 THEN PRINT "That item is not in the catalogue" CALL continue END SUB ! SUB search_by_code (item$ (), code (), stock (), no_of_items) ! Search catalogue for items by code - Valid code numbers range from 100 to 999 LET found = 0 PRINT "Search for item by code number" PRINT PRINT "Please enter code for item" DECLARE FUNCTION get_value LET item_code = get_value(100,999) FOR counter = 1 TO no_of_items IF item_code = code (counter) THEN LET found = 1 PRINT "Name Number in stock" PRINT item$ (counter), stock (counter) END IF NEXT counter IF found = 0 THEN PRINT "That item is not in the catalogue" CALL continue END SUB ! SUB search_by_stock_level (code (), stock (), reorder_level, no_of_items) ! Search catalogue for items whose stock level is less than the reorder level LET found = 0 PRINT "Search for items to be reordered" PRINT PRINT "Code Number in stock" FOR counter = 1 TO no_of_items IF stock (counter) < reorder_level THEN LET found = 1 PRINT code (counter), stock(counter) END IF NEXT counter IF found = 0 THEN PRINT "Stock levels are all above reorder level" CALL continue END SUB ! SUB find_maximum_in_stock (item$ (), price (), stock (), no_of_items) ! Search catalogue for potential sale item LET maximum = 1 PRINT "Search for a potential sale item" PRINT PRINT "Name Price Number in stock" FOR counter = 2 TO no_of_items IF stock (counter) > stock (maximum) THEN LET maximum = counter NEXT counter PRINT item$ (maximum), price (maximum), stock (maximum) CALL continue END SUB !