0% found this document useful (0 votes)
25 views3 pages

FinalExamCLC 2021 Ans

This document contains a final exam for an Advanced Programming course. It consists of 6 multiple choice and programming questions testing students' knowledge across 4 learning outcomes. The questions cover topics like functional vs object-oriented programming, lambda expressions, curried functions, higher-order functions, and implementing a game of Nim in Haskell.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views3 pages

FinalExamCLC 2021 Ans

This document contains a final exam for an Advanced Programming course. It consists of 6 multiple choice and programming questions testing students' knowledge across 4 learning outcomes. The questions cover topics like functional vs object-oriented programming, lambda expressions, curried functions, higher-order functions, and implementing a game of Nim in Haskell.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

(Date) (Date)

Lecturer: Approved by:


(Signature & Fullname) (Signature, Position & Fullname)

(The above part must be hidden when copying for exam)

Semester/Academic year 2 2021-2022


FINAL EXAM Date 23/05/2022
Course title Advanced Programming
UNIVERSITY OF TECHNOLOGY - VNUHCM Course ID CO2039
FACULTY OF CSE Duration 90 mins. Question sheet code
Notes: - This is closed-book exam
- Submit the question sheet together with the answer sheet

ANSWERS

Answer 1 (L.O.1, L.O.2):

- Functional Programming uses functions as the basic elements. OOP uses objects/classes as the
basic elements. Student should give an example.

Question 2 (L.O.3): Write paragraph to answer the following questions:

(i) Lambda expression can be used todefine a function without naming. Let give an example
(ii) Curried function receives parameters one-by-one. Let give an example
(iii)Higher-order function receives another function as its parameter. Let give an example
Question 3 (L.O.4): There are some ways to define the function:
perfects :: Int  [Int]

For example: perfects 500 will return [6,28,496]. Just follow the knowledges in the courses

Question 4 (L.O.4): Consider the following Haskell script:


ztn :: ([Int], Int) -> Int
ztn ([], x) = 0
ztn ((a:as), x) = (if a == x then 1 else 0) + ztn(as,x)
Answer the following questions:
(i) The function ztn counts the number of times that x appears in the array
(ii)
ztn [1,2,3] 2 error
ztn [1,2,3,2] 2 error
ztn ([1,2,3],2) 1
ztn ([1,2,3,2],2) 2
Question 5 (L.O.4): There are some ways to define the function.

For example:
removeIndex 0 [7, 5, 3, 8] -> [5, 3, 8]
removeIndex 3 [7, 5, 3, 8] -> [7, 5, 3]

Notice that you must compare the integer number and the length of the list.
Just follow the knowledges in the courses

Student ID: .......................................... Fullname: ......................................................................................... Page 1/2


Question 6 (L.O.3, L.O.4): Implement the game of nim in Haskell (interactive program).

Hint: Represent the board as a list of five integers that give the number of stars remaining on each
row. For example, the initial board is [5,4,3,2,1].

Consider an example of the output of the example program (the numbers after ? are the users’ inputs.
Assume that all users’ inputs are valid, thus you do not need to check the validity of the input):

Initializing … [[Note: Display the initial board]]

1: * * * * *
2: * * * *
3: * * *
4: * *
5: *
Player 1 is playing …
Row? 2

How many stars? 4 [[Note: Player 1 will remove 4 stars in row 2]]

1: * * * * * [[Note: Display the board after removing]]


2:
3: * * *
4: * *
5: *
Player 2 is playing …
Row? 3

How many stars? 2 [[Note: Player 2 will remove 2 stars in row 3]]

1: * * * * * [[Note: Display the board after removing]]


2:
3: *
4: * *
5: *
..........

[If one player is the winner then displays the winner, for example:

“Player 1 wins!!!”]

--- END ---


Student ID: .......................................... Fullname: ......................................................................................... Page 2/2

You might also like