0% found this document useful (0 votes)
13 views

3

Uploaded by

dhruvalsvm
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)
13 views

3

Uploaded by

dhruvalsvm
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/ 22

CSE240 - quizzes final

Study online at https://quizlet.com/_6j9zbz

1. This quote: False

"When piloting a helicopter - changing speed can/will


change your direction and possibly vice versa"

Demonstrates that changing speed and/or direction


is Orthogonal.

2. C++ was designed to bring Object Orientation to C. In True


fact it was originally released with the unimaginative
name "C with Classes"

3. There was an early focus on efficiency due to early True


programmable computers being themselves fairly in-
efficent being limited in power and storage.

4. When evaluating a programming language the cate- This concept asks


gory Reusability describes: how tied down
a language is to
a particular plat-
form, can code
be distributed eas-
ily and can li-
braries be made
and shared

5. Autocode and FORTRAN are considered to be the True


first high-level programming languages.

6. What is a feature of object-oriented computing? encapsulation of


states

7. In contrast to Web 1.0, what is the key function of Web Web is the com-
2.0? puting platform

8. What computing paradigm enforces stateless (no Functional


variable allowed) programming?

9. What programming paradigm does Fortran belong Imperative


to?
1 / 22
CSE240 - quizzes final
Study online at https://quizlet.com/_6j9zbz

10. What computing paradigm can solve a problem by Logic


describing the requirements, without writing code in
a step-wise fashion to solve the problem.

11. A programming languages can be broken down into Syntactic


four structural layers. Identify these layers. (Check all Contextual
that applies.) Semantics

12. Can the identifier "base_variable" be created from the No - there is


following BNF ruleset? an underscore in
the identifier name
<char> ::= a | b | c | ... | s | ... | x | y | z that cannot be
<identifier> ::= <char> | <char> <identifer> generated

13. Given this snippet of code in C, Syntactically cor-


rect, but contextu-
char alpha = 'a'; ally incorrect.
int numeric = alpha + 10;

which of the following statement is correct:

14. If your program was designed to print "Hello World" Semantics error
ten (10) times, but during execution, it printed eleven
(11) times. What type of error is it?

15. What does the | (pipe) symbol in a BNF rule mean? It is an or state-
ment. Choose one
of the options.

16. Given: False

Very Simple Programming Language (VSPL)

<char> ::= a | b | c | ... | z | 0 | 1 | ... | 9

<operator> ::= + | - | * | / | % | < | > | == | >= | <=

<variable> ::= <char> | <char> <variable>

2 / 22
CSE240 - quizzes final
Study online at https://quizlet.com/_6j9zbz
<expr> ::= <variable> <operator> <variable> | ( <expr>
) <operator> ( <expr> )

<assign> ::= <variable> = <expr>;

<statements> ::= <assign> | <assign> <statements>

The following is valid:


(a+b) = (x*y);

17. Given: True

Very Simple Programming Language (VSPL)

<char> ::= a | b | c | ... | z | 0 | 1 | ... | 9

<operator> ::= + | - | * | / | % | < | > | == | >= | <=

<variable> ::= <char> | <char> <variable>

<expr> ::= <variable> <operator> <variable> | ( <expr>


) <operator> ( <expr> )

<assign> ::= <variable> = <expr>;

<statements> ::= <assign> | <assign> <statements>

The following is valid:

a = x + y; b = s * t; c = w + v;

18. Given: False


Very Simple Programming Language (VSPL)
<char> ::= a | b | c | ... | z | 0 | 1 | ... | 9
<operator> ::= + | - | * | / | % | < | > | == | >= | <=
<variable> ::= <char> | <char> <variable>

3 / 22
CSE240 - quizzes final
Study online at https://quizlet.com/_6j9zbz
<expr> ::= <variable> <operator> <variable> | ( <expr>
) <operator> ( <expr> )
<assign> ::= <variable> = <expr>;
<statements> ::= <assign> | <assign> <statements>

The following is valid:

a = b + c + d;

19. If you like to see accurate debugging information, Interpretation


which of the following program processing would you
recommend?

20. If your application is composed of multiple modules Compilation


(programs), which of the following program process-
ing would you recommend?

21. During compilation, linker is used for resolving external


___________________. references (bring
in code from other
libraries).

22. Which implementation of a function has potentially Macro


the best performance in terms of execution speed?

23. Assume a function requires 20 lines of machine code a longer machine


and will be called 10 times in the main program. You code but with
can choose to implement it using a function definition shorter execution
or a macro definition. Compared with the function time.
definition, macro definition will lead the compiler to
generate, for the entire program, ______

24. Given the following code, what is the expected value 9


for z?

#define func(x, y) (x > y) ? y++ : x++

int main()
{
int x = 10;
4 / 22
CSE240 - quizzes final
Study online at https://quizlet.com/_6j9zbz
int y = 9;
int z = func(x, y);
}

25. Implicit type conversion is commonly refer to as Coercion


__________

26. Which of the following orthogonality describe this Number Orthogo-


example: nality

If a block allows one statement, it should allow zero


or more statements within that same block.

27. In C++, what function can be used to input a string cin.getline(...);


with spaces?

28. Where is the main() function located in a C or C++ outside any class
program?

29. The imperative programming paradigm is popular is based on com-


and is a part of object-oriented computing paradigm, puter organization
because it ____ (Select all answers that apply). and thus is effi-
cient to execute on
hardware.

matches the cul-


ture of doing
things by following
the step-wise in-
structions.

30. Which of the following types is a C++ type, but NOT a bool
C type?

31. What is NOT the purpose (functionality) of the for- to allow functions
ward declaration (prototype)? to return different
types of values

32.

5 / 22
CSE240 - quizzes final
Study online at https://quizlet.com/_6j9zbz
During data declaration, a name is binded to a mem- Data Type
ory location, what else can be identify as part of this Scope
process? Qualifier

33. Given a declaration: char a[] = "Hello World"; What is 12


the size (in bytes) of the array a[]?

34. Which of the following C assignment statements (as- a[0] = 'h';


sign a value to a variable at the semantic level) will
NOT cause a compilation error?

Assume the array has been declared as: char a[5];

35. Given the C declaration: char s1[4], s2[ ] = "hello"; if a The result is s1
string copy function strcpy(s1, s2) is executed, what will contain the
will happen? string "hell", and
the follwing two
byte loactions will
contain 'o' an '\0'.

36. Given: 40

char: 1

short: 2

int: 4

long: 4

float: 4

double: 8

How many bytes is this array: char* myStrings[10]

37. Given the following code and considering things like 'x'
ASCII values and pointer addresses:

6 / 22
CSE240 - quizzes final
Study online at https://quizlet.com/_6j9zbz
int num1 = 5; //addressed at 1767612

int num2 = 10; //addressed at 1767600

int num3 = 15; //addressed at 1767588

char ch1 = 'a'; //addressed at 3734375

char ch2 = 'b'; //addressed at 3734363

char ch3 = 'c'; //addressed at 3734351

char* chPtr = &ch3;

int* iPtr = &num3;

*iPtr = num3 * 8;

*chPtr = *iPtr;

What will the following statement output?

cout << ch3;

38. Given the following code and considering things like 1767588
ASCII values and pointer addresses:

int num1 = 5; //addressed at 1767612

int num2 = 10; //addressed at 1767600

int num3 = 15; //addressed at 1767588

char ch1 = 'a'; //addressed at 3734375

char ch2 = 'b'; //addressed at 3734363

char ch3 = 'c'; //addressed at 3734351


7 / 22
CSE240 - quizzes final
Study online at https://quizlet.com/_6j9zbz

char* chPtr = &ch3;

int* iPtr = &num3;

*iPtr = num3 * 8;

*chPtr = *iPtr;

What will the following statement output?

cout << iPtr;

39. Which of the following statements will allow me to *myPtr = 10;


give the value of 10 to the memory int* myPtr points
to?

40. (True or False) Multiple pointers can reference the True


same objects.

41. C/C++ has 2 pointer operators, which operator repre- Asterisk (*)
sents the name of the address? (Commonly refer as
l-value.)

42. Given this snippet of code, what is the value of x after 100
executing the last statement?

int x = 10, *y;

y = &x;

*y = 100;

y = y + 1;

43. Given this snippet of code, determine which of the fol- x = array;
lowing options will change the text in array to "Hello
Doe" after execution. (Check all that applies.) *(x + 6) = 'D';

---------------------
8 / 22
CSE240 - quizzes final
Study online at https://quizlet.com/_6j9zbz
char array[] = "Hello Joe"; x = &array[0];

char *x; x = x + 6;

*x = 'D';

44. A pointer variable can take the address of a memory 90


location as its value. Read the given program. 70
20
#include <stdio.h>
main() {
int a = 20, b = 30, *p, *q, **r;
p = &a;
*p = 50;
q = &b;
*q = 70;
r = &p;
**r = 90;
printf("%d\n", a); // 1st printf statement
printf("%d\n", b); // 2nd printf statement
a = 20;
b = 80;
printf("%d\n", **r); // 3rd printf statement
}

Answer the following three questions.

1.The output of the 1st printf statement is [first].

2. The output of the 2nd printf statement is [second].

3.The output of the 3rd printf statement is [third].

45. Given the following: 1877212

int num1 = 5; //addressed at 1877112


int num2 = 15; //addressed at 1877300
int num3 = 20; //addressed at 1877192
double d1 = 1.05; //addressed at 1374376

9 / 22
CSE240 - quizzes final
Study online at https://quizlet.com/_6j9zbz
double d2 = 2.25; //addressed at 1374360
double d3 = 3.14; //addressed at 1374344
After these statements:

int* ptr1 = &num3


ptr1 = ptr1 + 5;
What will be the address contained in ptr1?

46. Given this snippet of code, what is the value of x after 1000
executing the last statement?

int x = 10, *y, **z;

y = &x;

z = &y;

**z = 1000;

47. We use "Pass by Pointer" when: Function wants to


modify the value,
the value is expen-
sive to copy and
NULL is valid

48. We use "Pass by Constant Reference" when: Function does not


want to modify the
value, the value is
expensive to copy
and NULL is not
valid

49. We use "Pass by Constant Pointer" when: Function does not


want to modify the
value, the value is
expensive to copy
and NULL is valid

50. Given the following code It prints: catdog

10 / 22
CSE240 - quizzes final
Study online at https://quizlet.com/_6j9zbz
char a[2][3] = { { 'c', 'a', 't'}, { 'd', 'o', 'g'} };
int i, j;
for (i = 0; i<2 ; i++) {
for (j = 0; j<3; j++)
printf("%c", a[i][j]);
}

What will happen?

51. Given the following code It prints: carbike

char a[2][4] = { { 'c', 'a', 'r', 'b' }, { 'i', 'k', 'e', '\0' } }; char
*p = &a[0][0]; while (*p != '\0') { printf("%c", *p); p++; }

What will happen?

52. Given the following definition and declarations: char a2[size2];

#define size1 10
const int size2 = 20;
char a1[size1];
char a2[size2];

which line of code can cause a compilation error?

53. Given the following snippet of code, answer the fol- 6


lowing two questions based on the code: 7

typedef enum {Sun, Mon, Tue, Wed, Thu, Fri, Sat} days;
days x = Mon, y = Sat;
while (x != y) { x++; }
y++;
printf("x = %d, y = %d", x, y);

1. What value will be printed for variable x? [x].

2. What value will be printed for variable y? [y]

54.

11 / 22
CSE240 - quizzes final
Study online at https://quizlet.com/_6j9zbz
Which of the following coding practice can lead to a Keep the charac-
higher memory efficiency (use fewer padding bytes) ter type variables
in defining a structure? together.

55. When is padding required for a structure type vari- When the struc-
able? ture contains a
word-type vari-
able, such as in-
teger, float, and
pointer, and the
total number of
bytes is not a mul-
tiple of four.

56. The size (number of bytes) of a structure-type vari- changing the or-
able can be changed by the following factors. Select ders of the mem-
all that apply. bers in the struc-
ture.

changing the com-


puter from a 32-bit
to a 64-bit proces-
sor.

adding a member
into the structure.

57. When will the buffer be created? When the file op-
eration fopen is
performed.

58. What parameters are required when performing file source


operations fread and fwrite? destination
item size
number of items

59. When do we need to use fflush() or cin.ignore()? Between a format-


ted input and an
unformatted input

12 / 22
CSE240 - quizzes final
Study online at https://quizlet.com/_6j9zbz
60. Given the information below, how will you access the x->name;
name for a terminal node pointed to by x?

struct Terminal {
char name[30];
char location[32];
struct Terminal* next;
} *x;

61. Assume this is a 32-bit environment, what is the size 4 bytes


of x?

struct Terminal {
char name[30];
char location[32];
struct Terminal* next;
} *x;

62. Assume this is a 32-bit environment, what is the size 68 bytes


of x? (HINT: Don't forget about padding.)

struct Terminal {
char name[30];
char location[32];
struct Terminal* next;
} x;

63. Assume that the search function of a linked list is the address of a
specified by terminal node
0
struct Terminal* search();

What values can the search function return? Select


all correct answers.

64. Assume that you want to delete the entire linked list head = null;
pointed to by head. Which of the following deletion
operation will cause the most garbage of memory?

65.
13 / 22
CSE240 - quizzes final
Study online at https://quizlet.com/_6j9zbz
Given the information below, which of the follow- x = head;
ing snippet of codes will print every terminal in the
linked-list without any side-effects of changing the while(x != NULL) {
state. Assume head is the only reference to the
linked-list and there are more than one terminal in the printf("%s - %s",
list. x->name, x->loca-
tion);
struct Terminal { x = x->next;
char name[30]; }
char location[32];
struct Terminal* next;
} *head, *x;

66. Given the information below, which of the following p = (struct con-
snippet of codes will insert a new node in the second tact *) malloc(size-
place in the linked-list. Assume the linked-list con- of(struct contact));
tains already at least one node.
...
struct Terminal {
char name[30]; p->next =
char location[32]; head->next;
struct Terminal* next;
} *head, *p, *q; head->next = p;

67. What is the key difference between a static variable They have differ-
and a global variable? ent visibility

68. If a function calls another function, the local variables different stack
in these two functions use the memory from frames.

69. What opeartions will acquire memory from heap? malloc


Select all that apply. new

70. What is the best way of deleting an array created by delete[] p;


"p = new StructType[size];" in C++?

71. What memory must be garbage-collected by a de- heap memory cre-


structor? ated in the con-
structors in the
same class
14 / 22
CSE240 - quizzes final
Study online at https://quizlet.com/_6j9zbz

72. What is the best way of deleting a linked list of object Use a loop to
in C++? delete every ob-
ject in the linked
list.

73. We need to write a destructor for a class, if heap memory is


used in the con-
structor of the
class.

74. What members of a base class can be redefined in the virtual members
derived classes?

75. The semantics of multiple inheritance becomes com- overlapped mem-


plex and error prone, if the base classes have bers.

76. Consider a path from the root to a leaf of a class tree The class at the
based on the inheritance. Which class has the most leaf of the tree
class members?

77. If you want to create a linked list of Container nodes, A pointer to Publi-
which can contain Publication node, Book node, The- cation node
sis node, and Report node, what type of pointer
should be declared in the Container to point to all
these nodes?

78. Defining a virtual function in class means that the can be redefined
function in its child classes.

79. If the relation between two C++ classes can be best contain one class
described as "has-a" relation, we should in the other (con-
tainment).

80. Given the following class definition and the variable x.empl.id = 12345;
declaration:

class employee
char *name;
long id;
15 / 22
CSE240 - quizzes final
Study online at https://quizlet.com/_6j9zbz
}
class manager {
employee empl;
char* rank;
}x

Which of the following assignment statement is cor-


rect?

81. What features are supported in C++? Select all that Function over-
apply. loading
Operator over-
loading
Virtual operator
Virtual function

82. What keyword is used for defining an exception han- catch


dler?

83. The exception handling mechanism discussed in this user program.


course is at the level of

84. Given this snippet of code, identify what is the size-n void
(whole) problem? deleteList(struct
contact* node)
void deleteList(struct contact* node) {

if (node != NULL) {

deleteList(node->next);

free(node);

} else

return;

85. A merge-short is typically implemented using


16 / 22
CSE240 - quizzes final
Study online at https://quizlet.com/_6j9zbz
a function with two
recursive calls.

86. Given this snippet of code, identify what is the size-m deleteList(node->next)
(sub-divided) problem?

void deleteList(struct contact* node) {

if (node != NULL) {

deleteList(node->next);

free(node);

} else

return;

87. A tail-recursive function is structurely equivalent to a while loop

88. The Golden Rule of Recursion is "All base cases must False
make progress towards a recursive case."

89. Given a Binary Search Tree class with the properties: if(item > cur-
rent->data)
Node* root; return
And the node defined as: helpFindIt(cur-
rent->right, item)
struct Node
{ if(item < cur-
int data; rent->data)
Node* left; return
Node* right; helpFindIt(cur-
} rent->left, item)
I have a method:

Node* findIt(int item)


And a helper method:
17 / 22
CSE240 - quizzes final
Study online at https://quizlet.com/_6j9zbz

Node* helpFindIt(Node* current, int item)


These methods will either return a pointer to the node
that item is found in, or NULL signifying it was not
found.

What would be the recursive case or cases of


helpFindIt?

90. What mechanism defines tail recursion? The calculated an-


swer is propagat-
ed to each lay-
er of the recursion
through the para-
meters

91. The data stored in a binary search tree is sorted, if the inorder
tree is traversed in

92. The search algorithm will be more efficient if a binary a balanced binary
search tree is tree.

93. Consider an array, a linked list, and a binary search binary search tree
tree. Which data structure requires fewest compar-
isons in average to search an element stored in the
data structure?

94. How do we include a user-defined library, say my- #include "my-


MathLib.h, into a program that uses this library? MathLib.h"

95. In Scheme, the form (symbol-length? 'James) will re- an error message
turn:

96. One of the major differences between the imperative have side-effect.
and functional programming languages is that the
functional programming languages do NOT

97. In addition to functional programming, what other e-commerce


ideas are originated by John McCarthy? space fountain

18 / 22
CSE240 - quizzes final
Study online at https://quizlet.com/_6j9zbz
98. What notation requires parentheses in order to cor- infix notation
rectly define the order of computation?

99. Which of the followings is a valid Scheme form? (* 9 (/ (- 4 2) 7))

100. What functional feature does the code below best procedures are
exhibit? first class object.

(define start-engine (lambda ()


(error-detection (wheel-velocity (wheel-sensor))
(body-velocity))))

101. Given this procedure, what is the return result? "I'm a number"
(define (guess value)
(cond ((number? value) "I'm a number")
((char? value) "I'm a character")
((integer? value) "I'm a integer")))

(guess 10)

102. What data structure is used in Scheme for represent- list


ing extremely large integers?

103. Given an expression: x1 + x2 + x3 + x4 Scheme

Which language allows to evaluate the expression in


this order: (1) x1 plus x2; (2) x3 plus x4; (3) sum of (
x1 + x2 ) plus sum of ( x3 + x4 );

104. A let-form in Scheme defines a set of local names.

105. For functional programming languages, the scope of is in the body part
a local name of the declaration
or definition.

106. Given the Scheme code, answer the following ques- 18


tions. 22

((lambda (x)
((lambda (x y)
19 / 22
CSE240 - quizzes final
Study online at https://quizlet.com/_6j9zbz
(+ x y))
4 (* 6 x)))
3)

(1) The value to be passed to the parameter y is [y].

(2) The final output of the piece of code is [output].

107. What is the expected result for this expression (in #\o
Scheme)?

(string-ref "Hello World" 4)

108. Given the Scheme code below, answer the follow- 2


ing questions related the Fantastic Four abstract ap- 3
proach. 3 and 4

(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? Choose [Size1]

(2) What line of code contains the size-M problem,


where M < N? Choose [SizeM]

(3) What lines of code define the step that construct


the solution to size-N problem? Choose [SizeM_N]

109. What is the correct method for constructing a pair in (cons 1 2)


Scheme?

110. Which of the followings is a Scheme pair? Select all '(x . y)


that apply.
'(() ())

'(x)

20 / 22
CSE240 - quizzes final
Study online at https://quizlet.com/_6j9zbz
111. Given the Scheme code as follows. What is the out- (1 0 1 0 1 0)
put?

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

112. Given the following Scheme definition: Call-by-name

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

113. Compare the follow two Scheme forms: (cons '(1 2) '(4 5))
(append '(1 2) '(4 5)) and (cons '(1 2) '(4 5)). returns '((1 2) 4 5)

114. Which predicate logic matches most closely with this listensto(bill, mu-
statement? sic); listensto(bill,
news).
"Bill listens to music or news."

115. The scope of a Prolog variable is within a single


fact, rule, or query.

116. How many arguments can be defined in a fact? n, where n >= 0.

117. A prolog program may contain: (Select all that apply.) facts.
rules.
questions.

118. We apply an anonymous variable in the definition of


a rule if we
21 / 22
CSE240 - quizzes final
Study online at https://quizlet.com/_6j9zbz
do not want.to ob-
tain a return value
to the variable.

119. A fact starts with a relationship followed by a list of can have a struc-
arguments. The arguments of a fact ture similar to that
of a fact.

120. Given these facts: fruit_dessert(X) :-


is_dessert(X),
is_fruit(Y),
is_dessert(cookie). contains(X, Y).
is_dessert(ice_cream).
is_dessert(pie).
is_dessert(cheesecake).
is_fruit(strawberry).
is_fruit(apple).
is_fruit(peach).
contains(cookie, chocolate_chips).
contains(ice cream, cookie).
contains(ice cream, strawberry).
contains(ice cream, peach).
contains(pie, apple).
contains(pie, peach).
contains(pie, strawberry).
contains(cheesecake, strawberry).

Which of the following rule can help summarize all


desserts that contains fruits:

121. A higher order function is a function that takes the operator of a func-
tion as an argu-
ment.

22 / 22

You might also like