HJÆLP......små opgaver i scala og Haskell....

Tags:    diverse

Hej alle sammen,

Jeg har et par små opgaver; en i scala og en i Haskell, jeg skal aflever. Men jeg har desværre ikke så meget tid, så hvis der er nogle der kunne tænke sig at hjælpe ville jeg blive rigtig glad :D.

Opgaven i scala:

Opgave 1: Write methods union and intersection to form the union and intersection between two sets.
Opgave 2: Add a method
def excl(x: int)
to return the given set without the element x. To accomplish this, it is useful to also implement a test method
def isEmpty: boolean
for sets.

Opgaven i Haskell:

A scanner at a supermarket checkout will produce from a basket of shopping a list of bar codes, like
[1234,4719,3814,1112,1234]
which has to be converted to a bill:
Lists'R'Us

Dry Sherry, 1lt..........$5.40
Fish Fingers.............$1.21
Orange Jelly.............$0.56
Hula Hoops (Giant).......$1.33
Dry Sherry, 1lt..........$5.40

Total...................$13.90

We will model this in Haskell using the following types:
type Name = String
type Price = Int -- prices are specified in cents here
type BarCode = Int
type Database = [(BarCode,Name,Price)]

The example database and bar codes we use are these:
db = [(4719, "Fish Fingers", 121),
(5643, "Nappies", 1010),
(3814, "Orange Jelly", 56),
(1111, "Hula Hoops", 21),
(1112, "Hula Hoops (Giant)", 133),
(1234, "Dry Sherry, 1lt", 540)] :: Database

codes = [1234,4719,3814,1112,1234] :: [BarCode]

opgave 1: Write a function lookupBarCode :: BarCode -> Database -> (Name,Price) that finds the name and price for a given barcode and database.

opgave 2: Write a function formatLine :: (Name,Price) -> String that produces a single line of a bill; for example, formatLine ("Dry Sherry, 1lt", 540) should return the string Dry Sherry, 1lt..........$5.40.

Note that lines in bills are 30 chars wide. You may assume that names of goods are at most 20 chars long, that all prices are between 10 and 100000 cents, and that all relevant barcodes appear in the database.

The following function could also be useful:
substring s i j = take (j-i) (drop i s)
(It returns the substring of s from the i'th to the j'th char, like String.substring(int,int) in Java.) Moreover, it may be useful to know that an integer p can be converted to a string with show p, and the length of a list s (for example, a string) can be computed with length s. (The functions take, drop, show, and length are defined in the standard prelude.)

opgave 3: Write a function makeTotal :: [BarCode] -> Database -> Price that finds the total price for a given list of barcodes and a database. (Hint: use the lookupBarCode function.)

opgave 4: Write a function makeBill :: [BarCode] -> Database -> String that produces a bill for a given list of barcodes and a database, as in the example above. You can test your program with
main = putStr (makeBill codes db)
and then evaluate main from hugs (or use runhugs).

Jeg håber der er nogle der kan hjælpe mig :D
På forhånd tak.



2 svar postet i denne tråd vises herunder
1 indlæg har modtaget i alt 1 karma
Sorter efter stemmer Sorter efter dato
Nu kender jeg ingen af programmeringssprogen scala og Haskell. Hvor langt er du selv nået? Og har du noget dokumentation til syntax til disse sprog?



Nu kender jeg ingen af programmeringssprogen scala og Haskell. Hvor langt er du selv nået? Og har du noget dokumentation til syntax til disse sprog?


Hej, Jeg har været lidt længe om at svare, da jeg troede at opgaven ikke skulle løses alligevel, men den skal løses og jeg kan ikke selv få den løst. Jeg kan sende det dokumentation jeg har fået udleveret, det kan du måske bruge, hvis jeg får din mail eller noget.

mvh Gitte



t