0% found this document useful (0 votes)
0 views2 pages

FinalExamCLC 2022 Ans

This document outlines the final exam details for the Advanced Programming course at the University of Technology - VNUHCM, scheduled for June 4, 2023. It includes various questions related to functional programming concepts, Haskell scripts, and an implementation task for the game of Nim. The exam is closed-book, and students must submit both the question and answer sheets.

Uploaded by

acc4free9999
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)
0 views2 pages

FinalExamCLC 2022 Ans

This document outlines the final exam details for the Advanced Programming course at the University of Technology - VNUHCM, scheduled for June 4, 2023. It includes various questions related to functional programming concepts, Haskell scripts, and an implementation task for the game of Nim. The exam is closed-book, and students must submit both the question and answer sheets.

Uploaded by

acc4free9999
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/ 2

(Date) (Date)

Lecturer: Approved by:


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

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

Semester/Academic year 2 2022-2023


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

HINTS FOR 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): 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 4 (L.O.4): There are some ways to define the function:
listinsert :: Int  [Int]  [Int]

For example: listinsert 3 [1,2,8,9] will return [1,2,3,8,9]. Just follow the knowledges in the
courses to write your script

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
Question 6 (L.O.3, L.O.4): Implement the game of nim in Haskell (interactive program) as the exampe in
class.

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 ---

You might also like