Final exam Flashcards

(135 cards)

1
Q

What is printed by the following code?
int main () {
int array[5] = {10,30,50,70,90};
int p = array;
cout &laquo_space;(p+1) + (&
p) + 1; return 0;
}

A

41

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the value in the variable Exam::total that is printed when this program is executed?
#include<iostream>
using namespace std;</iostream>

class Exam {
public:
static int total;
Exam() {
total++; }
};

int Exam::total = 0;

int main(){
Exam a, b, c;
Exam d, e, *f = new Exam;
cout &laquo_space;Exam::total;
}

A

4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

a delete instruction is needed before the main() ends.
Which of the following options is correct?
#include<iostream>
using namespace std;</iostream>

class MyClass {
public:
MyClass() {cout &laquo_space;“MyClass constructed\n”;}
~MyClass() {cout &laquo_space;“MyClass destroyed\n”;}
};
int main(){
MyClass * pt = new MyClass[3];
return 0;
}

A

delete [] pt;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

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

parameters type in a function declaration should match these in the function call.

division by zero

statement should end with a ‘;’

unicity

a variable name should start with a letter, ‘$’ or ‘_’

type matching

A

parameters type in a function declaration should match these in the function call.

unicity

type matching

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

The syntactical structure of the imperative programming language reviewed in this course include which of the following validations

unicity

statement should end with a ‘;’

type matching

a variable name should start with a letter, ‘$’ or ‘_’

division by zero

parameters type in a function declaration should match these in the function call.

A

statement should end with a ‘;’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

include<iostream></iostream>

Running the following program,
How many times the message “constructing” is printed on the screen?

using namespace std;

class Rectangle {
public:
Rectangle(){
cout «“constructing”«endl;
}
~Rectangle()
{cout «“destructing”«endl;
}
};
class Box : public Rectangle {
public:
Box(){
cout «“constructing”«endl;
}
~Box()
{cout «“destructing”«endl;
}
};

int main(){
Box * a = new Box[5];
delete[] a;
return 0;
}

A

10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Features of the logic paradigm includes

expressing computation in terms of logic predicates

using lambda calculus

classes and objects

expressing computation in terms of boolean expressions

A

expressing computation in terms of logic predicates

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Which of the following options is the code in C++ for
A class Student that inherits from a class Person.
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

A

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 n, int y, char u):Person(n, y) {
//code
}
private:
char *university;
};

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

include<stdio.h></stdio.h>

What is printed on screen after running this program?
Be careful, do not add extra characters, not even spaces, unless they are part of your answer.

void main () {
int i = 0;
char a[] = “2020”;
while (a[i] != ‘\0’) {
(a + i) = (a + i) + 1;
i++;
}
char *q = a;
q[2]=’B’;
printf(“%s\n”, a);
}

A

31B1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

The Java programming language is weakly typed

A

FALSE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is printed on screen after running this code?

int main () {
int Employees[3][3] = {{10,20,30},{1,2,3},{15,25,35} };
cout &laquo_space;Employees[2][1] - Employees[1][2] ;
return 0;
}

A

22

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

include<iostream></iostream>

What is printed after running this program?

using namespace std;

class GrandPa {
public:
virtual void foo() {
cout«“Hi, I am a GrandPa”&laquo_space;endl;
}
};

class Dad : public GrandPa {
public: void foo() {
cout«“Hi, I am a Dad”&laquo_space;endl;
}
};

class Kid : public Dad {
public: void foo() {
cout«“Hi, I am a Kid”&laquo_space;endl;
}
};

int main(){
GrandPa * john = new Kid;
john -> foo();
delete john;
return 0;
}

A

Hi, I am a Kid

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

include<stdio.h></stdio.h>

What is printed by the following code?

int i=1;

void foo(int m, int *n){
printf(“i= %d m = %d n = %d\n”, i, m, *n);
i = 5; m = 3; *n = 4;
printf(“i= %d m = %d n = %d\n”, i, m, *n);
}

void main () {
int j = 2;
foo(j, &i);
printf(“i= %d j = %d\n”, i, j);
}

A

i = 1 m = 2 n = 1
i = 4 m = 3 n = 4
i = 4 j = 2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

It is used to define an alternative name for an existing type:

enum
typedef
define
struct

A

typedef

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Match the line with the error type (lexical, syntactic, or semantic) or with “correct” when there are no errors (lexical, syntactic, or semantic) in the line

int $ = 1; // in C/C++

char @ = ‘A’; // in C/C++

if = 5; // in C/C++

int If = (1<2 <3); // in C/C++

int If = (1<2 <3); // in Java

int x = 0/1; // Java

A

correct

Lexical Error

Syntactic error

correct

semantic

correct

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

include<iostream></iostream>

What is printed on screen when you run the following program?

using namespace std;

void recursive(int x) {
if (x<5) {
cout &laquo_space;x;
recursive(x+1);
cout &laquo_space;“B”;
}
else {
cout &laquo_space;“A”;
}
}

int main(){
recursive(1);
}

A

1234ABBBB

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

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 ?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is printed on the screen after executing the lines below (in your personal computer)?

int x[4] = {1, 2, 3, 0}; printf(“%d”,sizeof x) ;

A

16

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Lexical rules of Java and C/C++ languages include which of the following validations

unicity

division by zero

a variable name should start with a letter, ‘$’ or ‘_’

statement should end with a ‘;’

type matching

parameters type in a function declaration should match these in the function call.

A

a variable name should start with a letter, ‘$’ or ‘_’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Which of the following rules defines
“ if X is instructor of the course C and Y is enrolled in the course C then X teaches Y”

instructor(P,C), enrolled(S,C) :-teaches(P,S).
teaches(P,S) :- instructor(P,C); enrolled(S,C).
teaches(P,S) :- instructor(P,C), enrolled(S,C).
instructor(P,C); enrolled(S,C) :-teaches(P,S).

A

teaches(P,S) :- instructor(P,C), enrolled(S,C).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

T or F

Logic programming describes what the problem is by a set of conditions and constraints, and leaves the computer to match the problem to the existing knowledge of facts and rules and to find solutions to the problem.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Which rules in Prolog match the following definition of a bad dog:

A dog is bad if it bites the postman, chews the newspaper, or chases the cat.

bad_dog(Dog) :- is_dog(Dog); bites(Postman). bad_dog(Dog) :- is_dog(Dog); chews(Newspaper). bad_dog(Dog) :- is_dog(Dog); chases(Cat).

is_dog(Dog), bites(Dog, Postman), is_postman(Postman):-bad_dog(Dog). is_dog(Dog), chews(Dog, Newspaper), is_newspaper(Newspaper):-bad_dog(Dog). is_dog(Dog), chases(Dog, Cat), is_cat(Cat):-bad_dog(Dog).

bad_dog(Dog) :- is_dog(Dog), bites(Dog, Postman), is_postman(Postman). bad_dog(Dog) :- is_dog(Dog), chews(Dog, Newspaper), is_newspaper(Newspaper). bad_dog(Dog) :- is_dog(Dog), chases(Dog, Cat), is_cat(Cat).

bad_dog(Dog) :- is_dog(Dog); bites(Postman); is_postman(Postman). bad_dog(Dog) :- is_dog(Dog); chews(Newspaper); is_newspaper(Newspaper). bad_dog(Dog) :- is_dog(Dog); chases(Cat); is_cat(Cat).

A

bad_dog(Dog) :- is_dog(Dog), bites(Dog, Postman), is_postman(Postman). bad_dog(Dog) :- is_dog(Dog), chews(Dog, Newspaper), is_newspaper(Newspaper). bad_dog(Dog) :- is_dog(Dog), chases(Dog, Cat), is_cat(Cat).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Write this statement as a Prolog clause.
If weather is cold, everyone likes it.

weather(cold) :-everyone(likes).

likes(weather, everyone):-cold(weather).

cold(weather), likes(X).

likes(X, weather) :- cold(weather).

A

likes(X, weather) :- cold(weather).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Write in Prolog the question “Which food is meal and lunch?”

meal(X); lunch(X).
meal(X). lunch(X).
meal(X):- lunch(X).
meal(X), lunch(X).

A

meal(X), lunch(X).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Given the following fact and rule. (some extra white-spaces has been added to facilitate reading) fun(1, 2). fun(N, F) :- N>0, N1 is N - 1, fun(N1, F1), F is N * F1. What is the result of the query? ?- fun (1,2).
true
26
Prolog is based on Turing machine Boolean logic Predicate logic Lambda calculus
Predicate logic
27
?- 10 + 5 is 15. How will prolog respond to this query?
false
28
15 is 10 + 5. How will Prolog respond to this query?
true
29
Given the following facts. instructor(john,cse300). instructor(mary,cse400). instructor(paul,cse500). enrolled(joseph,cse300). enrolled(joseph,cse400). enrolled(joseph,cse500). enrolled(james,cse300). enrolled(james,cse500). Which query provides a list of all the students enrolled in cse300? enrolled(Who, cse300). enrolled(cse300, Who). X is enrolled cse300. enrolled(cse300).
enrolled(Who, cse300).
30
What is the value returned for the following LISP expression (+ 1 (if (< 2 1) (* 3 3) 6 ) )
7
31
Is the following line correct in LISP ( + 1 2 3 4 5 6 7 8 9 0)
true
32
What is printed by the print instruction in the second line? (setf theList '(2 3 7 9 10) ) (print (first ( rest theList ) ) )
3
33
functions are created by calling a function-making macro. This macro is called
define
34
What is equivalent code in C++ for the following LISP statement (if (< 1 2) (* 3 4) (/ 5 6) )
if (1 < 2) return 3 * 4; else return 5 / 6;
35
What is printed on the screen by the print instruction in the code below?
(print ( and (< (* 3 5 ) ) ( not (>= 4 6 ) ) ))
36
What is the last value printed on the screen after running the following LISP code? (setf num 1) (dotimes (x 3) (setf num (+ num num) ) ) (print num)
8
37
t or f One feature of the functional paradigm is a higher level of abstraction compared with Imperative and Object-Oriented paradigms
true
38
Which of the following lines (in Java, C, or C++) is equivalent to this expression in LISP (- (* 1 2) (+ 3 4) (/ 5 6) 7 )
(1 * 2) - (3 + 4) - (5 / 6) - 7
39
Which of the following lines represent in LISP the operation of 3 multiplied by 4?
(* 3 4)
40
Running the following program. How many times will the message "good bye!" be printed on the screen? #includeusing namespace std;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); q1.add(2); q1.add(8); q1.remove(); q2->remove(); delete q2; return 0;}
2
41
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;
42
In the following code, how many times the destructor of the class "Base" is executed? #includeusing namespace std;class Base { public: Base(int n) { cout<<"Base Constructor\n"; } void function() { cout<<"function\n"; } ~Base() { cout<<"Base destructor\n"; }};class Derived : public Base { public: Derived(int n) : Base(n) { cout<<"Derived Constructor\n"; } ~Derived() { cout<<"Derived destructor\n"; }};int main(){ Derived myPQ1(50); myPQ1.function(); Derived *myPQ2 = new Derived(50); myPQ2->function(); delete myPQ2; return 0;}
2
43
Given the following 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 them (the 2 Rectangles) with values. Select ALL the possible options. Rectangle *a[2]; a[0] = new Rectangle; a[0]->set_values(1,1); a[1] = new Rectangle; a[1]->set_values(2,2); Rectangle *a = new Rectangle[2]; a[0]->set_values(1,1); a[1]->set_values(2,2); Rectangle a[2]; a[0].set_values(1,1); a[1].set_values(2,2); Rectangle a = new Rectangle[2]; a[0].set_values(1,1); a[1].set_values(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); Rectangle a[2]; a[0].set_values(1,1); a[1].set_values(2,2);
44
The scope resolution operator (::) is used to overload a function or an operator in object-oriented paradigm. true or false
false
45
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
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; };
46
Which of the following classes creates and initializes correctly an static variable in C++? class Something { public: static int v; }; int v = 1; class Something { public: static int v; }; v = 1; class Something { public: static int v; }; int Something::v = 1; class Something { public: static int v; }; Something::v = 1;
class Something { public: static int v; }; int Something::v = 1;
47
The principle behind the object-oriented paradigm consists of a number of programming concepts, which does not include the following: Polymorphism Inheritance Classes Pointers Arrays
Pointers Arrays
48
Which lines in C++ are equivalent to this code in Java int x = 5;char a = 'A';System.out.print( "Hello " + x + ", " + a ); int x =5; char a = 'A'; cout ("Hello %d , %c", x , a ); int x =5; char a = 'A'; cout << "Hello %d , %c" << x << a ; int x =5; char a = 'A'; cout >> "Hello " >> x >> ", " >> a ; int x =5; char a = 'A'; cout << "Hello " << x << ", " << a ;
int x =5; char a = 'A'; cout << "Hello " << x << ", " << a ;
49
In C++, implementations of member functions cannot be inside the class definition (for short functions) or outside of the class definition. t or f
false
50
What is printed by the following code? #include int foo(int *n) { *n = 30; } int main() { int i=15; foo(&i); printf("i=%d\n",i); i=10; foo(&i); printf("i=%d\n",i); return 0; } i = 30 i = 30 i = 10 i = 10 i = 15 i = 15 i = 15 i = 10
i = 30 i = 30
51
Which of the following are NOT primitive data types in C? String bool short char double float long int
String bool short long
52
In a C Program, which of the following is true: C allows one parameter or two parameters for main. C allows empty parameters or two parameters for main. C allows more than two parameters for main. C allows only one parameter for main.
C allows empty parameters or two parameters for main.
53
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 All the values in array The value of the first element in the array An array cannot be passed as a parameter to a function
The address of the first element in the array
54
Printing format for memory addresses
%p
55
Printing format for strings of characters
%s
56
Printing format for characters
%c
57
Printing format for floating point values
%f
58
Printing format for integer values
%d
59
What is the output of the below code? #include 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); return 0; }
0,2,8
60
What is printed by the following code? #include 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 j = 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 i = 4 k = 3 l = 4 i = 4 j = 15 i = 10 k = 15 l = 10 i = 10 k = 3 l = 10 i = 10 j = 15 i = 10 k = 15 l = 10 i = 10 k = 3 l = 4 i = 10 j = 15
i = 10 k = 15 l = 10 i = 4 k = 3 l = 4 i = 4 j = 15
61
What is the output of the below code? #include int fun (int n) { if (n == 4) return n; else return 2*fun(n+1); } int main() { printf("%d", fun(3)); return 0; }
8
62
char, unsigned char, signed char and int are all numeric (integer) types in C programming. true or false
true
63
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 ? struct contact x; scanf("%s", x.name); scanf("%d", &x.phone); scanf("%s", x.email); struct contact x; scanf("%s", x.name); scanf("%d", x.phone); scanf("%s", x.email); struct contact x; scanf("%s", &x.name); scanf("%d", x.phone); scanf("%s", &x.email); struct contact x; scanf("%s", &x.name); scanf("%d", &x.phone); scanf("%s", &x.email);
struct contact x; scanf("%s", x.name); scanf("%d", &x.phone); scanf("%s", x.email);
64
What does the below program print on the screen? #include int main() { int i=3, *j, k; j=&i; printf("%d\n",i*ji-*j); return 0; }
24
65
Which of the followings are correct declarations of the main() method (i.e., the entry point of a program)? void main () { } void main (int argc, char *argv [ ]) { } int main() { return 0; } int main (int argc, char *argv [ ]) { return 0; } public static void main (string [ ] argv ) { } main() { return 0; }
void main () { } void main (int argc, char *argv [ ]) { } int main() { return 0; } int main (int argc, char *argv [ ]) { return 0; } main() { return 0; }
66
Considering the following code struct emp { int id; char *name; }; struct emp john; Which of the following lines are correct? int a = 1;char b[ ] = "John Doe";john[0].id = a;john[0].name = b;printf ("%d, %s", john[0].id, john[0].name); int a = 1;char b[ ] = "John Doe";emp.id = a;emp.name = b;printf ("%d, %s", emp.id, emp.name); int a = 1;char b[ ] = "John Doe";john.id = b;john.name = a;printf ("%d, %s", john.id, john.name); int a = 1;char b[ ] = "John Doe";john.id = a;john.name = b;printf ("%d, %s", john.id, john.name);
int a = 1;char b[ ] = "John Doe";john.id = a;john.name = b;printf ("%d, %s", john.id, john.name);
67
What is printed on screen after running this program #include int main() { int i=0; char a[ ] = "H2o2"; while(a[i] != '\0') { (a+1)= (a+i) + 2; i++; } char *q = a; q[2] = '#'; printf("%s", a); return 0; }
H4#2
68
The following code is correct and print "Hello" if ( 2 + 2 + 2 + 2) if (1) printf("Hello"); true or false
true
69
Which of the following lines print a "-15" on the screen int x = -15;int *point = &x;printf("%p", point); int x = -15;int point = &x;printf("%d", point); int x = -15;int *point = &x;printf("%d", &x); int x = -15;printf("%p", &x);
int x = -15;int point = &x;printf("%d", point);
70
Which code in C is equivalent to this code in Java int x = 5; float y = 10.3f; System.out.println("hello " + x + " bye " + y); int x = 5; float y = 10.3; printf("hello %d bye %f", &x, &y); int x = 5; float y = 10.3f; printf("hello %i bye %f", x, y); int x = 5; float y = 10.3; printf("hello %d bye %f", x, y); int *x = 5; float *y = 10.3; printf("hello %p bye %p", x, y);
int x = 5; float y = 10.3f; printf("hello %i bye %f", x, y);
71
What is the output of the following program? #include typedef enum week{Mon, Tue, Wed, Thur, Fri, Sat, Sun} WEEK; int main() { WEEK day; day = Wed; printf("%d",day); return 0; }
2
72
This programming language uses two-step translation with intermediate codes for execution.
java
73
T or F The compiler executes the program
F
74
The syntactic structure of imperative programming languages normally include which of the following units operators keywords identifiers conditional statements loop statements variable declaration
conditional statements loop statements variable declaration
75
What kind of error is in the following line:- int a = ((245)(6/2) hello (4+90));
syntax
76
Functional programming languages are low-level languages true or false
false
77
The lexical structure of all programming languages are similar and normally include which of the following units identifiers loop statements keywords operators literals variable declaration
identifiers keywords operators literals
78
What is a data type? a specialized format for organizing and storing data a storage location paired with an associated symbolic name a piece of information a set of primary values and the operations defined on these values
a set of primary values and the operations defined on these values
79
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 or false
true
80
Interpretation of a program is the direct execution of one statement at a time sequentially. true or false
true
81
The semantic structure of imperative programming languages normally include which of the following validations type matching division by zero a variable name should start with a letter, '$' or '_' parameters type in a function declaration should match these in the function call. statement should end with a ';' unicity
type matching parameters type in a function declaration should match these in the function call. unicity
82
Logic programming languages divide the program into reasonable sized pieces named functions or procedures or modules or subroutines. true or false
false
83
It is true or false the following statement: A programming language can belong to multiple paradigms true or false
true
84
Is the following statement true or false? Prolog is a functional programming language
false
85
Features of the functional paradigm includes simpler semantics polymorphism expresses computations in terms of logic predicates expresses computations in terms of mathematical functions
expresses computations in terms of mathematical functions simpler semantics
86
Features of the imperative or procedural paradigm includes encapsulation manipulation of named data (variables) classes and objects conditional statements
manipulation of named data (variables) conditional statements
87
Features of the object-oriented paradigm includes classes and objects inheritance lambda calculus logic predicates
classes and objects inheritance
88
Interpretation of a program is the direct execution of one statement at a time sequentially. true or false
true
89
Features of the logic paradigm includes classes and objects using lambda calculus expressing computation in terms of boolean expressions expressing computation in terms of logic predicates
expressing computation in terms of logic predicates
90
What is a programming paradigm? A programming language is a paradigm. A common set of hardware instructions for a specific kind of hardware A set of principles, concepts, and methods that is commonly accepted by members of a group or community. A mathematical model
A set of principles, concepts, and methods that is commonly accepted by members of a group or community.
91
What is a similarity between a struct and enum
They let you define new data structures
92
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
93
What operations will acquire memory from heap? (declaration, free, malloc, new)
malloc new
94
If a function calls another function, the local variables in these two functions use the memory from (different, the same) stack frame(s).
different
95
What is the best way to delete an array created by "p = new StructType[size];" in C++?
delete [] p;
96
What memory must be garbage collected by a destructor? (_____ memory created by _____ (in the same, outside) the class)
heap, constructors, in the same
97
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
98
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
99
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
100
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
101
The semantics of multiple inheritance becomes complex and error prone, if the base classes have (members with different names, overlapped members).
overlapped members
102
The semantics of multiple inheritance becomes complex and error prone, if the base classes have (members with different names, overlapped members). overlapped members 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
103
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
104
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 class definition and the variable declaration:class employeechar name;long id;}class manager {employee empl;char rank;} xHow do you set an x's employee's ID to 12345?
x.empl.id = 12345;
105
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
106
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 and b
107
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
108
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
109
What does the following line of code define? Days operator++(int)
An overloaded operator ++
110
What type of values can a throw-statement throw (return)? [object types, primitive types, string types, all of the above]
all of the above
111
The exception handling mechanism discussed in this course is at the level of (hardware, user).
user
112
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.
both
113
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 A virtual member function in C++ implies (early, late) binding between the function name and the code.
late
114
Type checking during compilation will prevent a base-class pointer from accessing the _____ of the derived class object.
additional members
115
Type checking during compilation will prevent a base-class pointer from accessing the _____ of the derived class object. additional members What part of memory can be de-allocated by the destructor?
heap memory created in the constructor
116
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
117
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
118
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
119
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
120
If the relationship between two classes can be best described as an "is-a" relation, we should use _____.
inheritence
121
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
122
In the C++ exception structure, how many handlers can be defined following each try-block?
zero or more
123
What is the function of throw statement? [exit from a _____ and pass a value to the _____]
try-block, catch-block
124
What type casting mechanism should be used if you want to cast an integer value to a double value?
static cast
125
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 casting
126
Given a declaration: int i = 25, j = &i, k = &j; which of the following operations will cause a compilation error? A) i++, B) (&i)++, C) (j)++, or D) (**k)++
b
127
Given a declaration: int i = 25, j = &i, k = &j; which of the following operations will change the value of variable i? A) j++, B) k++, C) (k)++, or D) (**k)++
d
128
Is Java a strongly or weakly typed language?
strong
129
Is C++ a strongly or weakly typed language?
strong
130
Are functional programming languages usually strongly or weakly typed languages?
weak
131
Is C a strongly or weakly typed language?
weak
132
Is Scheme a strongly or weakly typed language?
weak
133
Is Prolog a strongly or weakly typed language?
weak
134
Assume that two pointers are declared as char str1 = "alpha", str2. Which of the following assignment statements will lead to a semantic error? A) str2 = str1, B) str2 = 0, C) str1 = str1 + 1, or D) *str2 = "world"
d
135
Which of the following declarations will cause a compilation error? A) char s[5], B) char s[3] = "hello", C) char s[], or D) char s[] = {'s', 't', 'r'}
c