-- -- This module is submitted as part of the assessment for -- COMP1100. -- Its completion is substanitally my own work. -- (signed) Joseph Curtis 3952239 -- class STOCK_CONTROL -- program to manage stock in a department store creation make feature stocklist : ARRAY[STORE_ITEM] -- the items stocked by the store make is local do !!stocklist.make(1, 0) exec_commands end -- make exec_commands is -- Read in and execute commands. local s : STRING command : CHARACTER do from command := 'm' until (command = 'q') or (command = 'Q') loop inspect command when 'm', 'M' then print_menu when 'l', 'L' then load_data when 'p', 'P' then print_stocklist when 'n', 'N' then new_item when 'i', 'I' then item_report when 's', 'S' then sell_item when 'r', 'R' then receive_delivery when 'v', 'V' then value_stock else io.put_string("Invalid command ") io.put_character(command); io.put_new_line print_menu end -- inspect -- get next command io.put_string("%NCommand : ") io.skip_separators io.read_line; s := io.last_string if s.count > 0 then command := s.item(1) else command := 'm' end -- if io.put_new_line end -- loop end -- exec_commands print_menu is -- Print menu of available commands. do io.put_string("Menu of commands%N") io.put_string("--------------------------------------%N") io.put_string(" m: menu - print this menu%N") io.put_string(" l: load stocklist data from file%N") io.put_string(" p: print all stock info%N") io.put_string(" n: add new store item%N") io.put_string(" i: item - print info on a store item%N") io.put_string(" s: sell an item%N") io.put_string(" r: receive delivery of an item in stocklist%N") io.put_string(" v: report total wholsale value of stock%N") io.put_string(" q: quit%N") end -- print_menu load_data is -- Fill stocklist array with items read from a file. require stocklist /= void local infile : STD_FILE_READ -- input file to read from infilename : STRING -- filename of input file item : STORE_ITEM -- store item ic : INTEGER -- itemcode of item desc : STRING -- description of item wp : REAL -- wholesale price of item rp : REAL -- retail price of item qty : INTEGER -- quantity in stock of item do -- connect to file io.put_string("Name of file containing stock information : ") io.read_word infilename := clone(io.last_string) !!infile.connect_to(infilename) if not infile.is_connected then io.put_string("%NError in connecting to input file%N") else -- load stock data from infile from -- read first itemcode infile.read_integer until infile.end_of_input loop ic := infile.last_integer -- description infile.read_word; desc := clone(infile.last_string) -- wholesale price infile.read_real; wp := infile.last_real -- retail price infile.read_real; rp := infile.last_real -- quantity in stock infile.read_integer; qty := infile.last_integer -- create item and add to stock list !!item.make(ic, desc, wp, rp, qty) stocklist.add_last(item) -- read next itemcode infile.read_integer end -- loop end -- if end -- load_data print_stocklist is --This routine prints out stock data for all stock --in a list. local i:INTEGER do -- Print out the heading and the list titles. io.put_string("Stock list%N") io.put_string("==========") io.put_new_line io.put_string("Itemcode Description Wholesale ") io.put_string("Retail Quantity") io.put_new_line io.put_string("----------------------------------") io.put_string("-----------------") io.put_new_line -- Loop to print out all the data from i:=stocklist.lower until i>stocklist.upper loop stocklist.item(i).print_store_item -- print out data for an itemcode. i:=i+1 end end -- print_stock new_item is -- This routine receives data from the user for a new stock -- item. It then creates the store item and adds it to the -- stocklist. local icode : INTEGER -- Itemcode desc : STRING -- description wp : REAL -- Wholesale price rp : REAL -- Retail price item : STORE_ITEM -- temporary store item do io.put_string(" Itemcode : ") -- Get itemcode from user io.read_integer;icode:=io.last_integer io.put_string(" Description : ") -- Get description from user io.read_line;io.read_line;desc:=clone(io.last_string) io.put_string(" Wholesale price : ") -- Get wholesale price from user io.read_real;wp:=io.last_real io.put_string(" Retail price : ") -- Get retail price from user io.read_real;rp:=io.last_real -- Create the temporary item with the user imputs !!item.make(icode, desc, wp, rp, 0) -- Add the item to the stocklist stocklist.add_last(item) end -- new_item item_report is --This routine prints out information about a stock time, given --the itemcode. local ic:INTEGER -- itemcode do io.put_string(" Itemcode : ") -- Get itemcode from user io.read_integer;ic:=io.last_integer -- Get index of item and print out the correct data stocklist.item(index_of_item(ic)).print_store_item end -- item_report sell_item is -- This routine prompts the user for an itemcode and an amount -- to sell. It uses the 'sell_stock' routine of the STOCK_ITEM -- class to remove the correct amount from the 'quantity' attribute. -- It then displays the itemcode, number sold, retail price and -- then the total price. local ic:INTEGER -- itemcode qs:INTEGER -- quantity sold price:REAL -- total price of goods (retail price * quantity) i:INTEGER --index of item do -- Get the user's input io.put_string(" Itemcode : ") io.read_integer;ic:=io.last_integer io.put_string(" Quantity sold : ") io.read_integer;qs:=io.last_integer i:=index_of_item(ic) -- get index of item -- evaluate the total price price:=qs*stocklist.item(i).retail_price -- adjust the quantity in the stocklist stocklist.item(i).sell_stock(qs) -- Print out the info to the screen io.put_new_line io.put_integer_format(ic, 8) io.put_integer_format(qs, 4) io.put_string(" @ ") stocklist.item(i).my_print_real_format(stocklist.item(i).retail_price , 4, 2) stocklist.item(i).my_print_real_format(price, 8, 2) io.put_new_line end -- sell_item receive_delivery is -- Receives a delivery of a certain itemcode and adds the quantity -- entered by the user to the stocklist. local ic:INTEGER -- itemcode quantity:INTEGER -- quantity received i:INTEGER -- index of item do -- get input from user io.put_string(" Itemcode : ") io.read_integer;ic:=io.last_integer io.put_string(" Quantity received : ") io.read_integer;quantity:=io.last_integer i:=index_of_item(ic) -- get index of item -- update quantity in stocklist stocklist.item(i).add_stock(quantity) end -- receive_delivery value_stock is -- This routine evaluates to total wholesale value of the stock -- in the list. To get this the quantity is multiplied by the -- wholesale price for every item in the stocklist and this is added -- up to get the total. local value : REAL -- total value of stock i : INTEGER do -- Loop for all items in the stocklist from i:=stocklist.lower until i>stocklist.upper loop -- evaluate the wholasale value for an item and then add -- it to the total sum. value:=value+(stocklist.item(i).wholesale_price* stocklist.item(i).qty_in_stock) i:=i+1 end -- Print this information to the screen io.put_string("Total wholesale value of stock is $") stocklist.item(1).my_print_real_format(value,8,2) io.put_new_line end -- value_stock index_of_item(icode : INTEGER) : INTEGER is -- Return the index in the stocklist array for the store item with -- itemcode icode. If there is no item with itemcode icode, -- then return stocklist.upper + 1 local i : INTEGER do from i := stocklist.lower until i > stocklist.upper or else (stocklist.item(i).itemcode = icode) loop i := i + 1 end --loop Result := i end -- index_of_item end -- class STOCK_CONTROL