Quiz 4, Quiz 3, Quiz 2, final

Réussis tes devoirs et examens dès maintenant avec 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? (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

Given this class definition class Rectangle { private: int width, height; public: void set_values (int,int); int area (); }; Which of the following instruction(s) create an array of 2 Rectangles and initialize all the 3 of them with values. Select ALL the possible options. 1) Rectangle a[2]; a[0].set_values(1,1); a[1].set_values(2,2); 2) Rectangle *a[2]; a[0] = new Rectangle; a[0]->set_values(1,1); a[1] = new Rectangle; a[1]->set_values(2,2); 3) Rectangle *a = new Rectangle[2]; a[0]->set_values(1,1); a[1]->set_values(2,2); 4) Rectangle a = new Rectangle[2]; a[0].set_values(1,1); a[1].set_values(2,2);

1) Rectangle a[2]; a[0].set_values(1,1); a[1].set_values(2,2); 2) Rectangle *a[2]; a[0] = new Rectangle; a[0]->set_values(1,1); a[1] = new Rectangle; a[1]->set_values(2,2);

Which of the following options is the code in C++ for a) A class Student that inherits from a class Person. b) A constructor in Student that calls (is able to call) a constructor in Person * When the body of the method is not relevant to answer the question, it has been replaced for a comment // code 1) class Person { public: Person() { //code } Person(char* lName, int year) { // code } private: char* lastName; int yearOfBirth; }; class Student : public Person { public: Student() { //code } Student(char* lName, int year, char* univer) :Person(lName, year) { //code } private: char *university; }; 2) class Person { public: Person() { //code } Person(char* lName, int year) : Student (char* lName, int year, char* univer) { // code } private: char* lastName; int yearOfBirth; }; class Student : public Person { public: Student() { //code } Student(char* lName, int year, char* univer) { //code } private: char *university; }; 3) class Person { public: Person() { //code } Person(char* lName, int year) { // code } private: char* lastName; int yearOfBirth; }; class Student extends Person { public: Student() { //code } Student(char* lName, int year, char* univer) { Person(lName, year); //code } private: char *university; }; 4) class Person { public: Person() { //code } Person(char* lName, int year) { // code } private: char* lastName; int yearOfBirth; }; class Student : public Person { public: Student() { //code } Student(char* lName, int year, char* univer) { Person(lName, year); //code } private: char *university; };

1) class Person { public: Person() { //code } Person(char* lName, int year) { // code } private: char* lastName; int yearOfBirth; }; class Student : public Person { public: Student() { //code } Student(char* lName, int year, char* univer) :Person(lName, year) { //code } private: char *university; };

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

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

Which lines in C++ are equivalent to this code in Java int x =5; char a = 'A'; System.out.print( "Hello " + x + ", " + a ); 1) int x =5; char a = 'A'; cout << "Hello " << x << ", " << a 2) int x =5; char a = 'A'; cout << "Hello %d , %c" << x << a ; 3)int x =5; char a = 'A'; cout ("Hello %d , %c", x , a ); 4) int x =5; char a = 'A'; cout >> "Hello " >> x >> ", " >> a ;

1) int x =5; char a = 'A'; cout << "Hello " << x << ", " << a

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

In the following code, how many times the destructor of the class "Derived" is executed? class Base { public: Base(int n) { cout << "Base constructor" << endl; } void function() { cout << "function" << endl; } ~Base() { count << "Base destructor" << endl; } }; class Derived : public Base { public: Derived(int n) : Base(n) { cout << "Derived constructor" << endl; } ~Derived() { cout << "Derived destructor" << endl; } }; int main() { Derived myPQ1(50); myPQ1.function(); myPQ1.function(); Derived *myPQ2; myPQ2 = new Derived(50); myPQ2->function(); myPQ2->function(); delete myPQ2; )

2

Running the following program. How many times will "good bye" be printed on the screen? class CSE { public: CSE(int v) { cout << "constructor\n"; } void add(int v) { cout << "adding\n"; } int remove() { cout << "removing\n"; return 0; } ~CSE() { cout << "good bye!\n"; } }; int main() { CSE q1(5); CSE *q2 = new CSE(5); //Access Object q1.add(2); q1. add(8); //Access Object Pointer q1.remove(); q2->remove(); delete q2; return 0; }

2

Which of the following classes creates and initializes correctly an static variable in C++? 1) class Something { public: static int v; }; v = 1; 2) class Something { public: static int v; }; int Something::v = 1; 3) class Something { public: static int v; }; Something::v = 1; 4) class Something { public: static int v; }; int v = 1;

2) class Something { public: static int v; }; int Something::v = 1;

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

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

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

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

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

An overloaded operator ++

The principle behind the object-oriented paradigm consists of a number of programming concepts, which does not include the following: Classes, Inheritance, Polymorphism, Arrays, Pointers

Arrays and Pointers

"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

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

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.

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

False

Functional programming languages are low-level languages

False

In C++, implementations of member functions cannot be inside the class definition (for short functions) or outside of the class definition.

False

The scope resolution operator (::) is used to overload a function or an operator in object-oriented paradigm.

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

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

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

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

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

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

Features of the logic paradigm includes:

expressing computation in terms of logic predicates

The compiler executes the program

false

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

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

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

overlapped members

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

The following declaration allows all elements in the standard C++ library to be accessed in an unqualified manner (without the std:: prefix)

using namespace std;

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


Ensembles d'études connexes

Chapter 6- Relationships and Guidance

View Set

BAH - Chapter 35 & 36 Musculoskeletal

View Set

Canada: Geography and Where People Live and Trade

View Set

HESI Live Review Workbook for NCLEX-RN Exam

View Set

Chapter 52: Nursing Care of the Child with a Cognitive or Mental Health Disorder

View Set

Chapter 15: Assessing Head and Neck

View Set