Brain Teaser
Faisal
cs0u919b@liverpool.ac.uk
Mon, 10 Dec 2001 00:17:39 -0000
i got this from a tutor who thinks hes awesome and clever and thinks that i
wont be able to find the solutions to this! The question is whos clever
enuf out there to help me make my tutor look like a fool!
Please help, i will be in ur debt for a long time!!!!
Background
Rhode Jams make a variety of jams and require a database to keep track of
their stocks. Their jams come in three types:
Ordinary Jam
Extra Jam (with a higher proportion of fruit to sugar) and
Luxury Conserve (with a very high fruit content).
Each of these types of jam is available in the following flavours:
Strawberry
Raspberry
Apricot
Plum
Peach.
Rhode Jams need to store information concerning the prices of each kind of
jam they produce, and the number of items they have in stock.
For this assignment, you are asked to develop a datatype to represent a
database record, and some functions that could be used in a prototype
system to help Rhode Jams monitor their stock (you do not have to develop a
fully-fledged database).
Haskell source code for each of the following:
0 Define a type StockItem that can be used to represent a database record:
each element of the data type should contain data for a type of jam, a
flavour, a price, and the number of items currently in stock. (The type
StockItem is required, you may choose to define this type by building it
from other types that you define; all definitions should be documented and
handed in.)
1 Define a function of type
StockItem -> [Char]
that gives a string representation of a database record, in a format
suitable for printing to a screen.
2 Define a function of type
[StockItem] -> [StockItem]
that takes such a list of database records and returns the list of all
records representing jams with fewer than twenty items currently in stock.
3 Define a function of type
[StockItem] -> Int
that calculates the total value of the current stock.
4 Define a function that takes a list of flavours and a list of jam types
as arguments, and returns the list of StockItems that represents all
possible combinations of types and flavours of jam from the given lists
(with stock levels set to 0, and a fixed price of 87 pence for ordinary
jam, 98 pence for extra jam, and 128 pence for luxury conserve).