Sorting a list is a common example in computer science

Assignment Help Application Programming
Reference no: EM13380008

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 f evaluates 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 list To. This function should return a list of all the prime numbers up to a given value n.

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

Reference no: EM13380008

Questions Cloud

Task1 compile a list of at least four skills that are : task1. compile a list of at least four skills that are listed as essential or desirable from the advertisments you have
How tall must the antennas be if the link operates on a : how tall must the antennas be if the link operates on a frequency of 1450mhz d17miles d211miles and the obstruction is
Description provided with 6 papers we have to critically : description provided with 6 papers we have to critically analyse those papers and make a document with usual report
1nbspnbspnbspnbspnbspnbsp : 1.nbspnbspnbspnbspnbspnbsp ipnbspnbspnbspnbspnbspnbspnbspnbspnbspnbsp 143.190.149.158 subnet mast nbspnbspnbsp
Sorting a list is a common example in computer science : sorting a list is a common example in computer science functional languages make it very easy to express a sorting
1 give syntax example for each of the following group : 1. give syntax example for each of the following group functionsavgsumminmaxcountdistinctstddevvariance2. provide 2
Assess the idea that a system should be organized as a core : assess the idea that a system should be organized as a core system that implements the essential requirements with
Consider the type of software process used in your : consider the type of software process used in your organization or one in which you have previously worked. how many of
The paris bakery has decided to bake 30 batches of its : the paris bakery has decided to bake 30 batches of its famous beignets at the beginning of the day. the store has

Reviews

Write a Review

Application Programming Questions & Answers

  In this project you will create an application to run in

in this project you will create an application to run in the amazon ec2 service and you will also create a client that

  Imagine that your company has decided to expand to the web

imagine that your company has decided to expand to the web. you want to reuse some data entry code that has been

  1 here is a short program it prints out the value of a

1. here is a short program. it prints out the value of a variable x. ernie and bert disagree about what will be printed

  If the user wants to read the input from a file then the

if the user wants to read the input from a file then the output will also go into a different file. if the user wants

  Question 1we are given the following knowledge base of

question 1we are given the following knowledge base of travel informationnbspbycaraucklandhamilton.

  Basic requirementsscreen one has three edittext views and

basic requirementsscreen one has three edittext views and one button.the edittext views allow you to enter a students

  Create a application using the mvc architecture no

create a application using the mvc architecture. no scripting elements are allowed in jsp

  Rtl sa is a company which develops bespoke solutions for

rtl sa is a company which develops bespoke solutions for the rubber industry. they produce both rubber compound which

  Design a program that models the worms behavior in the

design a program that models the worms behavior in the subsequent scenarioa worm is moving toward an apple. each time

  Problem build a class for a type called fractionnbspthis

problem build a class for a type called fraction.nbspthis class is used to show a ration of two integers.nbsp include

  Part - 1 object-oriented designwrite a program that allows

part - 1 object-oriented designwrite a program that allows an instructor to keep a grade book. each students has scores

  Soda vending machine designnbsp design a soda vending

soda vending machine designnbsp design a soda vending machine that can deliver three kinds of soda a b and c. allnbsp

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd