Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Programming Language Expert

Sorting a list is a common example in Computer Science, functional languages make it very easy to express a sorting algorithm. There are a number of ways a list can be sorted, ascending order, descending order, the first/second value of a tuple etc.

a) Write a higher order function that takes as its parameters a function that will be used to compare two elements and a list to be sorted. The result of the function should be a list that has been sorted according to the comparison function. (You may define that the items in the list will be Ord a, that means you can use comparison operator ‘==' to compare two items). Some example output expected of this function is shown below:

Main>mySort (<) [1,5,3,6,4,1,3,3,2]
[1,1,2,3,3,3,4,5,6]
Main>mySort (>) [1,5,3,6,4,1,3,3,2]
[6,5,4,3,3,3,2,1,1]
Main>mySortlongerWord ["Hello", "The", "a", "Daniel", "Declarative"]
["Declarative", "Daniel", "Hello", "The", "a"]


b) Write a higher order function list To that takes a function f and a number n and uses list comprehension to return a list of all the numbers from 1 to n for which the function fevaluates to True.

A prime number is a number that is only divisible by itself and 1. For example the number 7 is divisible by 7 and 1 but it cannot be divided by anything else.

c) Write a function prime that takes a single integer and returns true if it is a prime number and false if it is not. Your functions should give useful error messages if 0 or negative values are given as parameters. Use currying to define a function prime To in terms of the function listTo. This function should return a list of all the prime numbers up to a given values.

Some expected output is shown below:
Main> prime 1
True
Main> prime 4
False
Main>primeTo 10
[1,2,3,5,7]

d) Write a Haskell script that will

1. Store an unsorted list of students including their:
-First and last names
-Student ID
-midterm mark
-final exam mark
-assignment 1 mark
-assignment 2 mark
-assignment 3 mark

2. Sort the list according to the last name

3. Calculate the students final grade based on the following formula:
final grade = midterm * 0.25 + final * 0.5 + ((assignment 1 + assignment 2 + assignment3) / 3.0) * 0.25

4. Print a table with proper headings containing the following information for each student.
Student ID First Name Last Name Final Grade

5. Print a footer containing the class average at the bottom of the table.
Some expected output is shown below:

Computer Science Declarative Programming Results
Student ID First Name Last Name Final Grade
01234567 Jo Bloggs A
12345678 John Doe B
23456789 Jane Doe C
. . . .. . . Class Average: B

Programming Language, Programming

  • Category:- Programming Language
  • Reference No.:- M9910296
  • Price:- $60

Priced at Now at $60, Verified Solution

Have any Question?


Related Questions in Programming Language

1 write a function named check that has three parameters

1. Write a function named check () that has three parameters. The first parameter should accept an integer number, andthe second and third parameters should accept a double-precision number. The function body should just ...

Question 1 what is a computer program what is structured

Question: 1. What is a Computer program? What is structured programming? 2. What is modular programming? Why we use it? 3. Please evaluate Sin (x) by infinite series. Then write an algorithm to implement it with up to th ...

Extend the adworks applicationi add dialogs to allow the

Extend the AdWorks application I. Add Dialogs to allow the user to Add, Edit, Read and Delete a Customer and refresh the view accordingly. 1. The user should be able to select a specific customer from the DataGrid and cl ...

Assignment - haskell program for regular expression

Assignment - Haskell Program for Regular Expression Matching Your assignment is to modify the slowgrep.hs Haskell program presented in class and the online notes, according to the instructions below. You may carry out th ...

Question - create a microsoft word macro using vba visual

Question - Create a Microsoft Word macro using VBA (Visual Basic for Applications). Name the macro "highlight." The macro should highlight every third line of text in a document. (Imagine creating highlighting that will ...

Overviewthis tasks provides you an opportunity to get

Overview This tasks provides you an opportunity to get feedback on your Learning Summary Report. The Learning Summary Report outlines how the work you have completed demonstrates that you have met all of the unit's learn ...

Assignment - proposal literature review research method1

Assignment - Proposal, Literature Review, Research Method 1. Abstract - Summary of the knowledge gap: problems of the existing research - Aim of the research, summary of what this project is to achieve - Summary of the a ...

Task arrays and structsoverviewin this task you will

Task: Arrays and Structs Overview In this task you will continue to work on the knight database to help Camelot keep track of all of their knights. We can now add a kingdom struct to help work with and manage all of the ...

Structs and enumsoverviewin this task you will create a

Structs and Enums Overview In this task you will create a knight database to help Camelot keep track of all of their knights. Instructions Lets get started. 1. What the topic 5 videos, these will guide you through buildi ...

Question 1 what is hadoop explaining hadoop 2 what is

Question: 1. What is Hadoop (Explaining Hadoop) ? 2. What is HDFS? 3. What is YARN (Yet Another Resource Negotiator)? The response must be typed, single spaced, must be in times new roman font (size 12) and must follow t ...

  • 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