PROGRAMMING AS PROBLEM SOLVING
COMP1100
checksum:
AAAAA
bytes:
65
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 QuickCheck and doctest in 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 (including example tests provided to you in the comments). Incorrect answers that pass tests will be penalised accordingly. The auto-grader will only mark code that you upload to the exam.


Total marks: 110
Writing period: 60 minutes duration.
Study period: None
Permitted materials: None, aside from the software environment provided.

You should attempt to answer all questions.
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

  [12 Marks]

For each of the following questions, mark the choice that provides the best answer.

1 i)

  [3 Marks]

  Binary representations

Using an unsigned binary interpretation, what is 110001 in decimal?

3
12
45
49

1 ii)

  [3 Marks]

  Binary representations

Using a two's complement 8-bit signed binary interpretation, what is 11111110 in decimal?

−2
254
101
−101

1 iii)

  [3 Marks]

  Binary representations

What is the 8-bit unsigned binary representation of decimal 38?

00100110
11100110
11011001
00011001

1 iv)

  [3 Marks]

  Binary representations

How many distinct values can be represented in n bits?

nn
n2
2n
2n−1
2n−1

Question 2

  [20 Marks]

For each of the following questions, mark the statements True or False.
If uncertain, use the 'Clear' button to clear your answer.

2 i)

  [5 Marks]

  Haskell function declarations

Mark True for each of the following if it is a valid type signature, 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 final mark for this question is calculated by bounding the sum of marks between 0 and 5. For example, if you answered all questions correctly you would gain 5 for this question. If you answer 3 correctly, 2 incorrectly and leave the remaining unanswered you would gain 2 for this question.

TrueFalse
baz :: Int -> Integer ->
baz :: (Int, Bool) -> Integer
baz :: (Int, Bool)
baz : Integer -> Bool -> Bool -> Bool
baz :: Integer - Bool -> Bool -> Bool
baz :: Bool

2 ii)

  [5 Marks]

  Haskell function declarations

Consider the following Haskell function definition:

sum x y = x + y
Mark True for each of the following if it is a valid type signature for sum, 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 final mark for this question is calculated by bounding the sum of marks between 0 and 5. For example, if you answered all questions correctly you would gain 5 for this question. If you answer 3 correctly, 2 incorrectly and leave the remaining unanswered you would gain 2 for this question.

TrueFalse
sum :: Integer ‐> Integer ‐> Integer
sum :: Int ‐> Int ‐> Int
sum :: Int -> Int -> Double
sum :: Double -> Double -> Double
sum :: Int -> Double -> Double

2 iii)

  [10 Marks]

  Haskell function declarations

Consider the following function signature

foo :: (Int, Int) -> Integer -> Double
Mark the following statements True or False.
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 final mark for this question is calculated by bounding the sum of marks between 0 and 10. For example, if you answered all questions correctly you would gain 10 for this question. If you answer 3 correctly, 2 incorrectly and leave the remaining unanswered you would gain 2 for this question.

TrueFalse
The type of foo is equivalent to the type (Int, Int) -> (Integer -> Double).
The type of foo is equivalent to the type Int -> Int -> Integer -> Double.
The type of foo is equivalent to the type (Int -> (Int -> (Integer -> Double))).
The type of foo is equivalent to the type Int -> Int -> (Integer, Double).
Function foo takes a pair of elements of type Int as its argument.
Function foo takes a list of at least two elements of type Int as its argument.
Function foo takes a list of Int and returns a Double.
Function foo can be applied to the argument (4,4).
Function foo can be applied to the argument (4,3).
Function foo can be applied to the argument 'c'.
Function foo can be applied to the argument [4,4].
The type of the return value of foo is not given by this signature.
Nothing can be said about a function when only its type signature is given.

Question 3

  [10 Marks]

  Function definition (IsMiddleZero.hs)

Using the incomplete template for IsMiddleZero.hs in your mid-semester exam IntelliJ project, complete the undefined function isMiddleZero. Use the doctests provided to test your solution, and then upload your implementation of IsMiddleZero.hs, by dragging your file into the box below.

The specification of the isMiddleZero function is provided in the comments immediately above the function. You will need to adhere to that specification. 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 slightly from the ones 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. Incorrect answers that nevertheless pass tests will be penalized accordingly.

Question 4

  [18 Marks]

  Function definition (Animals.hs)

Using the incomplete template for Animals.hs in your mid-semester exam IntelliJ project, complete the undefined functions. Use the doctests provided to test your solutions, and then upload your implementation of Animals.hs, by dragging your file into the box below.

The specifications of the functions are provided in the comments immediately above the functions. You will need to adhere to those specification. 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 slightly from the ones 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. Incorrect answers that nevertheless pass tests will be penalized accordingly.

Question 5

  [15 Marks]

  List processing (LastChar.hs)

Using the incomplete template for LastChar.hs in your mid-semester exam IntelliJ project, complete the undefined function lastChar. Note that you are prohibited from using the prelude function last and must not change the import line. Use the doctests provided to test your solution, and then upload your implementation of LastChar.hs, by dragging your file into the box below.

The specification of the lastChar function is provided in the comments immediately above the function. You will need to adhere to that specification. 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 slightly from the ones 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. Incorrect answers that nevertheless pass tests will be penalized accordingly.

Question 6

  [20 Marks]

  Recursion over lists (Frequency.hs)

Using the incomplete template for Frequency.hs in your mid-semester exam IntelliJ project, complete the undefined function frequency. Use the doctests provided to test your solution, and then upload your implementation of Frequency.hs, by dragging your file into the box below.

The specification of the frequency function is provided in the comments immediately above the function. You will need to adhere to that specification. 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 slightly from the ones 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. Incorrect answers that nevertheless pass tests will be penalized accordingly.

Question 7

  [15 Marks]

  Computing with numbers (Shapes.hs)

Using the incomplete template for Shapes.hs in your mid-semester exam IntelliJ project, complete the undefined functions. Use the doctests provided to test your solutions, and then upload your implementation of Shapes.hs, by dragging your file into the box below.

The specification of the functions are provided in the comments immediately above the functions. You will need to adhere to those specification. 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 slightly from the ones 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. Incorrect answers that nevertheless pass tests will be penalized accordingly.