// Title : COMAL Solution // Author : John Walsh // Date : 22 September 2000 // // Catalogue Shopping Program // set_aside_space fill_arrays (item$ (), price (), code% (), stock% (), no_of_items%) REPEAT CLS present_menu choice% := get_value% (1, 5) CASE choice% OF WHEN 1 search_by_name (item$ (), stock% (), no_of_items%) WHEN 2 search_by_code (item$ (), code% (), stock% (), no_of_items%) WHEN 3 search_by_stock_level (code% (), stock% (), reorder_level%, no_of_items%) WHEN 4 find_maximum_in_stock (item$ (), price (), stock% (), no_of_items%) ENDCASE UNTIL choice% = 5 PRINT "End of program" END // PROC set_aside_space // Initialise variables and set aside space for arrays no_of_items% := 10 reorder_level% := 5 choice% := 0 DIM item$ (no_of_items%), price (no_of_items%), code% (no_of_items%), stock% (no_of_items%) ENDPROC set_aside_space // PROC fill_arrays (REF item$ (), REF price (), REF code% (), REF stock% (), no_of_items%) CLOSED // Fill the arrays with data from the data statements FOR counter% := 1 TO no_of_items% DO READ item$ (counter%), price (counter%), code% (counter%), stock% (counter%) NEXT counter% ENDPROC fill_arrays // 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 // FUNC get_value% (minimum%, maximum%) CLOSED // Only accept numbers within a given range INPUT number% WHILE (number% < minimum%) OR (number% > maximum%) DO PRINT "Only values between "; minimum%; " and "; maximum%; " are accepted - please re-enter"; INPUT number% ENDWHILE RETURN number% ENDFUNC get_value% // PROC 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 a potential sale item" PRINT "5. Exit" PRINT '"Enter 1,2,3,4 or 5" ENDPROC present_menu // PROC continue // Pause program REPEAT PRINT PRINT "Press to continue" UNTIL GET = 32 ENDPROC continue // PROC search_by_name (REF item$ (), REF stock% (), no_of_items%) CLOSED // Search catalogue for items by name found := FALSE PRINT "Search for item by name" PRINT PRINT "Please enter name of item" INPUT name$ FOR counter% := 1 TO no_of_items% DO IF name$ = item$ (counter%) THEN found := TRUE PRINT "Name Number in stock" PRINT name$, stock% (counter%) ENDIF NEXT counter% IF found = FALSE THEN PRINT "That item is not in the catalogue" continue ENDPROC search_by_name // PROC search_by_code (REF item$ (), REF code% (), REF stock% (), no_of_items%) CLOSED // Search catalogue for items by code - Valid code numbers range from 100 to 999 found := FALSE PRINT "Search for item by code number" PRINT PRINT "Please enter code for item" item_code% := get_value% (100, 999) FOR counter% := 1 TO no_of_items% DO IF item_code% = code% (counter%) THEN found := TRUE PRINT "Name Number in stock" PRINT item$ (counter%), stock% (counter%) ENDIF NEXT counter% IF found = FALSE THEN PRINT "That item is not in the catalogue" continue ENDPROC search_by_code // PROC search_by_stock_level (REF code% (), REF stock% (), reorder_level%, no_of_items%) CLOSED // Search catalogue for items whose stock level is less than the reorder level found := FALSE PRINT "Search for items to be reordered" PRINT PRINT " Code Number in stock" FOR counter% := 1 TO no_of_items% DO IF stock% (counter%) < reorder_level% THEN found := TRUE PRINT code% (counter%), stock% (counter%) ENDIF NEXT counter% IF found = FALSE THEN PRINT "Stock levels are all above reorder level" continue ENDPROC search_by_stock_level // PROC find_maximum_in_stock (REF item$ (), REF price (), REF stock% (), no_of_items%) CLOSED // Search catalogue for potential sale item maximum% := 1 PRINT "Search for a potential sale item" PRINT PRINT "Name Price Number in stock" FOR counter% := 2 TO no_of_items% DO IF stock% (counter%) > stock% (maximum%) THEN maximum% := counter% NEXT counter% PRINT item$ (maximum%), price (maximum%), stock% (maximum%) continue ENDPROC find_maximum_in_stock //