程序代写代做 compiler C Haskell assembly PROGRAMMING AS PROBLEM SOLVING COMP1100

PROGRAMMING AS PROBLEM SOLVING COMP1100
checksum: AAAAA bytes: 40
Important notice: Code templates for answers to coding questions in this exam can be found in the accompanying IntelliJ project. You can place this Web page for the exam in a window side-by-side with the IntelliJ project window, so that you can conveniently switch between them while working on your answers. You will also want to open the Terminal tool in IntelliJ in which you can load your solution codes into GHCi and test them out. You can also make use of doctest for testing.
All of your answers will be auto-graded, so for coding problems you will be marked according to how many of our tests you pass. Incorrect answers that pass tests will be penalised accordingly. The auto-grader will only mark code that you upload to the exam.
Total marks: 50 Reading period: 10 minutes
Writing period: 60 minutes
Permitted materials: None, aside from the software environment provided.
Questions are not of equal value.
All questions must be completed on this web form.
Your work is automatically saved and recorded as you type. This is a closed examination. You may not copy this exam.
Question 1 [10 Marks] Multiple choice questions For each of the following questions, mark the correct answer.
1 i) [2.5 Marks] Programming
Which statement is False about Programming?
A compiler translates code from one form (source code) to another (target code).
Declarative programming is only possible in a language that does not support imperative programming. Haskell supports declarative programming.
Imperative programming is the oldest control flow paradigm.
Machine and Assembly languages are imperative.
Clear
1 ii) [2.5 Marks] Haskell
Which statement is False in Haskell?
Calling the same function with the same arguments always results in the same output. Expressions are not evaluated until their results are needed.
Functions can be inputs to other functions.
Functions can return functions as output.
The data stored in variables can change as the program runs.
Clear
1 iii) [2.5 Marks] Guarded expressions
Which of the following definitions is not a correct implementation of the && operation in Haskell?
myAnd :: Bool -> Bool -> Bool
myAnd b c
| b == c = b
| otherwise = False
myAnd b c |b=c
| otherwise = not c
myAnd b c
| b /= c = False
| otherwise = b
myAnd b c
| (b,c) == (True,True) = True
| otherwise = False
myAnd b c
| b && c = True
| otherwise = False
Clear
1 iv) [2.5 Marks] Style
Which of the following is not a good way to document a Haskell function?
A comment explaining the purpose of the function. A comment explaining the syntax of the function. A descriptive function name.
A type declaration.
One or more unit tests.
Clear
Question 2 [5 Marks] True/False questions: Sets and Functions Mark True for each of the following statements if it is correct, and False if not.
Each correct answer gains you 1 mark, each incorrect answer loses you 0.5 mark, while a question left unanswered neither loses nor gains marks. The minimum total mark for this question is 0.
True False
{1,2, …, 1000} is a finite set Theset A+B+C isequalto AxBxC ThesetA⟶B⟶C isequaltoA⟶(B⟶C) Given functions f :: A ⟶ B and g :: B ⟶ C , there is a function f . g :: A ⟶ C
Haskell functions are exactly the same as mathematical functions.
Question 3 [5 Marks] True/False questions: Lists Consider the following Haskell function.
head xs = case xs of
[] -> error “empty”
(h:_) -> h
Mark True for each of the following statements if it is correct, and False if not.
Clear Clear Clear Clear Clear
Each correct answer gains you 1 mark, each incorrect answer loses you 0.5 mark, while a question left unanswered neither loses nor gains marks. The minimum total mark for this question is 0.
True False
A valid type signature for head is [a] -> a The type of head “1234” is Char head ‘a’ gives the same result as head “a” head “ac” ++ head “bc” returns “ab” head (True,False) returns True
Clear Clear Clear Clear Clear
Question 4 [8 Marks] Animals (Animals.hs)
Using the incomplete template Animals.hs in your midterm exam IntelliJ project, complete the two undefined functions
classOf and sameClass .
The specification of the functions are provided in the comments immediately above the functions. You will need to adhere to
these specifications. You may use the doctests provided to help test your solution.
You can upload your implementation of Animals.hs by dragging your file into the box below. If you drag your file into the box again, it will overwrite your previous upload. This question is auto-graded: you will be graded according to how many tests you pass. The tests used to grade your work may differ from the doctests that appear in the template file. The auto- grader will only mark what you upload to the exam. Therefore it is essential that you upload your code into this exam, in the browser.
NOTE THAT CODE THAT DOES NOT COMPILE WILL RECEIVE ZERO MARKS, EVEN IF PART OF THE CODE IS CORRECT
Drag and drop Animals.hs below
!
Question 5 [7 Marks] Integer division (Division.hs)
Using the incomplete template Division.hs in your midterm exam IntelliJ project, complete the undefined function
intDiv .
The specification of the function is provided in the comments immediately above it. Instructions for submission are as for the previous programming question.
Drag and drop Division.hs below
!
Question 6 [8 Marks] Numbers (Numbers.hs)
Using the incomplete template Numbers.hs in your midterm exam IntelliJ project, complete the two undefined functions
intSum and countAppearances .
The specifications of the functions are provided in the comments immediately above them. Instructions for submission are as for the previous programming questions.
Drag and drop Numbers.hs below
!
Question 7 [7 Marks] Remove vowels (Vowels.hs)
Using the incomplete template Vowels.hs in your midterm exam IntelliJ project, complete the undefined function removeVowels .The specifications of the function is provided in the comments immediately above it. Instructions for
submission are as for the previous programming questions.
Drag and drop Vowels.hs below
!