Page 1 of 1

The assessment consists of three elements. - In element 1, implement a number of functions. For this element, you need t

Posted: Thu Jul 14, 2022 2:13 pm
by answerhappygod
The Assessment Consists Of Three Elements In Element 1 Implement A Number Of Functions For This Element You Need T 1
The Assessment Consists Of Three Elements In Element 1 Implement A Number Of Functions For This Element You Need T 1 (147.55 KiB) Viewed 16 times
The assessment consists of three elements. - In element 1, implement a number of functions. For this element, you need to submit a Haskell (.hs) file with the source code in Haskell. - In element 2, complete an online multiple-choice quiz. For the source code submission, please note the following: 1. Any code you write must be in Haskell and follow the functional programming paradigm. 2. Your code should be correct, maintainable and readable: a. Identifiers should have reasonable names hinting and their purpose or function. b. Code should be reasonably commented: i. Module files should have a brief outline summarising their contents. ii. Any non-trivial function should have its purpose explained and arguments listed, including their semantics. iii. Use of whitespace (spaces/tabulators, empty lines, etc.) should be conducive to reading the code. 3. All code in your solutions must be your own. Unless otherwise specified, you can use the full standard prelude, but not any external modules, libraries, packages, or similar, even when these were mentioned in the lecture material or further reading. Unless otherwise mentioned, all modules imported in your code must be your own. 4. You can develop your submission in whatever environment you like (Windows, Macintosh, Linux, you name it), but a common standard is necessary. Therefore, it is a significant requirement that your submission executes correctly on a clean WinGHCi installation as installed on the university computers, without any modifications or additions either to your code, or the files you submit, or to the WinGHCi installation. Remote access to the university's WinGHCi installation is available via AppsAnywhere. 5. Some parts of the assessment may stipulate strict submission structure (module elements, function arguments, class members, etc.) and identifier values (e.g., names for files, folders, functions, classes, class members, etc.). Meeting these requirements to the letter contributes significantly to the grade.
Implement a module containing four functions: Function 1: Implement a function quadrupling a given numerical input Define a function triple : : Num a ⇒a→a that returns the input times three. For example, triple 3 would return 9 Function 2: Implement a function that checks whether the argument list begins and ends with the same value Define a function startEqualsend :: Eq a ⇒[a]→ Bool that returns True if the list argument starts and ends with the same value and returns False if not. For example, startEqualsEnd [2,16,7,32,4,2] would return True and startequalsend [1,3,5,7] would return False Function 3: Implement a function that produces sorted lists through elimination Define a function
would return  [’b’, ’c’, ’d’]  Function 4: Implement a function that computes the integer log (base 2) Implement the function log2 : : Integral a ⇒ a → a which computes the integer log (base 2) of its argument. That is, log2 computes the exponent of the largest power of 2 which is less than or equal to its argument. For example, Log2 17 should return 4 and log2200 should return 7 Function 5: Implement a function that searches a list for an item Write a recursive function contains : : [a] → a → b that searches a list given as first argument for a value given as second argument and returns True if the list contains the value. For example, contains "application" 'a' should return True and contains 6[1,2,3,4,5] should return False Function 6: Implement a triangle number function Define a recursive function triangleNumber : : Int → Int calculating the triangle number, that is, the sum of all positive integers less than or equal to the given number. For example: triangleNumber 5 would calculate the sum of 1+2+3+4+5 and return 15
The Caesar cipher is one of the earliest and simplest methods of encryption. It's a type of substitution cipher, i.e., each character of a given text is replaced by a character some fixed number of positions down the alphabet. You can assume that the plain text will contain alphanumerical characters only (see below). Characters should be shifted based on the following order: "abcdefghijklmnopqrstuvwXyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 " Take note of the space character at the end. For example, with a shift of 1 , occurrences of a are replaced by b, occurrences of b are replaced by c, and so on: z is replaced by A,z is replaced by 1,1 is replaced by 2,0 is replaced by the space character, and the space character is replaced by a. With a shift of 2 , occurrences of a ar replaced by c, occurrences of b are replaced by d, and so on. You can assume that the plain text will contain alphanumerical characters and spaces only. Thus, to cipher a given text we need an integer value, known as shift, to indicate the number of position each letter of the text has been moved down. The method is named after Julius Caesar, who historically used it to communicate with his officials. Define two functions encrypt and decrypt. encrypt :: [Char] → Int → [Char] should take a plain text and a shift, and returns the corresponding cipher text, whereas decrypt :: [Char] → Int → [Char]. should take a cipher text and a shift, and returns the corresponding plain text. For example: encrypt "Veni vidi vici" 2 would return "Xgpkbxkfkbxkek" and decrypt "Xgpkbxkfkbxkek" 2 would return "Veni vidi vici" Function 8: Define a Functor instance for a binary tree type Define an instance of the Functor class for the following type of binary tree with data in leaves: data Tree a = Leaf a | Node (Tree a) (Tree a) Submission Using the respective link for the code submission, submit your Haskell code as a Haskell code (.hs) file as follows: Submit all six functions in one Haskell module. The module must be called A1R_ and must export all six functions mentioned above. The Haskell start file must be called A1R_. hs. So, for example, if your student number were 21345678 , then the Haskell file must be named A1R_21345678. hs, the module must be called A1R_21345678, and it will contain the functions triple, startEqualsEnd, halve, log10, find, and factorial as described above.