Plants

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Given this procedure, what is the return result? (define (guess value) (cond ((number? value) "I'm a number") ((char? value) "I'm a character") ((integer? value) "I'm a integer")))(guess 10) "I'm a number" "I'm a character" "I'm a integer" Error: Unable to computer result.

"I'm a number"

How do we include a user-defined library, say myMathLib.h, into a program that uses this library? #include <myMathLib.h> #include "myMathLib.h" #include (myMathLib.h) #include [myMathLib.h]

#include "myMathLib.h"

Given a C declaration: char a[] = "Hello World"; What can be used as the initial address of array a[]? Select all correct answers. a a[0] &a[0] *a[0]

&a[0]

Given this snippet of code, what is the value of x after executing the last statement? int x = 10, *y, **z; y = &x; z = &y; **z = 1000; 10 100 1000 None of the above.

1000

Given the code as follows: main() { int i = 3, n; float x; x = i; n = 8 % x; } What problem will occur? A compilation error will occur. A run time error will occur. An inheritance error will occur. No problem will occur at all.

A compilation error will occur.

When will the buffer be created? When the pointer of a file type is declared. When the file operation fopen is performed. When the file opeartion fread or fwrite is performed. When the file is closed.

When the file operation fopen is performed.

Given this snippet of code, identify what is the size-m (sub-divided) problem? void deleteList(struct contact* node) { if (node != NULL) { deleteList(node->next); free(node); } else return; } void deleteList(struct contact* node) if (node == NULL) then return void deleteList(node->next); free(node);

deleteList(node->next);

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

reinterpret_cast

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

static_cast

What does the following line of code define? Days operator++(int) a new int type. A new class Days. An overloaded operator ++ An overloaded operator *

An overloaded operator ++

Select all that apply: Identify the differences between a global variable and a static variable: Scope Static Ram Persistent Value Only initialized once Static keyword

Scope Static keyword

A merge-short is typically implemented using a tail-recursive function. a function with a single recursive call. a function with two recursive calls. two while loops.

a function with two recursive calls.

What is the maximum number of padding bytes that a compiler can add to a structure? 3 2 more than 4 4

more than 4

What's true about OOP in C++? One class per .h/.cpp file combination "this" is a pointer in C++ and therefore we use -> to access from it We can directly deference this to use the dot-operator similar to Java: *this.doStuff() In C++ structs are fully OOP but it changes the base assumption of visibility from private to public Generally follows a pattern of forward declaration in a .h file and definitions in a .cpp file

"this" is a pointer in C++ and therefore we use -> to access from it In C++ structs are fully OOP but it changes the base assumption of visibility from private to public Generally follows a pattern of forward declaration in a .h file and definitions in a .cpp file

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

Assume that the search function of a linked list is specified by struct Terminal* search(); What values can the search function return? Select all correct answers. 0 the address of a terminal node the name stored in the terminal node in the linked list the terminal node itself

0 the address of a terminal node

Given this snippet of code, what is the value of x after executing the last statement? int x = 10, *y; y = &x; y = y + 1; *y = 100; 10 100 1000 None of the above.

10

Given this snippet of code, what is the value of x after executing the last statement? int x = 10, *y; y = &x; *y = 100; 10 100 1000 None of the above.

100

Given the following code, what is the expected value for y? #include <stdio.h>#define func(x, y) (x > y) ? y : xint main(){int x = 10;int y = 9;int z = func(++x, y++);} 9 10 11 12

11

Given the following: 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 double d2 = 2.25; //addressed at 1374360 double d3 = 3.14; //addressed at 1374344 After these statements: double* ptr1 = &d2;ptr1 = ptr1 - 2; What will be the address contained in ptr1? 1374360 1374358 1374352 1374344 Unknown - we are not given the storage address of ptr1

1374344

What's the size of this struct? struct record4 { int a; int c; float e; char b; char d; }; 16 20 14 24

16

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 3 4 error message

2

Given the following snippet of code, answer the following two questions based on the code: typedef enum {red, amber, green} traffic_light; traffic_light x = red, y = green; while (x != y) { x++; } y++; printf("x = %d, y = %d", x, y); 1. What value will be printed for variable x? Please choose: 2. What value will be printed for variable y? Please choose:

2, 3

What's the size of this struct? struct record3 { int a; char b; int c ; char d; float e; }; 20 16 24 14

20

What is the size of this struct? struct record1 { double x; char p[10]; char c; int a; }; 24 32 14 23

24

What is the size of this struct? struct record1 { char p[10]; double x; char c; int a; }; 32 14 23 24

32

Consider the following snippet of code in a 32-bit computer. struct contact {char name[30];int phone;char email[30];} x; What is the size of variable x in bytes? 9 68 64 8

68

Match: :: : <library>.h <library>.cpp

:: Scope resolution operator : Inheritance operator <library>.h The file we generally forward declare our classes and methods in <library>.cpp The file we generally put our method definitions in

What should be listed in a header file (.h file)? Select all that apply. Constants that you want to share. Forward declaration of the functions that you want to share. Implementation (C code) of the functions that you want to share. The main function of your program.

Constants that you want to share. Forward declaration of the functions that you want to share.

Type checking happens during compilation phase, it reinforces which of the following structural layer? Lexical Syntactic Contextual Semantics

Contextual

The reason that we use a buffer between the disk and the memory is _______ Disk access speed is low, and disk is read and written large block of data. Disk can store binary type of data only. Disk can store text type of data only. memory is organized in a one-dimensional array and disk is organized in a multidimensional array.

Disk access speed is low, and disk is read and written large block of data.

Functional programming language is more friendly to parallel computing, because it supports Eager Evaluation Lazy Evaluation Loop Tail-Recursion

Eager Evaluation

C++ Inheritance is identical in every way to Java. True False

False

In a C++ class, if we don't specify a Visibility modifier it defaults to Protected True False

False

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

False

When defining methods for a forward declared class, all the method definitions MUST be in the same .cpp file. True False

False

Given the following snippet of C++ code: string name = "Hello";ifstream myFile; myFile.open(myFile);myFile >> name;myFile.close(); What does it do? It saves the word Hello into a file in the file system. It loads the word Hello from a file in the file system. It prints the word Hello to screen (standard output). It reads a word from the keyboard (standard input).

It loads the word Hello from a file in the file system.

Given the following code 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? It prints: carbike It prints: carb A compilation error will occur at this line: char *p = &a[0][0]; A compilation error will occur at this line: while (*p != '\0')

It prints: carbike

Given the following code char a[] = {'c', 'a', 't', '\0'}; char *p = a; while (*p != 0) { *p = *p + 1; printf("%c", *(p++)); } What will happen? It prints: a string of random characters It prints: cat It prints: dbu A run time error will occur at this line.

It prints: dbu

Given this snippet of code, what is the value of z after executing the last statement? int x = 10, *y, **z; z = &y; y = &x; *y = 100; 10 100 1000 None of the above.

None of the above.

The complexity of searching an arbitrary binary search tree is the order of O(1) O(lg n) O(n) O(n*n)

O(n)

What is the main reason of applying two-step translation of high level programming language? More accurate debugging information Better support of macros One compiler for all machines Support stronger typing system

One compiler for all machines

Which of these parts of RAM are automatically controlled by the program/memory manager? Stack Static Heap

Stack Static

What mechanism defines tail recursion? The calculated answer is propagated to each layer of the recursion through the parameters The recursion "coils" itself up like a spring, eventually reaching a base case and allowing waiting calculations to finish A shallow inheritance structure is used and each object stores another object of the same type allowing you to call through the stack of objects as a whole calculation Multiple recursive cases are used creating a "search space" of possible calculated recursive solutions. At a certain point a consideration path can be abandoned for another path.

The calculated answer is propagated to each layer of the recursion through the parameters

What is true about Encapsulation in C++ vs. Java? There is no real difference in concept, just in Syntax. Visibility Modifiers are categories instead of line-to-line keywords. In C++ private and protected are the same thing Java technically has a 4th visibility modifier. When you don't put a visibility modifier on a property or method it gets the "Default" modifier which makes it partially private. C++ only allows you to use Public, Private and Protected once each.

There is no real difference in concept, just in Syntax. Visibility Modifiers are categories instead of line-to-line keywords. Java technically has a 4th visibility modifier. When you don't put a visibility modifier on a property or method it gets the "Default" modifier which makes it partially private.

(True or False) Multiple pointers can reference the same objects. True False

True

A Stack or Queue can be created simply by renaming certain Linked List functions/methods. We don't actually need most of the functionality of a full Linked List as the FIFO and LIFO behaviors are what are important. True False

True

Classes in C++ follow the same general syntax pattern as Structs, Enums, etc. <typename> <name> { <body> }; True False

True

If we don't use the Scope-Resolution Operator :: to define a method, than C++ just thinks we're creating a function. True False

True

Java uses which of the following program processing? Interpretation Compilation Two Step Translation with Intermediate Code -- (Compilation + Interpretation) Two Step Translation without Intermediate Code

Two Step Translation with Intermediate Code -- (Compilation + Interpretation)

What is the best way of deleting a linked list of object in C++? head = 0; delete head;head = 0; Use a loop to delete every object in the linked list. Leave the job to the automatic garbage collector.

Use a loop to delete every object in the linked list.

How does Scheme implement the function such as: for (i = 1; i< 100, i++) {sum = sum + i;} Use for-loop Use while-loop Use repeat-until Use recursion

Use recursion

When is padding required for a structure type variable? As long as the size of the structure is not a multiple of four. When the structure contains a word-type variable, such as integer, float, and pointer, and the total number of bytes is not a multiple of four. As long as the structure contains a word-type variable, such as integer, float, and pointer. When the structure contains character type of variables.

When the structure contains a word-type variable, such as integer, float, and pointer, and the total number of bytes is not a multiple of four.

The function searching a binary search tree can be easily implemented using a a while loop. a tail-recursive function. a recursive function with two recursive calls. multiple while loops.

a recursive function with two recursive calls.

A tail-recursive function is structurally equivalent to a switch statement a while loop an if-then-else construct. multiple nested while loops.

a while loop

The size (number of bytes) of a structure-type variable can be changed by the following factors. Select all that apply. adding a member into the structure. changing the computer from a 32-bit to a 64-bit processor. changing the orders of the members in the structure. changing an int-type variable to a pointer-type variable.

adding a member into the structure. changing the computer from a 32-bit to a 64-bit processor. changing the orders of the members in the structure.

If we want to store an array of structures into a disk file, what file type should we choose? binary file text file array file structure file

binary file

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

binary search tree

The statement "a function is a first-class object" means that a function must be instantiated from a class. can be placed in a place where a value is expected. must have a return value. may not have side-effect.

can be placed in a place where a value is expected.

Defining a virtual function in class means that the function is an interface only, and it does not allow to have implementation. will acquire the memory from the stack. can be redefined in its child classes. will acquire the memory from the virtual memory in the disk storage.

can be redefined in its child classes.

Given the following definition and declarations: #define size1 10const int size2 = 20;char a1[size1];char a2[size2]; which line of code can cause a compilation error? const int size2 = 20; char a1[size1]; char a2[size2]; both char a1[size1] and char a2[size2];

char a2[size2];

What C/C++ constant variable can potentially be modified during the execution? Neither (A) nor (B) Both (A) and (B) const x = 5; #define x 5

const x = 5;

What is the best way of deleting an array created by "p = new StructType[size];" in C++? delete p; delete[] p; Use a loop to assign 0 value to each element. Leave the job to the automatic garbage collector.

delete[] p;

If the relation between two C++ classes can be best described as "is-a" relation, we should derive one class from the other (inheritance). contain one class in the other (containment). define them to be independent of each other. merge them into a single class.

derive one class from the other (inheritance).

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

different stack frames.

In addition to functional programming, what other ideas are originated by John McCarthy? e-commerce space fountain object-oriented programming stored program concept

e-commerce space fountain

One of the major differences between the imperative and functional programming languages is that the functional programming languages do NOT support call-by-value parameter passing. have side-effect. allow nested function calls. allow a procedure to return a value.

have side-effect.

Given a Binary Search Tree class with the properties: Node* root; And the node defined as: struct Node{int data;Node* left;Node* right;} I have a method: Node* findIt(int item) And a helper method: 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 base case or base cases or cases of helpFindIt? if(current == NULL)return NULL;if(current->data == item)return current; if(current->data == item)return current; if(item > current->data)return helpFindIt(current->right, item)if(item < current->data)return helpFindIt(current->left, item) if(current->data == item)return current;elsereturn helpFindIt(current, item);

if(current == NULL)return NULL;if(current->data == item)return current;

Given a Binary Search Tree class with the properties: Node* root; And the node defined as: struct Node{int data;Node* left;Node* right;} I have a method: Node* findIt(int item) And a helper method: 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? if(current == NULL)return NULL;if(current->data == item)return current; if(current->data == item)return current; if(item > current->data)return helpFindIt(current->right, item)if(item < current->data)return helpFindIt(current->left, item) if(current->data == item)return current;elsereturn helpFindIt(current, item);

if(item > current->data)return helpFindIt(current->right, item)if(item < current->data)return helpFindIt(current->left, item)

The data stored in a binary search tree is sorted, if the tree is traversed in preorder. postorder inorder. in any order.

inorder

Which of the following C declarations (contextual level) will cause a compilation error? int c[] = {'a', 'b', '\0'}; int d[]; int a[] = {12, 24}; int b[2];

int d[];

It does not cause memory (storage) overhead to create multiple names (alias) for a variable. pointers to a variable. copies of a variable. pointers to a pointer to a variable.

names (alias) for a variable.

What data types in C have the same data range, assuming that the computer used is a 32-bit computer? pointer type and unsigned int long int and double wchar_t and char array of int and string

pointer type and unsigned int

What functional feature does the code below best exhibit? (define start-engine (lambda ()(error-detection (wheel-velocity (wheel-sensor)) (body-velocity)))) Use local variable to store intermediate value. procedures are first class object. Use recursion instead of loop. sequential processing of components.

procedures are first class object.

Assume pointer variable p points to node x, and node x's next pointer points to node y. What does free(p) operation mean? return the memory held by x to the free memory pool. return the memory held by x and by y to the free memory pool. set pointer p to 0. return the memory held by x to the free memory pool and set pointer p to 0.

return the memory held by x to the free memory pool.

A critical step in writing a recursive function is to assume that the stopping condition can be identified by the underlying recursive mechanism. size-1 problem has been solved by the underlying recursive mechanism. size-m problem has been solved by the underlying recursive mechanism, where m < n. size-n problem has been solved by the underlying recursive mechanism.

size-m problem has been solved by the underlying recursive mechanism, where m < n.

Functional programming languages do NOT allow to define procedures. multiple parameters in one procedure. named values. variables whose value can be modified.

variables whose value can be modified

Given this snippet of code, identify what is the size-n (whole) problem? void deleteList(struct contact* node) { if (node != NULL) { deleteList(node->next); free(node); } else return; } void deleteList(struct contact* node) if (node == NULL) then return void deleteList(node->next); free(node);

void deleteList(struct contact* node)

Given the following code and considering things like 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 char* chPtr = &ch3; int* iPtr = &num3; *iPtr = num3 * 8; *chPtr = *iPtr; What will the following statement output? cout << ch3; 'c' 'P' 'x' 3734351 120

'x'

Which of the following statements will allow me to give the value of 10 to the memory int* myPtr points to? myPtr = 10; myPtr *= 10; *myPtr = 10; myPtr = *10;

*myPtr = 10;

Given the declaration: char a[] = "Hello";char *p = a, *q; what operations are valid syntactically? Select all that apply. *q = *(&a[0]); q = &(*p); q = &&a[0]; q = &&a;

*q = *(&a[0]); q = &(*p);

Which operators can be overloaded? Select all that apply + ++ >> :: ?:

+ ++ >>

Given: char: 1 short: 2 int: 4 long: 4 float: 4 double: 8 How many bytes is this array: char* myStrings[10] 40 10 80 32

10

Given the following code and considering things like 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 char* chPtr = &ch3; int* iPtr = &num3; *iPtr = num3 * 8; *chPtr = *iPtr; What will the following statement output? cout << iPtr; 15 120 'x' 3734351 1767588

1767588

Given the following code and considering things like 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 char* chPtr = &ch3; int* iPtr = &num3; *iPtr = num3 * 8; *chPtr = *iPtr; What will the following statement output? cout << iPtr; 15 120 'x' 3734351 1767588

1767588

Assume this is a 32-bit environment, given a declaration: int a[10]; What is the size (in bytes) of the entire array? 4 10 40 80

40

Assume this is a 32-bit environment, what is the size of x? (HINT: Don't forget about padding.) struct Terminal { char name[30]; char location[32]; struct Terminal* next;} x; 4 bytes 66 bytes 68 bytes 72 bytes

68 bytes

C/C++ has 2 pointer operators, which operator represents the name of the address? (Commonly refer as l-value.) Comma (,) Asterisk (*) Ampersand (&) Semicolon (:)

Asterisk (*)

What is a good rule of thumb for sizing a Struct in C/C++ assuming that the Struct is optimally set up? Count all the bytes of the data in the struct. Find the nearest power of 2, 4 or 8 based on the largest Data Type in your struct. If the total number of bytes is larger than that power, then the struct will be the next power in size. Count all the bytes of the data-types in the struct. Find the nearest power of 2, 4 or 8 based on the largest member in your struct. If the total number of bytes is larger than that power, then the struct will be the next power in size. Count all the bytes of the data in the struct. Find the nearest power of 2 based on the largest array in your struct. If there isn't an array use the largest variable. If the total number of bytes is larger than that power, then the struct will be the next power in size. The largest data-type in your struct raised to the power of how many members are in the struct.

Count all the bytes of the data in the struct. Find the nearest power of 2, 4 or 8 based on the largest Data Type in your struct. If the total number of bytes is larger than that power, then the struct will be the next power in size.

Select all that apply: Which statements indicate why it is important to understand dynamic multi-dimensional arrays as "arrays of arrays"? The memory is constructed such that it could actually be understood as a single dimension array if you're willing to do the math. It helps us figure out how to get the computer to tell us the size of each dimension of the array and the size of the array itself. Dynamic allocation requires multiple pointers and each pointer can 'point' to it's own array If we get that each row is an independent array, it makes the idea of passing single rows or other subsections of the multi-dimensional array to functions easier. This is the only way to create "ragged or jagged" arrays in C/C++. It might be wise to keep a parallel array of each row's size. Each row is independently created at run-time

Dynamic allocation requires multiple pointers and each pointer can 'point' to it's own array If we get that each row is an independent array, it makes the idea of passing single rows or other subsections of the multi-dimensional array to functions easier. This is the only way to create "ragged or jagged" arrays in C/C++. It might be wise to keep a parallel array of each row's size. Each row is independently created at run-time

A major difference between arrays in C/C++ and Java is that in C/C++ arrays are actually objects and in Java they are strictly memory constructs accessed via pointers. True False

False

C++ allows for multiple inheritance - this idea is identical to Java's Interfaces True False

False

When creating a multi-dimensional array dynamically in C/C++ the Memory Manager will go to great pains to make sure the array is completely contiguous with each row followed immediately by another row in the array. The goal is to keep all the data together in memory rather than "wherever it fits." True False

False

When deleting a linked list ... all we have to do is delete or free the head pointer, the system will take care of the rest. True False

False

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 Function wants to modify the value, the value is expensive to copy and NULL is valid Function does not want to modify the value, the value is expensive to copy and NULL is valid Function wants to modify the value, the value is expensive to copy and NULL is not valid Function does not want to modify the parameter and the value is easy to copy

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

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 Function wants to modify the value, the value is expensive to copy and NULL is valid Function does not want to modify the value, the value is expensive to copy and NULL is not valid Function does not want to modify the parameter and the value is easy to copy Function wants to modify the value, the value is expensive to copy and NULL is not valid

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

We use "Pass by Reference" when: Function wants to modify the value, the value is expensive to copy and NULL is valid Function does not want to modify the parameter and the value is easy to copy Function does not want to modify the value, the value is expensive to copy and NULL is valid Function wants to modify the value, the value is expensive to copy and NULL is not valid Function does not want to modify the value, the value is expensive to copy and NULL is not valid

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

We use "Pass by Pointer" when: Function does not want to modify the value, the value is expensive to copy and NULL is valid Function does not want to modify the value, the value is expensive to copy and NULL is not valid Function does not want to modify the parameter and the value is easy to copy Function wants to modify the value, the value is expensive to copy and NULL is valid Function wants to modify the value, the value is expensive to copy and NULL is not valid

Function wants to modify the value, the value is expensive to copy and NULL is valid

If you like to see accurate debugging information, which of the following program processing would you recommend? Interpretation Compilation Both compilation and interpretation provide the same level of debugging information. Some time compilation is better than interpretation, but other time interpretation is better than compilation.

Interpretation

Given the following code 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? A compilation error will occur at this line: printf("%c", a[i][j]); It prints: catdog A compilation error will occur at this line: char a[2][3] = { { 'c', 'a', 't'}, { 'd', 'o', 'g'} }; It prints: cat

It prints: catdog

Given the following code char *p = "hello", *s = "this is a string"; p = s; printf("%s\n", p); What will happen? A run time error may occur at this line: p = s; It prints: hello It prints: this is a string A compilation error will occur at this line: p = s;

It prints: this is a string

Given the following code char *p = "hello", *s = "this is a string"; p = s; printf("%s\n", p); What will happen? It prints: this is a string A run time error may occur at this line: p = s; A compilation error will occur at this line: p = s; It prints: hello

It prints: this is a string

Given the following snippet of C++ code: string name = "Hello"; ofstream myFile; myFile.open(myFile); myFile << name; myFile.close(); What does it do? It saves the word Hello into a file in the file system. It loads the word Hello from a file in the file system. It prints the word Hello to screen (standard output). It reads a word from the keyboard (standard input).

It saves the word Hello into a file in the file system.

Macros-Processing takes place during which phase? Saving Pre-processing Compilation Execution

Pre-processing

Visibility modifiers, match: Public Private Protected

Public Member is accessible via any created object as well as internally and in inheritance Private Member is accessible in the class that defines it not externally or in inheritance Protected Member is accessible internally and in inheritance, but not externally

Match the C++ inheritance idea to its best description Public Inheritance Protected Inheritance Private Inheritance

Public Inheritance This is the "standard" form of inheritance. No major changes are made from parent to child except that private members of the parent are inaccessible in the child. Protected Inheritance This method of inheritance allows you to functionally remove the public interface of the parent but still have access to the functionality of the interface. It's often used when a child class wants to define its own public interface completely. Private Inheritance This method of inheritance is used to block off access to parent features in future inheritance and/or give a child class access to functionality of a different class without closely tying it to that inheritance hierarchy. Often referred to as "implemented in terms of" This method of inheritance allows for private members of the parent to be accessible in the child.

Maintaining a Tail pointer does what for us? Doesn't actually help us with insertion at all Speeds up all insertion algorithms because it gives us a condition to loop for that would be impossible otherwise Speeds up InsertAtTail making the algorithm O(1) instead of O(n)

Speeds up InsertAtTail making the algorithm O(1) instead of O(n)

Assume that Publication is the root class of an inheritance tree. You want to form a linked list of different publications in the inheritance tree, including Book, Report, Newspaper, etc. What is the best way to create a linked list using PublListNode and Publication classes? The Publication class is derived from the PublListNode class. The PublListNode class is derived from the Publication class. The Publication class contains the PublListNode class. The PublListNode class contains the Publication class.

The PublListNode class contains the Publication class.

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

The class at the leaf of the tree.

What is the key difference between a static variable and a global variable? They have different life time. They have different visibility. They come from different parts of memory. Only one of them needs to be garbage-collected.

They have different visibility.

C++ has multiple forms of inheritance True False

True

C/C++ is "perfectly happy" to allow the programmer to walk outside the bounds of an array. An error can/will eventually occur when you interact with memory that the Memory Manager has reserved. True False

True

Deleting the Tail node is always a O(n) operation in a Singly Linked List True False

True

Deletion in a Linked List is often a two pointer job: 1 pointer to 'point at' the node you want to delete and 1 pointer to 'point at' the node previous to it. True False

True

Goal #1 of our Linked List algorithms is to maintain the fidelity of the list. This means "shuffling" the pointers in the right order so we don't accidentally lose access to the rest of the list and create memory leaks. True False

True

PriQueue inherits from Queue. In the implementation of the getMax() method 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 methods in the derived class (PriQueue) allowed to access the protected members in the base class (Queue)? Yes, always. No, never. Depending on the data type of the members. Depending on if the members are static or not.

Yes, always.

Select all that are true When doing Arbitrary insertion: You Answered Each arbitrary insertion has to be customized to the actual algorithm. Inserting at Index and Sorted Insert are going to cause you to reassign the pointers completely differently There is no reason for arbitrary insertion. All insertion happens at head or tail in a Linked List. You need to be aware the multiple cases might need to be dealt with. For instance your arbitrary insertion might actually be at the head or tail meaning your have to reassign head/tail properly When you arbitrary insert into a Linked List ... first you insert the node at head, then reassign the pointers physically moving the node through the list until it's in the right spot. The main difficulty in the algorithm comes from finding the insertion point. Regardless of how that point is found, the actual insertion plays out the same

You need to be aware the multiple cases might need to be dealt with. For instance your arbitrary insertion might actually be at the head or tail meaning your have to reassign head/tail properly The main difficulty in the algorithm comes from finding the insertion point. Regardless of how that point is found, the actual insertion plays out the same

What type of value are stored within a pointer type? a character value. a integer value, which represents the address. a string value, which represents the address. a decimal (float), which represents the address.

a integer value, which represents the address.

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

a longer machine code but with shorter execution time.

Consider C++'s typing system. C++ uses (Select all correct answers) value semantics for its primitive types (such as integer and float) only. both value semantics and reference semantics for its primitive types . reference semantics for its object types only. both value semantics and reference semantics for its object types.

both value semantics and reference semantics for its primitive types . both value semantics and reference semantics for its object types.

Assume that you want to delete the entire linked list pointed to by head. Which of the following deletion operation will cause the most garbage of memory? free(head); head = null; head = null; p= head; while (p != null) { p = p->next; free(head); head = p; } free(head->next); free(head); head = null;

head = null;

The memory must be explicitly garbage-collected, if the memory comes from heap static stack stack frame

heap

Which of the following statements will assign the address of the variable int myInt to the pointer int* myPtr? int* myPtr = myInt; int* myPtr = *myInt; int& myPtr = &myInt int* myPtr = &myInt;

int* myPtr = &myInt;

Given the snippet of code: int x = 5; int bar(int j) { int *k = 0, m = 5; k = &m; return (j+m); } void main(void) { static int i =0; i++; i = bar(i) + x; } Which variables obtain their memory from the stack? Select all that apply. i j k m x

j,k,m

The semantics of multiple inheritance becomes complex and error prone, if the base classes have members with different names. variables using different types of memory. overlapped members. variable using the same type of memory.

overlapped members.

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

p = (struct contact *) malloc(sizeof(struct contact)); ... p->next = head->next; head->next = p;

Given the information below, how do you insert a new node, p, to the beginning of a linked-list. Assume head is pointing to the first node in the linked-list. struct Terminal { char name[30]; char location[32]; struct Terminal* next;} *head, *p; p->next = head; head = p; head = p; p->next = head; head = p; p->next = head;

p->next = head; head = p;

Given the declaration: char A[3] = {'C', 'a', 'r'}, *p = A; what statement prints character a? printf("%c", *p); printf("%c", *p++); printf("%c", *p+1); printf("%c", *(++p));

printf("%c", *(++p));

How do you properly delete the first node of a linked list pointed to by head, assuming that the linked list is not empty and temp is another pointer of the same type? temp = head; head = head->next; free(temp); head = head->next; free(head); head = head->next; free(head);

temp = head; head = head->next; free(temp);

Java programmers do not need to do garbage collection, because Java does not use heap memory. does not use static memory. does not use stack memory. uses a system program to collect garbage.

uses a system program to collect garbage.

Given this snippet of code, determine which of the following options will change the text in array to "Hello Doe" after execution. (Check all that applies.) char array[] = "Hello Joe"; char *x; x = array; *(x + 6) = 'D'; x = array; x = x + 6; x = 'D'; x = &array; x = x + 6; x = 'D'; x = &array[0]; x = x + 6; *x = 'D';

x = array; *(x + 6) = 'D'; x = &array[0]; x = x + 6; *x = 'D';

Given the information below, which of the following snippet of codes will print every terminal in the linked-list without any side-effects of changing the state. Assume head is the only reference to the linked-list and there are more than one terminal in the list. struct Terminal { char name[30]; char location[32]; struct Terminal* next; } *head, *x; x = head; while(x != NULL) { printf("%s - %s", x->name, x->location);x = x->next;} x = head; while(x->next != NULL) { printf("%s - %s", x->name, x->location); x = x->next;} while(head != NULL) { printf("%s - %s", head->name, head->location); head = head->next;} while(head->next != NULL) { printf("%s - %s", head->name, head->location); head = head->next;}

x = head; while(x != NULL) { printf("%s - %s", x->name, x->location); x = x->next;}

Given the information below, how will you access the name for a terminal node pointed to by x? struct Terminal { char name[30]; char location[32]; struct Terminal* next;} *x; *name; &name; x.name; x->name;

x->name;

Given the following class definition and the variable declaration: class employee char *name; long id; } class manager { employee empl; char* rank;} x Which of the following assignment statement is correct? x.id = 12345; x.empl.id = 12345; x->id = 12345; x.empl->id = 12345;

x.empl.id = 12345;

If A is the base class and B is a class derived from A, and x and y are pointers to objects of A and B, respectively, which assignment statement can pass the compiler check? x = y; y = x; A = B; B = A;

x=y;


Ensembles d'études connexes

Real Estate GA state practice exam

View Set

NorthWestern Mutual Life Insurance Test

View Set

Chapter 27 26, 25 Bleeding,24 Trauma 12 1 13 14 Airway Management - 10, 6, 5

View Set

Biology Chapter 3: Chemical Building Blocks of Life

View Set

9 клас карпюк Magic Box

View Set

Chapter 11-Domestic and International Sales

View Set

Health and Life Licensing: Chapter 1

View Set