SOLUTIONS RATED A+
✔✔The exception handling mechanism discussed in this course is at the level of -
✔✔user program.
✔✔A throw statement is associated with a specific exception handler through the -
✔✔the data type implied by the throw value.
✔✔There are various consequences to not using the C++ built-in exception handling
mechanisms. Which of them is the most serious consequence? - ✔✔Not restoring the
stack pointer to its original position before entering the function.
✔✔Which of the followings is a valid Scheme form?
* 9 (/ (- 4 2) 7)
*9 / - 4 2 7
9 * (4 - 2)/7
(* 9 (/ (- 4 2) 7)) - ✔✔(* 9 (/ (- 4 2) 7))
✔✔One of the major differences between the imperative and functional programming
languages is that the functional programming languages do NOT - ✔✔have side-effects.
✔✔The statement "a function is a first-class object" means that a function - ✔✔can be
placed in a place where a value is expected.
✔✔Functional programming languages do NOT allow us to define
- named values.
- variables whose value can be modified.
- multiple parameters in one procedure.
- procedures. - ✔✔variables whose value can be modified.
✔✔What notation requires parentheses in order to correctly define the order of
computation? - ✔✔infix notation
✔✔Functional programming language is more friendly to parallel computing, because it
supports - ✔✔Eager Evaluation
✔✔What functional feature does the code below best exhibit?
(define start-engine (lambda ()(error-detection (wheel-velocity (wheel-sensor)) (body-
velocity)))) - ✔✔procedures are first class objects.
,✔✔How does Scheme implement the function such as: for (i = 1; i< 100, i++) {sum =
sum + i;} - ✔✔With recursion
✔✔What is the return value of the code below?
(define lst '(3 5 2 9))(min (min (car lst) (cadr lst)) (min (caddr lst) (cadddr lst))) - ✔✔2
✔✔What statements contain non-functional features of Scheme? Select all that apply.
- (display x)
- (begin (write x) x)
- (caddr lst)
- (if a b c) - ✔✔- (display x)
- (begin (write x) x)
✔✔A let-form in Scheme defines a set of - ✔✔local names.
✔✔Given the Scheme code, answer the following questions.
((lambda (x)
((lambda (x y)
(+ x y))
4 (* 6 x)))
3)
(1) The value to be passed to the parameter y is __ .
(2) The final output of the piece of code is __ . - ✔✔1. 18
2. 22
✔✔What is the expected result for this expression (in Scheme)?
(string-ref "Hello World" 4) - ✔✔#\o
✔✔Given the Scheme code below, answer the following questions related the Fantastic
Four abstract approach.
(define dtob (lambda (N) ; line 1
(if (= N 0) (list 0) ; line 2
(append (dtob (quotient N 2)) ; line 3
(list (remainder N 2)))))) ; line 4
(1) What line of code defines the stopping condition and the return value?
(2) What line of code contains the size-M problem, where M < N?
(3) What lines of code define the step that construct the solution to size-N problem? -
✔✔1. Line 2
2. Line 3
3. Lines 3 and 4
✔✔What is the correct method for constructing a pair in Scheme? - ✔✔(cons 1 2)
, ✔✔Given this expression, what is the expected result?
(car (cdr '(1 2 3 4 5)) - ✔✔2
✔✔What statement is accurate and correct?
- There is only one Scheme list that is not a pair.
- There is only one Scheme pair that is not a list.
- Every Scheme list is a pair.
- Every Scheme pair is a list. - ✔✔There is only one Scheme list that is not a pair.
✔✔Given the Scheme code as follows. What is the output?
(define not-gate (lambda(x) (if (= x 0) 1 0)))
(define onescomplement (lambda (a-list) (map not-gate a-list)))
(onescomplement '(0 1 0 2 0 3)) - ✔✔(1 0 1 0 1 0)
✔✔Given the following Scheme definition:
(define reduce
(lambda (op base x)
(if (null? x)
base
(op (car x) (reduce op base (cdr x))
))))
What parameter passing mechanism is used for the parameter op in this code? -
✔✔Call-by-name
✔✔Compare the following two Scheme forms:(append '(1 2) '(4 5)) and (cons '(1 2) '(4
5)). - ✔✔(cons '(1 2) '(4 5)) returns '((1 2) 4 5).
✔✔Filter is a higher-order function that - ✔✔applies a predicate to all elements of a list.
✔✔Which predicate logic matches most closely with this statement?
"Bill listens to music or news." - ✔✔listensto(bill, music); listensto(bill, news).
✔✔A fact starts with a relationship followed by a list of arguments. The arguments of a
fact - ✔✔can have a structure similar to that of a fact.
✔✔A Prolog program finds a solution by - ✔✔searching the built-in database consisting
of facts and rules.
✔✔A Prolog variable represents a - ✔✔place holder.
✔✔The scope of a Prolog variable is - ✔✔within a single fact, rule, or query.
✔✔How many arguments can be defined in a fact? - ✔✔n, where n >= 0.