Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Data Structure Expert

Lists & Functions Assignment

This assignment consists of three exercises. You are expected to submit a single file named a5.hs containing
• your name(s) and ID(s) (as comments at the top of the file),
• solutions for all exercises, include type definition for every function/value.
Test your final version of a5.hs files and make sure it compiles and has no syntax or logical errors.

Exercise 1

a) Define a recursive function hasD which takes a non-negative integer n and an integer digit d between 0 and 9 inclusive, and returns True if the base-10 representation of n contains the digit d; False otherwise. For example, hasD 3071 7 should evaluate to True, and hasD 1201 4 to False.

b) Define a recursive function count :: [ Int ] ->

Int ->

Int which,

given a list of non-negative integers intL and an integer digit a between 0 and 9 inclusive, returns the number of integers in intL which contain the digit a (again

when written in base 10). For example, count
to 2, and count [98,4,376] 2 to 0.

[102,41,256] 2 should evaluate

c) Re-write the function from point b define using list comprehension-call it countC.

Exercise 2

a) Write a recursive function takeOut::Int->[Int]->[Int] so that

takeOut m

xs removes all multiples of m from xs.

b) Re-write the function from point a using list comptrehension-call it takeOutB.

c) Write a recursive function called count3r that takes a list of triples of Ints as a parameter. The result should be the number of triples for which the last element is the sum of the first two elements. For example:
count3r [(6,-8,-2),( 2,4,6),(8,7,1),(4,5,9)] should return 3

and count3r

[(-1,3,1), (1,5,7)] should return 0

d) Re-write the function from point c) using list comprehension;call it count3L

Exercise 3 Write a Haskell script that will display some information about data stored in a file called DVDdata.hs The file DVDdata.hs contains a list of DVD movies and for each movie it contains its ID number, its title, whether it is available



(yes, no) and if it is overdue, how many days it is overdue. according to the movie ID values.
Here is a possible DVDdata.hs file:

The list is sorted

673_de.png

Your script should print a table with a) proper headings and
b) containing the following information for each DVD:

i. ii. iii. iv)

ID number title availability
if overdue - the required payment . The payment for overdue DVDs is computed by multiplying the number of overdue days by penaltyPerDay.

c) a footer containing the total number of available DVDs.
d) The list of DVDs should be now sorted on the title of the DVDs.
e) The output should be produced when the function printable (see picture below) is invoked at the prompt.

The output obtained from the above file should be like this:

628_d3.png

Be aware that the content of the file DVDdata.hs can be changed (for example more
DVDs can be included in the list), but the format of the information will be preserved.


Submit your solution electronically.

Important:
1. You can define and use other functions in order to solve a problem that asks you to define a function to perform a specific task.
2. Run your final version of a5.hs file on the computer labs and make sure it has no errors. Please note that if we cannot run your a5.hs script you will get 0 marks.

Data Structure, Computer Science

  • Category:- Data Structure
  • Reference No.:- M91420303
  • Price:- $15

Priced at Now at $15, Verified Solution

Have any Question?


Related Questions in Data Structure

Problem regarding the management program

Problem: Looks like its just adding a save and load feature to the same file you sent me for python 3.5 Until now, you have had to leave your team management program running on your computer indefinitely since you did no ...

Data Communication Delivering Information anywhere

Topic: Data Communication Delivering Information anywhere. Write a 9-12 pages paper in which you: Present an overview of the origin and history of the concept. Describe the current use of and attitude toward the concept. ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As