Quiz 3, Quiz 2, final

Ace your homework & exams now with Quizwiz!

In Scheme, what will the primitive (char? "#\A") will return?

#t

Match the following control symbols with their use %d, %f, %c, %s, %p

&d - integers %f - floating points %c - characters %s - string of characters %p - pointers

What will (member '2 '(3 4 2 1)) return in Scheme?

(2 1)

What is the return value of the following form? (map (lambda (x) (+ x 10)) '(10 30 15))

(20 40 25)

What is the return value of the following form? (filter (lambda (x) (> x 20)) '(10 30 15 10 80))

(30 80)

The most efficient way, in terms of the execution time, to check whether a list L is empty is by what in Scheme?

(NULL? L)

Assume that you have (define x '(5)) and (define y '(8 9)). What operations will return the list (5 8 9)?

(append x y)

What is the output of the below code? int main() { int a[5] = (3, 1, 5, 20, 25}; int i, j, m; i = *(a + 1) -1; j = a[1] +1; m = a[j] + a[i]; printf("%d, %d, %d", i, j, m); }

0, 2, 8

Match the following: 1) Data Type 2)Variable 3) Constant 4) Pointer A) Fixed value that the program may not alter during its execution. B) A classification that specifies which type of value a variable has and what type of mathematical, relational or logical operators. C) A name given to a storage location that stores an address. D) A name given to a storage location

1 - B 2 - D 3 - A 4 - C

The syntactic structure of imperative programming languages normally include which of the following units

1) conditional statements 2) loop statements 3) variable declaration

Features of the functional paradigm includes:

1) expresses computations in terms of mathematical functions 2) simpler semantics

The lexical structure of all programming languages are similar and normally include which of the following units

1) identifiers 2) keywords 3) operators 4) literals

Features of the object-oriented paradigm includes:

1) inheritance 2) classes and objects

A deep-filter can be used in the situation where the list A) contains sublists, or B) is a plain list.

A

Defining a virtual function in class means that the function A) can be redefined in its child classes, or B) is an interface only and not allowed implementation.

A

Given the following snippet of C++ code: string name = "Hello"; ifstream myFile; myFile.open(myFile); myFile >> name; myFile.close(); What does it do? A) It loads the word Hello from a file in the file system, or B) It reads a word from the keyboard.

A

If a member function in a class A is defined as a virtual function, then the member function A) can be re-defined in a derived class, or B) cannot be defined in class A.

A

If class B is derived from class A, and two pointers p and q are declared by "A *p; B *q;" which operation is valid according to polymorphism? A) p = q;, B) q = p;, C) both, or D) neither

A

If the relation between two C++ classes can be best described as "has-a" relation, we should A) contain one class in the other (containment), or B) derive one class from the other (inheritance).

A

Lazy evaluation evaluates A) a parameter of a function only if it is necessary, or B) all parameters of a function first.

A

Normally, a recursive procedure can be written by following these steps: Define the size-n problem, find the solution for the base case or the stopping condition, and then, find the solution of the A) size-n problem based on the hypothetical solution of the size-(n-1) problem, or B) size-(n-1) problem, and finally find the solution of the size-n problem.

A

The class hierarchy of a C++ program is formed according to the A) inheritance relationship among class, or B) number of data fields in classes.

A

Which of the following is NOT a Scheme pair? A) '(), or B) '(x . y)

A

Which of the following is a valid Scheme form? A) (* 9 (/ (- 4 2) 7)), or B) 9 * (4 - 2)/7

A

What is a data type?

A set of primary values and the operations defined on these values

What is a programming paradigm?

A set of principles, concepts, and methods that is commonly accepted by members of a group or community.

Consider C++'s typing system. C++ uses (Select all correct answers): A) both value semantics and reference semantics for its object types, B) both value semantics and reference semantics for its primitive types, C) reference semantics for its object types only, and/or D) value semantics for its primitive types only.

A, B

In C++, if class B is derived from class A, then without casting, a pointer to a class (A, B) object can point to a class (A, B) object.

A, B

If you want to create a linked list of Container nodes, which can contain Publication node, Book node, Thesis node, and Report node, what type of pointer should be declared in the Container to point to all these nodes? [A pointer to (Book, Publication) node]

Publication

Type checking during compilation will prevent a base-class pointer from accessing the _____ of the derived class object.

additional members

What type of values can a throw-statement throw (return)? [object types, primitive types, string types, all of the above]

all of the above

Each let-form in Scheme can be converted into what?

an unnamed procedure

If class B is derived from class A, and x is a protected member of A, in which classes can x be accessed? (A, B, both, neither)

both

What mechanism cannot be used for passing a value into a Scheme procedure?

call-by-alias

How is a procedure name (operator) passed into a procedure?

call-by-name

What is the best way to delete an array created by "p = new StructType[size];" in C++?

delete[] p;

If a function calls another function, the local variables in these two functions use the memory from (different, the same) stack frame(s).

different

What type casting mechanism should be used if you want to change an object of one class to an object of a different class?

dynamic_cast

What type casting mechanism should be used if you want to change pointer type for pointing to a different object in an inheritance hierarchy?

dynamic_cast

In addition to functional programming, what other ideas are originated by John McCarthy?

e-commerce, space fountain

Features of the logic paradigm includes:

expressing computation in terms of logic predicates

The compiler executes the program

false

Which of the following are NOT primitive data types in C? int, short, long, char, String, bool, float, double.

short, long, String, bool

What type casting mechanism should be used if you want to cast an integer value to a double value?

static_cast

What is the function of throw statement? [exit from a _____ and pass a value to the _____]

try-block, catch-block

The exception handling mechanism discussed in this course is at the level of (hardware, user).

user

Given the following class definition and the variable declaration: class employee char *name; long id; } class manager { employee empl; char* rank; } x How do you set an x's employee's ID to 12345?

x.empl.id = 12345;

Can a multithreading program take a longer time than a single thread program that solves the same problem?

yes

In the implementation of the getMax() function in the PriQueue class, we need to read and write the variables "front" and "rear", which are defined as protected members in the base class Queue. Are the functions in the derived class allowed to access the protected members in the base class?

yes

In the C++ exception structure, how many handlers can be defined following each try-block?

zero or more

Interpretation of a program is the direct execution of one statement at a time sequentially.

True

It is true or false the following statement: A programming language can belong to multiple paradigms

True

The following code is correct and print "Hello" if ( 2 + 2 + 2 + 2) { if (1) { printf("Hello"); } }

True

char, unsigned char, signed char and int are all numeric (integer) types in C programming.

True

What notation requires parentheses in order to correctly define the order of computation?

infix notation

If the relationship between two classes can be best described as an "is-a" relation, we should use _____.

inheritance

A virtual member function in C++ implies (early, late) binding between the function name and the code.

late

What operations will acquire memory from heap? (declaration, free, malloc, new)

malloc, new

In imperative languages, different orders of evaluations (eager or lazy) (always, may, never) produce different results.

may

In functional languages, different orders of evaluations (eager or lazy) (always, may, never) produce different results.

never

In Scheme, is an empty list a pair?

no

The semantics of multiple inheritance becomes complex and error prone, if the base classes have (members with different names, overlapped members).

overlapped members

Compilation of a program is to execute all the statements of the program completely.

False

Functional programming languages are low-level languages

False

Is the following statement true or false? Prolog is a functional programming language

False (Prolog is a logic programming language)

What is printed on screen after running this program int main() { int i = 0; char a[] = "H2o2"; while (a[i] != '\0') { *(a+1) = *(a + i) + 2; i++; } char *q; q = a; q[2] = '#'; printf("%s", a); return 0; }

H4#2

This programming language uses two-step translation with intermediate codes for execution.

Java

During compilation, all the statements of a program in a high-level language are converted (translated) to a low-level language (such as assembly language).

True

What is the output of the below code? int fun(int n) { if (n == 4) return n; else return 2*fun(n+1); } int main() { printf("%d ", fun(3)); return 0; }

8

Considering the following code struct emp { int id; char *name; }; struct emp john; Which of the following lines are correct? 1) int a = 1; char b[ ] = "John Doe"; john.id = a; john.name = b;\ printf ("%d, %s", john.id, john.name); 2) int a = 1; char b[ ] = "John Doe"; emp.id = a; emp.name = b; printf ("%d, %s", emp.id, emp.name); 3) int a = 1; char b[ ] = "John Doe"; john.id = b; john.name = a; printf ("%d, %s", john.id, john.name); 4) int a = 1; char b[ ] = "John Doe"; john[0].id = a; john[0].name = b; printf ("%d, %s", john[0].id, john[0].name);

1) int a = 1; char b[ ] = "John Doe"; john.id = a; john.name = b;\ printf ("%d, %s", john.id, john.name);

Features of the imperative or procedural paradigm includes:

1) manipulation of named data (variables) 2) conditional statements

The semantic structure of imperative programming languages normally include which of the following validations

1) unicity 2) type matching 3) parameters type in a function declaration should match those in the function call

Which of the following programs are correct in C? 1) typedef int booOoolean; typedef char FlagType; int main() { booOoolean x = 0; int counter; FlagType xx = 'A'; } 2) typedef enum {false, true} booOoolean; typedef enum {Sun, Mon, Tue, Wed, Thu, Fri, Sat} days; int main() { booOoolean a = false; int counter; days x = Mon, y = Fri; while (x != y) x++; } 3) typedef enum { red, amber, green} traffic_light; main( ) { traffic_light x = red; while (1) switch (x) { case amber: x = red; printf("R"); break; case red: x = green; printf("G"); break; case green: x = amber; printf("A"); break; } }

1, 2, 3

Which of the followings are correct declarations of the main() method (i.e., the entry point of a program)? 1) void main () {d} 2) void main (int argc, char *argv [ ]) {} 3) int main() { return 0; } 4) main() { return 0; } 5) int main (int argc, char *argv [ ]) {} 6) public static void main (string [ ] argv ) {}

1, 2, 3, 4, 5

Given the following struct: struct contact { char name[32]; int phone; char email[32]; }; Which code can be used to create a contact and store data ? 1) struct contact x; scanf("%s", x.name); scanf("%d", x.phone); scanf("%s", x.email); 2) struct contact x; scanf("%s", x.name); scanf("%d", &x.phone); scanf("%s", x.email); 3) struct contact x; scanf("%s", &x.name); scanf("%d", &x.phone); scanf("%s", &x.email); 4) struct contact x; scanf("%s", &x.name); scanf("%d", x.phone); scanf("%s", &x.email);

2) struct contact x; scanf("%s", x.name); scanf("%d", &x.phone); scanf("%s", x.email);

What does the below program print on the screen? int main() { int i=3, *j, k; j=&i; printf("%d\n", i**j*i-*j); return 0; )

24

Which of the following lines print a "-15" on the screen 1) int x = -15; printf("%p", &x); 2) int x = -15; int *point = &x; printf("%d", &x); 3) int x = -15; int *point = &x; printf("%p", point); 4) int x = -15; int *point = &x; printf("%d", *point);

3) int x = -15; int *point = &x; printf("%p", point);

What will (caddr '(2 4 6 8 10)) return in Scheme?

6

What does the following line of code define? Days operator++(int)

An overloaded operator ++

"Map and Reduce" is a concept for defining A) generic type, or B) parallel computing process.

B

Eager evaluation evaluates A) a parameter of a function only if it is necessary, or B) all parameters of a function first.

B

If A is the base class and B is a class derived from A, then class A) A becomes a member in class B, or B) B has all the members of class A.

B

If you want to return multiple values from a Scheme procedure, which of these methods is invalid? A) Put the values in a pair and return the pair, or B) Use multiple return statements

B

Java programmers do not need to do garbage collection because Java A) does not use heap memory, or B) uses a system program to collect garbage.

B

One of the major differences between the imperative and functional programming languages is that the functional programming languages do NOT A) allow a procedure to return a value, or B) have side effects.

B

What is a generic type? A) A type that can take different type of values at the same time, or B) The type can be determined at run time.

B

What is the best way of deleting a linked list of objects in C++? A) head = 0; or B) Use a loop to delete every object in the linked list.

B

What is the key difference between a static variable and a global variable? A) They come from different parts of memory, or B) They have different visibility.

B

Which of the following forms is an unnamed procedure? A) (+ z 3), or B) ((lambda (z) (+ z 3)) 4)

B

Why do we need the spin synchronization at the end of a MapReduce process? A) To improve the performance of multithreading, or B) To make sure that all the threads complete their tasks

B

In a C Program, which of the following is true:

C allows empty parameters or two parameters for main.

What kind of error is in the following line:- int a = ((2*45)*(6/2) hello (4+90));

Syntactic Error

In C, when you pass an array as a parameter to a function, what is actually passed?

The address of the first element in the array

What is a similarity between a struct and enum?

They let you define new data types

What part of memory can be de-allocated by the destructor?

heap memory created in the constructor

What part of memory must be de-allocated by an explicit "delete" operation?

heap object created in main function

What memory must be garbage collected by a destructor? (_____ memory created by _____ (in the same, outside) the class)

heap, constructors, in the same

What is printed by the following code? int i = 10; int bar(int m, int *n) { printf("i = %d k = %d l = "d\n", i, m, *n); } int foo(int k, int *l) { printf("i = %d k = %d l = "d\n", i, k, *l); k = 3; *l = 4; bar(k, l); } int main() { int k = 15; foo(j, &i); printf("i = %d j = "d\n", i, j); return 0; }

i = 10 k = 15 l = 10 i = 4 k = 3 l = 4 i = 4 j = 15

What is printed by the following code? void foo(int *n) { *n = 30; } void main() { int i = 15; foo(&i); printf("i = %d\n", i); i = 10; foo(&i); printf("i = %d\n", i); }

i = 30 i = 30


Related study sets

Chapter 10 Hmwk and Quiz questions

View Set

Psychiatric-Mental Health Practice Exam HESI

View Set

What three structures make up the bacterial cytoskeleton and what are they used for? Which are used in eukaryotic flagella? Which are used in pseudopodia motility?

View Set

Texas Promulgated Contract Forms: Ch. 7 Quiz

View Set