FinalExamCLC 2021 Ans
FinalExamCLC 2021 Ans
ANSWERS
- Functional Programming uses functions as the basic elements. OOP uses objects/classes as the
basic elements. Student should give an example.
(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
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
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):
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]]
How many stars? 2 [[Note: Player 2 will remove 2 stars in row 3]]
[If one player is the winner then displays the winner, for example:
“Player 1 wins!!!”]