CP1 1902程序 写作、 写作c/c++程序作业、 辅导Java,Python

” CP1 1902程序 写作、 写作c/c++程序作业、 辅导Java,PythonCP1 1902/159.202AKLIMASSEY UNIVERSITYAUCKLAND CAMPUSEXAMINATION FOR159.202 DECLARATIVE PROGRAMMINGSEMESTER TWO 2019_________________________________________________________________________________________________________Time allowed is THREE (3) Hours.This paper has FOUR (4) questionsALL questions should be attemptedWrite your answers in the Blue Answer Book providedNon-Programmable Calculators only are permitted.Students may NOT remove any part of this exam paper from the exam room.The exam paper will be made available on the University Library website.This final examination has 55 marks and contributes 55% to your final gradePage 2 of 5 COSQuestion 1. Short Answer Questions [20 marks]a. Describe the major differences between declarative and imperative [2 marks]programming languages.b. Describe Tthe similarities and differences between the logic and functional [2 marks]programming language paradigms.c. Describe what referential transparency is and discuss its importance for [2 marks]functional programming languages.d. Give two differences between imperative arrays and declarative lists. [2 marks]e. Briefly discuss the feature of Haskell that allows it to support infinite lists. [2 marks]f. Briefly describe what higher-order functions are and how they can be used. [2 marks]g. What is the difference between functions and operators? [2 marks]h. What are the two main data structures in Haskell? [2 marks]i. Explain Why input/output introduces a problem in functional languages. [2 marks]j. Briefly describe what a lambda function is and what the advantage of using [2 marks]one is.CP1 1902作业 写作、 写作c/c++程序语言作业Page 3 of 5 COSQuestion 2. Haskell Programming [10 marks]A happy number is defined as follows – take any positive integer and replace it by the sum of thesquares of its digits (in base ten), repeat this process until it reaches 1 (where it stays forever) or itreaches 4 (the process will always reach one of these two numbers). If the process reaches 1 thenthe number is happy, if it reaches 4 then it is unhappy.For example:68 62 + 82 = 100 12 + 02 + 02 = 1 68 is happy (reached 1)13 12 + 32 = 10 12 + 02 = 1 13 is happy (reached 1)24 22 + 42 = 20 22 + 02 = 4 24 is unhappy (reached 4)a. Write a function to determine whether a number is happy. [2 marks]example:Main happy 13TrueMain happy 24FalseUsing the function you have written in part a, write a function that takes two positive integers andreturns a list of all the happy numbers between these two values (possibly including the twonumbers if they are happy) according to the requirements below:example:Main happy_numbers 10 30[10, 13, 19, 23, 28]b. Implement the function using guards and recursion. [2 marks]c. Implement the function Using if-then-else statements and recursion. [2 marks]d. Implement The function using list comprehension(s) and without recursion. [2 marks]e. Rewrite the function using the built-in function map and without recursion. [2 marks]Page 4 of 5 COSQuestion 3. Haskell Programming Lists and Polymorphism [15 marks]For all following functions, Write the type signature and implementation of the function. The typeof the functions should be as general as possible. Do not use the Haskell built-in functions (unlessexplicitly stated). Example expected behaviour is shown for some functions.a. A function to find the length of a list. [2 marks]Main length [1,2,3,4,5]5b. A function to find the maximum value in a list. [2 marks]Main maximum [1,4,6,2,13,5]13c. A function to find the Element in the middle of a list. If there are an even [2 marks]number of elements, return the first element of the pair in the middle.Main middle [1,2,3,4,5]3Main middle [a, b, c, d, e, f]cd. A function to find the average of a list of numbers. [3 marks]Main average [7,9,14,10,12,11]10.5e. A function that formats a string so the first letter of every word is uppercase [3 marks]and all other letters are lowercase. You are allowed to use the following threefunctions in your answer:isLetter returns true if character is a letter, false otherwise.toUpper converts a lowercase char to uppercase, unchanged otherwise.toLower converts an uppercase char to lowercase, unchanged otherwise.Main format hello CLASS, hOw are YOu goiNG?Hello Class, How Are You Going?f. A function that implements quicksort using list comprehensions. [3 marks]Page 5 of 5 COSQuestion 4. Haskell Programming Higher-Order Functions [10 marks]a. Write a higher-order function foldr1If that takes a list and two functions and [2 marks]folds (combines) selected elements in the list together. The first function shouldbe used to combine two elements together and the second used to decide whetherthe elements should be selected.example:Main foldr1If [2,5,4,3,6,7,11] (+) even12Main foldr1If [3,4,5,6,7,8] (*) odd105b. Write the higher-order function foldr1If2 that has the same functionality as [2 marks]foldr1If from part a But is implemented using the higher-order functionsfoldr and filter.c. Write the higher-order function foldr1If3 that again behaves the same as [2 marks]foldr1If but is written using partial definition(s) and function composition(s).d. Write a higher-order Function called mapEach that takes a list of functions and [4 marks]a list of elements and applies each function to the corresponding element in theother list.example:Main mapEach [sqrt, cos, (\x – 2**x), (*3)] [4, 0, 3, 5][2.0, 1.0, 8.0, 15.0]+ + + + + + + +如有需要,请加QQ:99515681 或邮箱:99515681@qq.com

添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导