CSE 240

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) What is output?

"I'm a number"

Given this procedure, what is the expected result? (map (lambda (x) (+ x x 2)) '(1 2 3 4 5 6)) 1. (4 6 8 10 12) 2. (1 2 3 4 5 6) 3. (4 6 8 10 12 14) 4. Error Message

(4 6 8 10 12 14)

Which of the following is equivalent to the expression below? (car (cdr '(1 2 3 4 5)) 1. (cadr '(1 2 3 4 5)) 2. (caddr '(1 2 3 4 5)) 3. (cdar '(1 2 3 4 5)) 4. (cacdr '(1 2 3 4 5))

(cadr '(1 2 3 4 5))

Compare the follow two Scheme forms: (append '(1 2) '(4 5)) and (cons '(1 2) '(4 5)). 1. Both return "Error". 2. (append '(1 2) '(4 5)) returns '((1 2) 4 5). 3. Both return: '(1 2 4 5). 4. (cons '(1 2) '(4 5)) returns '((1 2) 4 5).

(cons '(1 2) '(4 5)) returns '((1 2) 4 5).

Which of the following expression will return false (#f)? 1. (number? 10) 2. (number? 15.6) 3. (number? #\7) 4. (number? -1)

(number? #\7)

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

1, 3

What notation does Prolog use for expressing arithmetic operations? 1. infix notation 2. prefix notation 3. BNF notation 4. postfix notation

1. infix notation

Functional programming language is more friendly to parallel computing, because it supports: 1. Eager Evaluation 2. Lazy Evaluation 3. Loop 4. Tail-Recursion

Eager Evaluation

Given this procedure, what is the expected result? (map (lambda (x) (+ x x 2)) '(1 2 3 4 5 (6 7))) 1. Error Message 2. (1 2 3 4 5 6) 3. (2 4 6 8 10 12) 4. (4 6 8 10 12 14)

Error message

Reliability speaks to how easily a programmer can express themselves reliably within the language.

False

True or False: In Backus Naur Form, non-terminals contained in () are required in the syntax.

False

Is sort orthogonality one-to-many, many-to-many, or a general lack of restriction?

One-to-many

Which of the following cannot be checked by an imperative or object-oriented compiler. (Check all that applies.) 1. Lexical 2. Semantics 3. Contextual 4. Syntactic

Semantics

Which of these parts of RAM are automatically controlled by the program/memory manager? Select all that apply 1. Stack 2. Static 3. Heap

Stack, static

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

They have different visibility.

What is the best of deleting all the nodes in a binary tree pointed to by the root pointer?

Traverse the tree and delete each node individually.

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

True

True or False: Autocode and FORTRAN are considered to be the first high-level programming languages.

True

True or False: Backus Naur Form allows for recursive definitions of non-terminal symbols. The definitions are usually separated with a | (aka a "pipe").

True

True or False: C++ was designed to bring Object Orientation to C. In fact it was originally released with the unimaginative name "C with Classes"

True

True or False: There was an early focus on efficiency due to early programmable computers being themselves fairly inefficent being limited in power and storage.

True

True or false: All pointers are the same size and that size is dependent on the architecture of the processor.

True

True or false: C++ has multiple forms of inheritance

True

How does Scheme implement the function such as: for (i = 1; i< 100, i++) {sum = sum + i;}

Use recursion

In contrast to Web 1.0, what is the key function of Web 2.0? 1. Web is the computing platform 2. Web supports graphic display 3. Web supports semantic analysis 4. Web is accessed over HTTP protocol

Web is the computing platform

Given 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> Is the following valid? 2sum = 2+3;

Yes. It follows the variable/assign rules

A let-form in Scheme is equivalent to: 1. an unnamed procedure. 2. a global name. 3. a tail-recursive procedure. 4. a named procedure.

an unnamed procedure

Filter is a higher-order function that 1. can check the equality of all types of data. 2. applies a function to all elements of a list. 3. allows a variable number of arguments. 4. reduces a list of elements to a single element.

applies a function to all elements of a list.

Which of the following types is a C++ type, but NOT a C type? 1. bool 2. char 3. double 4. void

bool

Given the following Scheme definition: (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? 1. Call-by-reference 2. Call-by-name 3. Call-by-value 4. Call-by-address

call-by-name (think functional paradigm capabilities)

A fact starts with a relationship followed by a list of arguments. The arguments of a fact: 1. can have a structure similar to that of a fact. 2. must be variables. 3. must be simple values. 4. can have a structure similar to that of a rule.

can have a structure similar to that of a fact.

Explicit type conversion is commonly refer to as __________ .

casting

In C++, what function can be used to input a string with spaces? 1. scanf("%s", &str); 2. cin >> str; 3. cin.getline(...); 4. scanf.getline(...);

cin.getline(...);

Event-driven computing paradigm is to 1. enable multiple tasks running on different processors. 2. define a set of events and write an event handler for each event. 3. require the program to execute in a predefined order. 4. write requirements without having to write any program.

define a set of events and write an event handler for each event.

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

different stack frames.

What is a feature of object-oriented computing? 1. Stateless 2. encapsulation of states 3. platform-independent 4. Side-effect free

encapsulation of states

In Scheme, the form (symbol-length? 'James) will return what? 0 5 6 error message

error message

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

false

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

have side-effect

Which of the following statements will assign the address of the variable int myInt to the pointer int* myPtr? 1. int* myPtr = myInt; 2. int* myPtr = *myInt; 3. int& myPtr = &myInt 4. int* myPtr = &myInt;

int* myPtr = &myInt;

For functional programming languages, the scope of a local name: 1. is always the entire program. 2. starts immediately at the point when the name is declared. 3. is in the body part of the declaration or definition. 4. is exactly same as object-oriented programming languages such as C++.

is in the body part of the declaration or definition.

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. 1. i 2. j 3. k 4. m 5. x

j, k, m

Which of the following constructs break or bend the normal functional programming rules of scheme? (select all that apply) 1. define 2. lambda 3. let 4. cond 5. if 6. begin

let, begin

What operations will acquire memory from heap? Select all that apply. 1. malloc 2. new 3. free 4. declaration

malloc, new

Compositional Orthogonality is:

many-to-many

How many different identifiers can the following BNF ruleset generate? <char> ::= a | b | c | ... | x | y | z <identifier> ::= <char> | <char> <identifer> 1. 26 2. 1 3. more than 26 4. None

more than 26

It does not cause memory (storage) overhead to create multiple: 1. names (alias) for a variable. 2. pointers to a variable. 3. copies of a variable. 4. 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? 1. array of int and string 2. pointer type and unsigned int 3. long int and double 4. wchar_t and char

pointer type and unsigned int

During compilation, linker is used for ___________________.

resolving external references (bring in code from other libraries).

Which command will have a loop when expressed in a syntax graph? 1. while-loop 2. if-then-else 3. switch 4. if-then

switch

The key idea of logic programming paradigm is to solve a problem by describing: 1. where the problem comes from. 2. the problem in a set of mathematic formulas. 3. what the problem is. 4. how to solve the problem in steps.

what the problem is.

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

A compilation error will occur.

True or false: C++ Inheritance is identical in every way to Java.

False

What computing paradigm can solve a problem by describing the requirements, without writing code in a step-wise fashion to solve the problem. 1. imperative 2. functional 3. object-oriented 4. logic

logic

Given this expression, what is the expected result? (car (cdr '(1 2 3 4 5)) 1 2 3 4

2

Number orthogonality is:

General lack of restriction on reproducing features in your code

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

1, 2

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

1, 2, 3

Why does the datatype of the pointer matter? Select all that apply 1. The datatypes have rules about addressing the pointer needs to work within those rules 2. It's only a readability feature that makes it clear what a pointer is for 3. When we do pointer arithmetic, the number of bytes the address changes is based on data type 4. If I dereference a pointer, the datatype informs how many bytes are going to be interpreted and how to interpret them

1, 3, 4

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; 1. 10 2. 100 3. 1000 4. None of the above.

10

Given the Scheme code, answer the following questions: ((lambda (x) ((lambda (x y) (+ x y)) 4 (* 6 x))) 3) a) The value to be passed to the parameter y is _ . b) The final output of the piece of code is _ .

18, 22

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

When evaluating a programming language the category Reliability describes: 1. The 'first concern' historically. Concerned with how fast the code compiles and run 2. This concept is concerned with the simplicity and understandability of the language... features, constructs, orthogonality, etc. 3. This concept is concerned with the actual production of code and the ability of the programmer to easily use the language... syntax, abstraction, expressivity ... 4. This concept is concerned with the internal safety and consistency of the language ... type checking, exceptions, etc. 5. This concept asks how tied down a language is to a particular platform, can code be distributed easily and can libraries be made and shared

2

Select all that apply: What does it mean for a function to be a "first class citizen"? 1. Functions become robust systems like Classes in OOP 2. Functions can be created and used anywhere and also assigned to an identifier to be reused. 3. Functions can be added together like numbers 4. Functions can be returned from a function 5. Functions can be appended to like strings 6. Functions can be passed to other functions as parameters

2, 4, 6

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? 1. A pointer to Book node 2. A pointer to Publication node 3. A pointer to Report node 4. A pointer to Thesis node

2. A pointer to Publication node

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

3, 4, 5

Select all that apply: Our primary objectives in functional programming are: 1. To model algorithms in a state-machine like format 2. Modeling data into classes/objects that intercommunicate to solve software issues 3. Raising our abstraction towards math 4. Code free of side effects 5. Modeling data into a fact-base to be queried 6. Removing state from programming 7. Functions should be as pure as possible following a pattern of Input->Processing->Output

3, 4, 6, 7

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

3. *myPtr = 10;

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? 1. 1374360 2. 1374358 3. 1374352 4. 1374344 5. Unknown - we are not given the storage address of ptr1

4. 1374344

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

40 (explanation: ints = 4 bytes. The array size is 4 * 10 = 40

When evaluating a programming language the category Reusability describes: 1. The 'first concern' historically. Concerned with how fast the code compiles and run 2. This concept is concerned with the simplicity and understandability of the language... features, constructs, orthogonality, etc. 3. This concept is concerned with the actual production of code and the ability of the programmer to easily use the language... syntax, abstraction, expressivity ... 4. This concept is concerned with the internal safety and consistency of the language ... type checking, exceptions, etc. 5. This concept asks how tied down a language is to a particular platform, can code be distributed easily and can libraries be made and shared

5

True or False: With over 500 programming languages in the world, the best way approach to learning languages is to focus on memorizing syntax and structure. Then learn languages with simimlar syntaxes and structures.

False

True or false: 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.

False

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

False

True or false: Dynamically allocated data/objects/etc. are created and exist on the Stack part of RAM 1. True 2. False

False

C++ only has two visibility modifiers: Public and Private 1. True 2. False

False (it has 3 which are public, private, protected)

Which programming paradigm focuses primarily on the "how" of programming and the step-by-step execution of algorithms? 1. Imperative/Procedural 2. Object-Oriented 3. Service Oriented 4. Functional

Imperative/Procedural

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

Interpretation (has good debugging information)

Context Error asks what?

Is the statement built from the right stuff?

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? 1. A compilation error will occur at this line: while (*p != '\0') 2. It prints: carbike 3. It prints: carb 4. A compilation error will occur at this line: char *p = &a[0][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? 1. It prints: dbu 2. A run time error will occur at this line. 3. It prints: a string of random characters 4. It prints: cat

It prints: dbu

Which of the following coding practice can lead to a higher memory efficiency (use fewer padding bytes) in defining a structure? 1. Keep the character type variables together. 2. The order of the members in a structure does not increase or decrease the structure size. 3. Keep the word-type variables together. 4. Place the word-type of variables (such as int, float, pointer) between the character-type variables.

Keep the character type variables together.

Which programming paradigm is focused primarily on the data and how it is modeled and used? 1. Object-Oriented 2. Imperative/Procedural 3. Service Oriented 4. Functional

Object-oriented

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

One compiler for all machines

What is the major improvement of structured programming languages over the earlier programming languages? 1. Introducing variables. 2. Allowing code reuse. 3. Not allowing the use of variables. 4. Removing Goto statement from the language

Removing Goto statement from the language

Select all that apply: Identify the DIFFERENCES between a global variable and a static variable: 1. Scope 2. Static Ram 3. Persistent Value 4. Only initialized once 5. Static keyword

Scope, Static keyword

PEBCAK Error is what?

When the user/programmer is being stupid

Given 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> Is the following valid? myvar = (x + y) * (a - c);

Yes. variable = expression (operator) expression. (Reminder: | means or)

Given the Scheme code below, answer the following questions related the Fantastic Four abstract approach. (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 a) What line of code defines the stopping condition and the return value? (2) What line of code contains the size-M problem, where M < N? (3) What lines of code define the step that construct the solution to size-N problem?

a) Line 2 b) Line 3 c) Lines 3 and 4

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

const x = 5;

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

contain one class in the other (containment).

The display form (display "Hello") violates the functional paradigm because it: 1. outputs a result. 2. does not have a return value. 3. can output text only. 4. is an invalid form.

does not have a return value.

The memory must be explicitly garbage-collected, if the memory comes from _

heap

We need to write a destructor for a class, if 1. heap memory is used in the constructor of the class. 2. stack memory is used in the constructor of the class. 3. if heap memory is used on the main() function, and the main() function uses the class to instantiate an object. 4. if stack memory is used on the main() function, and the main() function uses the class to instantiate an object.

heap memory is used in the constructor of the class

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? 1. 9 2. 68 3. 8 4. 64

idk answer

What is NOT the purpose (functionality) of the forward declaration (prototype)? 1. to serve as an index to the functions 2. to satisfy scope rule 3. to allow functions to be ordered in any way 4. to allow mutually recursive functions 5. to allow functions to return different types of values

to allow functions to return different types of values

The Scheme form (char? #\5) will return: 1. true (#t) 2. false (#f) 3. 5 4. Error meesage

true (#t)

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?

x = 6, y = 7

For the following BNF ruleset, which are terminal symbols? (Check all that apply.) <char> ::= a | b | c | ... | x | y | z <identifier> ::= <char> | <char> <identifer> 1. <identifier> 2. y 3. a 4. ::= 5. | (or symbol)

y, a

What does one-to-many mean?

if you can combine one command in a set of command with another command in another

When evaluating a programming language the category Efficiency describes: 1. The 'first concern' historically. Concerned with how fast the code compiles and run 2. This concept is concerned with the simplicity and understandability of the language... features, constructs, orthogonality, etc. 3. This concept is concerned with the actual production of code and the ability of the programmer to easily use the language... syntax, abstraction, expressivity ... 4. This concept is concerned with the internal safety and consistency of the language ... type checking, exceptions, etc. 5. This concept asks how tied down a language is to a particular platform, can code be distributed easily and can libraries be made and shared

1

von Neumann Architecture is: 1. A state based programming structure which loads and interprets instructions from memory into action 2. A system for defining and understanding language syntax free from context 3. A system for designing buildings post-world war 2 which focused heavily on concrete as a primary material 4. A system for delivering service based software with a client/producer model. Possibly the next major programming paradigm

1

What features are supported in C++? Select all that apply. 1. Virtual function 2. Function overloading 3. Operator overloading 4. Virtual operator

1, 2, 3

Which commands (constructs) do NOT have a loop when expressed in syntax graphs? Select all that apply 1. if-then-else 2. while (condition) do {statements;} 3. switch (expr) { case value: statements ;} 4. for ( <init-expr>; <test-expr>; <increment-expr> ) {<statements>}

1, 2, 4

Select all that apply. Which statements indicate why it is important to understand dynamic multi-dimensional arrays as "arrays of arrays"? 1. Dynamic allocation requires multiple pointers and each pointer can 'point' to it's own array 2. 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. 3. The memory is constructed such that it could actually be understood as a single dimension array if you're willing to do the math. 4. 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. 5. Each row is independently created at run-time 6. 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.

1, 2, 4, 5

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

1, 3

Which predicate logic matches most closely with this statement? "Bill listens to music or news." 1. listensto(bill, music, news, talkshow). 2. listensto(bill, music); listensto(bill, news). 3. listensto(Bill, music); listensto(Bill, news). 4. bill(listensto, music); bill(listensto, news).

2. listensto(bill, music); listensto(bill, news).

What is true about Encapsulation in C++ vs. Java? 1. There is no real difference in concept, just in Syntax. Visibility Modifiers are categories instead of line-to-line keywords. 2. In C++ private and protected are the same thing 3. 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. 4. C++ only allows you to use Public, Private and Protected once each.

1, 3

A goal succeeds, if there are facts (rules) that match or unify the goal. What are required in order for a goal clause and a fact to unify? Select all that apply. 1. their predicates are the same. 2. their arity must be different. 3. they have the same number of arguments. 4. their corresponding arguments match.

1, 3, 4

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

1. It prints: carbike

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

1. It saves the word Hello into a file in the file system. (because it says OFstream)

Visibility modifiers, match: 1. Public 2. Private 3. Protected a. Member is accessible via any created object as well as internally and in inheritance b. Member is accessible in the class that defines it not externally or in inheritance c. Member is accessible internally and in inheritance, but not externally

1. Matches with a 2. Matches with b 3. Matches with c

Match: 1. :: 2. : 3. <library>.h 4. <library>.cpp a. Scope resolution operator b. Inheritance operator c. The file we generally forward declare our classes and methods in d. The file we generally put our method definitions in

1. Matches with a 2. Matches with b 3. Matches with c 4. Matches with d

Match the C++ inheritance idea to its best description: 1. Public inheritance 2. Protected inheritance 3. Private inheritance a. This method of inheritance allows for private members of the parent to be accessible in the child. b. 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. c. 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. d. 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"

1. Matches with b 2. Matches with c 3. Matches with d

The imperative programming paradigm is popular and is a part of object-oriented computing paradigm, because it ____ (Select all answers that apply). 1. is based on computer organization and thus is efficient to execute on hardware. 2. matches the culture of doing things by following the step-wise instructions. 3. enforces the modularity and supports the development of large programs. 4. supports class inheritance and code reuse.

1. is based on computer organization and thus is efficient to execute on hardware. 2. matches the culture of doing things by following the step-wise instructions.

Assume a varible is declared in a block of code within a pair of curly braces. The scope of the variable ______ 1. starts from its declaration point and extends to the end of the block. 2. starts from its declaration point and extends to the end of the entire program. 3. covers the entire block, including the code before the declaration point. 4. covers the entire program, including the code in the other blocks.

1. starts from its declaration point and extends to the end of the block

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; 1. 10 2. 100 3. 1000 4. None of the above.

1000

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

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

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

2. a integer value, which represents the address.

Given these facts: is_dessert(cookie). 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 identify the list of desserts that contains apple? 1. apple_dessert(X) :- is_dessert(X), is_fruit(X). 2. apple_dessert(X) :- is_dessert(X), contains(X, apple). 3. apple_dessert(X) :- is_dessert(X), contains(X, _). 4. apple_dessert(X) :- is_dessert(X); contains(X, apple).

2. apple_dessert(X) :- is_dessert(X), contains(X, apple).

Which predicate logic matches most closely with this statement? "Bill likes chocolate and cookies." 1. likes(bill, chocolate); likes(bill, cookies). 2. likes(bill, chocolate), likes(bill, cookies). 3. bill(likes, chocolate), bill(likes, cookies). 4. likes(bill, chocolate, cookies, icecream).

2. likes(bill, chocolate), likes(bill, cookies).

When evaluating a programming language the category Writeability describes: 1. The 'first concern' historically. Concerned with how fast the code compiles and run 2. This concept is concerned with the simplicity and understandability of the language... features, constructs, orthogonality, etc. 3. This concept is concerned with the actual production of code and the ability of the programmer to easily use the language... syntax, abstraction, expressivity ... 4. This concept is concerned with the internal safety and consistency of the language ... type checking, exceptions, etc. 5. This concept asks how tied down a language is to a particular platform, can code be distributed easily and can libraries be made and shared

3

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: int* ptr1 = &num3 ptr1 = ptr1 + 5; What will be the address contained in ptr1? 1. 1877192 2. 1877197 3. 1877212 4. 1877220 5. Unknown - we are not given the storage address of ptr1

3. 1877212 Explanation: to get answer, you do data type data value * added spots = new address. Example: int = 4 bytes. 4 * 5 = 20. Since we're currently at num3 address (1877192) we add 20 to it to get the answer.

char *p = "hello", *s = "this is a string"; strcpy(p, s); printf("%s\n", p); What will happen? 1. It prints: hello 2. It prints: this 3. A compilation error will occur at this line: strcpy(p, s); 4. A run time error may occur at this line: strcpy(p, s);

A run time error may occur at this line: strcpy(p, s);

During data declaration, a name is binded to a memory location, what else can be identify as part of this process? 1. Data Type 2. Scope 3. Qualifier 4. All of the above.

All of the above

What does the following line of code define? bool operator>(const Cylinder &c) 1. An overloaded function Cylinder 2. An overloaded operator > 3. A virtual function Cylindarer 4. An overloaded operator &

An overloaded operator >

What programming language characteristics impact the readability of the programs written in this language? Check all that apply 1. Control structures 2. Type checking 3. Syntax design 4. Data structures

Control structures, syntax design, data structures

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

False

True or false: When creating a multi-dimensional array during compile time (on stack RAM) it is possible to create a "ragged array" - which is a multi-row array where the rows are not the same length.

False

True/False - This function is a Right-Fold pattern: (define foo1 (lambda (input)(if (null? input)0(if (eq? (modulo (car input) 2) 0)(+ 1 (foo1 (cdr input)))(+ 0 (foo1 (cdr input)))))))(foo1 '(1 2 3 4 5 6 7))

False

We use "Pass by Value" when: 1. Function does not want to modify the value, the value is expensive to copy and NULL is valid 2. Function wants to modify the value, the value is expensive to copy and NULL is valid 3. Function does not want to modify the value, the value is expensive to copy and NULL is not valid 4. Function does not want to modify the parameter and the value is easy to copy 5. 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

We use "Pass by Constant Reference" when: 1. Function does not want to modify the value, the value is expensive to copy and NULL is not valid 2. Function wants to modify the value, the value is expensive to copy and NULL is not valid 3. Function does not want to modify the value, the value is expensive to copy and NULL is valid 4. Function wants to modify the value, the value is expensive to copy and NULL is valid 5. 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: 1. Function does not want to modify the value, the value is expensive to copy and NULL is valid 2. Function does not want to modify the value, the value is expensive to copy and NULL is not valid 3. Function wants to modify the value, the value is expensive to copy and NULL is valid 4. Function wants to modify the value, the value is expensive to copy and NULL is not valid 5. 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

We use "Pass by Reference" when: 1. Function does not want to modify the value, the value is expensive to copy and NULL is valid 2. Function wants to modify the value, the value is expensive to copy and NULL is not valid 3. Function does not want to modify the parameter and the value is easy to copy 4. Function wants to modify the value, the value is expensive to copy and NULL is valid 5. 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: 1. Function does not want to modify the parameter and the value is easy to copy 2. Function wants to modify the value, the value is expensive to copy and NULL is valid 3. Function wants to modify the value, the value is expensive to copy and NULL is not valid 4. Function does not want to modify the value, the value is expensive to copy and NULL is valid 5. 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

Is number orthogonality one-to-many, many-to-many, or a general lack of restriction?

General lack of restriction on reproducing features in your code

Semantic Error asks what?

Is the program doing the right things?

Syntax Error asks what?

Is the statement built correctly?

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

It prints: catdog

Which language will report a compilation error for the following snippet of code? int i = 3; double n, j = 3.0; n = i + j; 1. Java 2. C 3. All of the above 4. C++

Java

Is compositional orthogonality one-to-many, many-to-many, or a general lack of restriction?

Many-to-many

Given 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> Is the following valid? my_int = int1 + int2;

No, not valid because of the underscore. To be valid, the underscore would have to be in the VSPL symbols

Given 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> Is the following valid? (a+b) = (x*y);

No, to assign you need a variable. <assign> ::= <variable> = <expr>;

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; 1. 10 2. 100 3. 1000 4. None of the above.

None of the above

Which of the following cannot be checked by an imperative or object-oriented compiler? 1. Lexical 2. Contextual 3. Syntactic 4. Semantics

Semantics

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

Semantics error

If I have set of commands S1 that describe data types in my language and a set of commands S2 that describe creation of variables: S1: int, decimal, bool S2: <type> <name>, <type> <name> = <value>, constant <type> <name> = <value> The set S3: int <name>, int <name> = <value>, constant int <name> = <value> -- demonstrates what kind of orthogonality?

Sort orthogonality

Given this snippet of code in Java char alpha = 'a';int numeric = alpha + 10; which of the following statement is correct: 1. Syntactically correct and contextually correct. 2. Syntactically incorrect, but contextually correct. 3. Syntactically incorrect and contextually incorrect. 4. Syntactically correct, but contextually incorrect.

Syntactically correct, but contextually incorrect.

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

True

True or false: Learning the concepts, logic and problem solving of programming unlocks our ability to learn knew languages.

True

True/False - This function is a Right-Fold pattern: (define foo1 (lambda (input)(if (null? input)0(if (eq? (modulo (car input) 2) 0)(+ 1 (foo1 (cdr input)))(+ 0 (foo1 (cdr input)))))))(foo1 '(1 2 3 4 5 6 7))

True

When is padding required for a structure type variable? 1. When the structure contains character type of variables. 2. 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. 3. As long as the size of the structure is not a multiple of four. 4. As long as the structure contains a word-type variable, such as integer, float, and pointer.

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.

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)? 1. Yes, always. 2. No, never. 3. Depending on the data type of the members. 4. Depending on if the members are static or not.

Yes, always.

The statement "a function is a first-class object" means that a function 1. must be instantiated from a class. 2. can be placed in a place where a value is expected. 3. must have a return value. 4. 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 1. is an interface only, and it does not allow to have implementation. 2. will acquire the memory from the stack. 3. can be redefined in its child classes. 4. will acquire the memory from the virtual memory in the disk storage.

can be redefined in its child classes.

If A is the base class and B is a class derived from A, then 1. class A has all the members of class B. 2. class B has all the members of class A. 3. classes A and B always have the same members. 4. class A becomes a member in class B.

class B has all the members of class A.

What is the correct way to declare a class in C++?

class Circle { private: double radius; public: void setRadius(double radius); double getDiameter(); double getArea(); double getCircumference(); };

What members of a base class can be redefined in the derived classes? 1. public members 2. private members 3. final members 4. virtual members

idk (NOT PUBLIC MEMBERS)

What does many-to-many mean?

if you can combine all the commands in one set with all commands in another set

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

delete[] p;

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

dynamic_cast

If I dynamically allocate a 1D array in C++ ... what command do I use to release the memory? 1. free_array() 2. delete[] 3. free() 4. delete

free()

What computing paradigm enforces stateless (no variable allowed) programming? 1. imperative 2. object-oriented 3. functional 4. service-oriented

functional

The primary module/unit of abstraction in Functional Programming is... 1. math 2. classes 3. methods 4. functions

functions

Which of the following constructs break or bend the normal Syntax patterns of scheme? (<thing I want to do> <things I want to do it too>) (select all that apply) 1. if 2. begin 3. define 4. list 5. let 6. cond 7. append

if, begin, let, cond

What programming paradigm does Fortran belong to? 1. imperative 2. object-oriented 3. functional 4. logic

imperative

What notation requires parentheses in order to correctly define the order of computation? 1. prefix notation 2. infix notation 3. postfix notation 4. all of the above

infix notation

Sort Orthogonality is _

one-to-many

Where is the main() function located in a C or C++ program? 1. in the Main class 2. in all classes 3. in any one class 4. outside any class

outside any class

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

overlapped members

A prolog program may contain: (Select all that apply.) 1. rules. 2. questions. 3. facts. 4. higher-order functions Map, Reduce, and Filter.

rules, questions, facts

In the C-Style input function scanf("%d", &i); What does the character "&" mean? 1. scanf takes an integer type variable as its parameter. 2. scanf takes the address of an variable as its parameter. 3. scanf takes the value of an variable as its parameter. 4. scanf takes multiple variables as its parameters.

scanf takes the address of an variable as its parameter.

A Prolog program finds a solution by: 1. searching the Internet. 2. using lambda expressions. 3. Boolean logic expressions. 4. searching the built-in database consisting of facts and rules.

searching the built-in database consisting of facts and rules

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

true

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

uses a system program to collect garbage

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

variables whose value can be modified.

In the following query language statement, which function acts as the filter function? var myQuery = from b in Books where b.price < 80 orderby b.title select b; 1. where 2. from 3. orderby 4. select

where

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? 1. x.id = 12345; 2. x.empl.id = 12345; 3. x->id = 12345; 4. 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

Chapter 9 - Thinking, Language, and Intelligence

View Set

Campbell Mastering Biology Ch. 2

View Set

Chapter 2: Animal Research Environment

View Set

Personal Finance: Chapter Fourteen

View Set

Glossary Of Life Insurance Terms

View Set