-------------------------------------------------------------------------------- MODULE: CA215 Languages and Computability COURSE: B.Sc. in Computer Applications (Software Engineering) YEAR: 2 EXAMINERS: Andy Way, Mary Hearne TIME ALLOWED: 1 hour 50 mins INSTRUCTIONS: Attempt all 3 questions. The exam is automatically corrected, meaning that you MUST observe the following: 1) In the home directory of the account you have been given, I will expect to find files called q1.hs, q2.hs and q3.hs containing your answer for each question. 2) The function names given in the questions themselves must be used, otherwise the marking system will not be able to call your program. -------------------------------------------------------------------------------- Question 1 [40 marks] Write code which takes a list l as input and returns the list where every second element in list l has been swapped. The top-level function must have the type declaration swap :: [a] -> [a]. Here are some sample inputs along with the corresponding output that your code should generate: Main> swap [1,2,3,4] [2,1,4,3] Main> swap ['a','b','c','d','e'] "badce" Main> swap ["seven"] ["seven"] Main> swap [5,33,22,9,7,0,11] [33,5,9,22,0,7,11] Please save your solution in file q1.hs. Question 2 [30 marks] Write code which calculates the points total in a game of rugby from a list of scores. The top-level function must have the type declaration sumScore :: [Score] -> Int. Assume this datatype definition: data Score = Conversion | Try | Goal. Note that a goal is worth 3 points, a try is worth 5 points and a conversion is worth 2 points. Here are some sample inputs along with the corresponding output that your code should generate: Main> sumScore [] 0 Main> sumScore [Goal] 3 Main> sumScore [Goal,Goal,Try,Conversion,Try] 18 Please save your solution in file q2.hs. Question 3 [30 marks] Write code which computes the standard deviation over a list of Floats. The top-level function must have the type declaration stdDev :: [Float] -> Float. Here are some sample inputs along with the corresponding output that your code should generate: Main> stdDev [1,2,3] 1.0 Main> stdDev [1,1,1,2,2,2,2,2] 0.5175492 Main> stdDev [5,13,4,9,18] 5.80517 Main> stdDev [109,88,3,65,-17,0,337] 121.6742 Please save your solution in file q3.hs.