CSE 240

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

The size (number of bytes) of a structure-type variable can be changed by the following factors. Select all that apply.

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

What parameters are required when performing file operations fread and fwrite?

-destination -source -item size -number of items

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

-e-commerce -space fountain

Consider Java's typing system. Java uses (Select all correct answers)

-value semantics for its primitive types (such as integer and float) only. -reference semantics for its object types only.

When is padding required for a structure type variable?

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.

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;

What functional feature does the code below best exhibit? (define start-engine (lambda () (error-detection (wheel-velocity (wheel-sensor)) (body-velocity))))

procedures are first class object.

A critical step in writing a recursive function is to assume that the

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

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

static_cast

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?

binary search tree

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

dynamic_cast

In Scheme, the form (symbol-length? 'James) will return:

error message

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

false

If you declare a pointer to the object of the parent class and use the pointer to access the object of a child class, you can access

the members that exist in the parent class.

::

Scope resolution operator

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"

How do we include a user-defined library, say myMathLib.h, into a program that uses this library?

#include "myMathLib.h"

Convert the following expression into prefix-p notation (Scheme statement): 10 + (5 - 3) + 2 / 4

(+ 10 (- 5 3) (/ 2 4))

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

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

What's true about OOP in C++?

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

Select all that apply: Identify the differences between a global variable and a static variable:

-Scope -Static keyword

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

-Stack -Static

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

Given the following snippet of code, answer the following two questions based on the code: 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? 2. What value will be printed for variable y?

1. 6 2. 7

Assume this is a 32-bit environment, what is the size of x? struct Terminal { char name[30]; char location[32]; struct Terminal* next; } *x;

4 bytes

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;

68 bytes

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.

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

An overloaded operator ++

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.

Functional programming language is more friendly to parallel computing, because it supports

Eager Evaluation

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

False

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

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

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

We use "Pass by Reference" when:

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

We use "Pass by Pointer" when:

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

The complexity of inserting n numbers into a binary search tree is at least the order of

O(n)

:

Inheritance operator

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?

It prints: catdog

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.

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

Public

Member is accessible via any created object as well as internally and in inheritance

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 PublListNode class contains the Publication class.

What mechanism defines tail recursion?

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

<library>.h

The file we generally forward declare our classes and methods in

<library>.cpp

The file we generally put our method definitions in

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

True

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

True

A merge-short is typically implemented using

a function with two recursive calls.

A tail-recursive function is structurely equivalent to

a while loop

Defining a virtual function in class means that the function

can be redefined in its child classes.

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

char a2[size2];

If the relation between two C++ classes can be best described as "has-a" relation, we should

contain one class in the other (containment).

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?

head = null;

Given the information below, how will you access the name of the third terminal node in the linked-list? Assume head is pointing to the first terminal node and there are at least 3 terminals in the linked-list. struct Terminal { char name[30]; char location[32]; struct Terminal* next; } *head;

head->next->next->name;

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(item > current->data) return helpFindIt(current->right, item) if(item < current->data) return helpFindIt(current->left, item)

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

infix notation

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

inorder

What data structure is used in Scheme for representing extremely large integers?

list

What is the maximum number of padding bytes that a compiler can add to a structure?

more than 4

C++ has multiple forms of inheritance

true

Functional programming languages do NOT allow to define

variables whose value can be modified.

void deleteList(struct contact* node) { if (node != NULL) { deleteList(node->next); free(node); } else return; }

void deleteList(struct contact* node)

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

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;

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;

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.empl.id = 12345;


Kaugnay na mga set ng pag-aaral

Combo with "Homeowner's Insurance" and 27 others

View Set

Pharm - Ch. 49 Drugs to Treat Anemias

View Set

Exam 2 - quiz questions - Ch. 6,7, 8

View Set

Vocab Unit 1 CHOOSING THE RIGHT WORD

View Set

InQuizitive Sociology: Chapter 1

View Set

Chapter 11 Stress Psychology 2301

View Set