CSE1321- Final Exam

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

What is the output of the following code? int u = 3; int v = 5; u += v; v += u; u -= v; v -= u; PRINT (u + ", " + v); 5, 3 3, 5 -5, 18 -5,-3

-5, 18

Array index starts with: 0 1 2 -1

0

Consider the snippet of code: What will this code print? int y=1; int x=1; PRINTLINE(x++); 0 unknown 1 2

1

What is the value of j after this code is executed? int i = 6, int j=10; j+=i; 16 10 6 4

16

CREATE myArray[5][5] creates an array that can hold how many elements? 25 50 125 5

25

What is the output of the following code? int num1 = 500; int num2 = 200; int num3 = 300; double average = num1 + num2 + num3 / 3; PRINTLINE(average); Error message 333.0 333.33333333333 800.0

800.0

What are used to get values from private attributes? Accessor Getter Setter Mutator

Accessor and Getter

The parameters in the method call (actual parameters) and the method header (formal parameters) must be the same in quantity. data type. All of the other choices sequence.

All of the other choices

ArrayLists have the following advantage over Arrays: Both of these answers Increase and decrease size dynamically Provide methods to add, insert, remove or find elements

Both of these answers

Select the correct declaration for 2D array of 5 rows and 10 columns: CREATE myArray[10,5] OR CREATE myArray[10][5] CREATE myArray[5,10] OR CREATE myArray[5][10] CREATE myArray(5,10) OR CREATE myArray(5)(10)

CREATE myArray[5,10] OR CREATE myArray[5][10]

These are used to create new objects from a class: Constructors Destructors Creators Activators

Constructors

Which of the following programming terms is enforced by declaring class attributes as private? Encapsulation Escalation None of these answers Escape Sequences

Encapsulation

lements in an ArrayList are stored as: integers Objects floats chars

Objects

Which keyword makes attributes and methods secure and promotes encapsulation? PRIVATE PUBLIC SHARED SECURE

PRIVATE (special method to interact are getters and setters. Getter is return statements, setters take in parameter)

What is used to pass variables between methods? Parameters Parachutes Passengers Pajamas

Parameters/arguements

Objects are (two possible): Real world entities Distinctly identifiable Same as a class Same as a method

Real world entities/Distinctly identifiable (Writing classes: a stands for attributes, b stands for behaviors, c stands for constructor (order acb))

What are used to set values for private attributes? Accessor Getter Setter Mutator

Setter and Mutator

Arrays can hold which data types? Integers (int, byte, short & long) Decimals (double & float) Characters (Char) Objects

can hold all of these

Object Oriented Programming is categorized by use of classes and objects. modules to combine program statements used for a common purpose. Graphical User Interfaces. the goto statement

classes and objects.

Programming starts with writing code until it works. looking online for the answers. developing an algorithm.

developing an algorithm.

The Boolean expression ((A and B) and (not(A and B)) evaluates to: false in all cases. true in all cases. true whenever only A is true or only B is true. true whenever both A is true and B is true.

false in all cases.

What would be the best datatype to represent product? A variable that stores information about the number of items currently in stock in a grocery store. String double float int

int

When a variable is declared within a method and its scope is within the method it is known as a(n) local variable. global variable. public instance data. actual parameter.

local variable.

A distinguishing feature of methods that have the reserved word void in the method header is that they have a single return statement. none of the other answers multiple return statements. no return statements.

no return statements.

Which of the following correctly refers to the last element in the array of integers called numbers? numbers[length of numbers-1] numbers[last numbers] numbers[size] numbers[length of numbers]

numbers[length of numbers-1]

Consider an array values. The array is of size 7. The statement: System.out.println(values[7]);//Java Console.WriteLine(values[7]);//C# cout << values[7] << endl;//C++ will produce a syntax error. produce an index out of bounds error. output 7. output 0.

produce an index out of bounds error.

Debugging is the process of compiling the source code. writing source code. solving errors in the source code. publishing the source code to the client.

solving errors in the source code.

Program design consists of A) the ability to solve problems. B) writing the code for a program. C) writing the documentation for a program. D) steps a programmer should do before they start coding a program in a specific language.

steps a programmer should do before they start coding a program in a specific language.

Keyword used to remove ambiguity when assigning values in a class: this that there huh

this

An object's method is called by using the method name only. using the class name, followed by a period and the method name. using the object's name, followed by a period and the method name. using the object name only.

using the object's name, followed by a period and the method name.

Consider the expression: value >= 30 Which of the following is equivalent to this expression: NOT(value > 31) value > 30 OR value == 30 NOT(value < 29) value > 30 AND value == 30

value > 30 OR value == 30

Passed by value means: Values are copied to method's variables. Method's variables point to original variable memory space. Method cannot accept the variables. Method does not need parameters.

Values are copied to method's variables.

2D Arrays can hold two different types of data at the same time True/False

False

2D arrays have to have identical size rows and columns True/False

False

A CLASS method cannot access PRIVATE attributes True/False

False

A String (or string) object is a primitive data type. True/False

False

All method (function) headers must include parameters. True/False

False

All methods must have a return statement. True/False

False

An object is a primitive data type. True/False

False

Array Lists can be multi-dimensional. True/False

False

Arrays are able to be re-zieds as needed while program is running. True/False

False

If x = 3, y = 1, and z = 5 then the following Boolean expression evaluates to true: ( x > 0) && (y == 0) || (z < 5) True/False

False

In programming && is considered an arithmetic operator. True/False

False

Input is sending messages to the console/user. True/False

False

Method names can begin with numbers True/False

False

Methods can return only primitive data types. True/False

False

Methods can see and easily alter other method's variables True/False

False

Output is process of reading information from user, usually via keyboard or mouse. True/False

False

Parentheses can be left out if a method does not need any parameters. True/False

False

Pseudocode form of writing should be used only when the logic of the program is complex. True/False

False

Strings are a primitive data type which support the '+' operation. True/False

False

The statement int[] list = {5, 10, 15, 20}; (C# & Java) int list[] = {5,10,15,20}; (C++) gives an error since there is no new reserved word included in the statement. True/False

False

You can send a Method more parameters than declared in its signature True/False

False

You must use FOR loops to iterate through an array True/False

False

Arrays can hold different types of data at the same time. True/False

False (only homogenous)

IDE stands for Initial Degree Expectations Integrated Development Environment Intramural Department Executive

Integrated Development Environment

Consider the array declaration and instantiation: int[ ] arrayOne = new int[5]; Which of the following is true about arrayOne? It stores 6 elements with legal indices from 0 to 5. It stores 5 elements with legal indices from 1 to 5. It stores 5 elements with legal indices from 0 to 4. It stores 4 elements with legal indices from 1 to 4.

It stores 5 elements with legal indices from 0 to 4.

Overloading methods means: Sending more variables than parameters listed. Multiple methods of same name with different parameters. Crashing your program by running method too many times. Repeating code in a program.

Multiple methods of same name with different parameters

Keyword to call a class's constructor. NEW CREATE BUILD START

NEW

Method signature is: Name and parameter list Method name Parameter list Entire header

Name and parameter list

Type of loops used to iterate through a 2D array Nested Next Cascading Piggyback

Nested

Consider two variables x and y. If the values of x =5 and y=10 C++ if (x < 0) { cout << "Mr.Spock"; } else { if (x > y) { cout << "Captain Kirk"; } else { cout << "Star Trek it is!!!"); } } What is displayed as the result of the code being executed: Mr. Spock Nothing will be printed/displayed Star Trek it is!!! Captain Kirk

Star Trek it is!!!

Imagine a game of Yahtzee where a roll of dice always returns an even number. Consider the snippet of code where the number is variable that stores the value of the dice. What will the code display? C++: int result = number % 2; if (result == 0) cout << "TRUE"; else cout << "FALSE"; TRUE Unable to determine Neither condition is satisfied FALSE

TRUE

Consider variable x which is an int where x = 0, which statement below will be true after the following loop terminates? while (x < 100) { x *= 2; } x == 0 x == 2 The loop won't terminate. It's an infinite loop. x == 98

The loop won't terminate. It's an infinite loop.

Which keyword indicates nothing is being returned? Void Invalid Nothing Null

Void

2D arrays are declared in row, column order for C++, C# and Java. Meaning first value is number of rows, second value is number of columns. True/False

True

A flowchart is a type of diagram that represents an algorithm, workflow or process. True/False

True

A logical operator used when comparing primitive data types is !=. True/False

True

A return statement is required if a return type is declares in the header True/False

True

A switch statement is similar to an if statement in that both are used to alter the flow of a program if the specified test condition is true. True/False

True

A variable's scope starts when it is declared and stops at the end of the code block True/False

True

An array index cannot be of the double, float or String data types. True/False

True

An if statement does not need to have an else clause. True/False

True

Arrays are passed by reference True/False

True

Classes should be contained in their own file. True/False

True

D Arrays are still homogeneous. True/False

True

Formal parameters in method headers require including the data type for each parameter in source code. True/False

True

If the expression xyz % 3 == 0 is true and xyz is a positive integer, then the value stored in the variable xyz is evenly divisible by 3. True/Flase

True

If the variable isTested is a Boolean, then the statement below is a valid control expression (in all three languages): if (isTested) True/False

True

If you return a value from a method, you should do something with it. True/False

True

In general, the advantage of using a binary search over a linear search increases when searching larger sorted arrays. True/False

True

Is this valid syntax for a FOR loop? for(int j = 0; j < 1000; j++) x--; // where x is a positive integer True/False

True

Once an array is created, it cannot be resized during program execution. True/False

True

Parameters are matched by position in declaration and method call. True/False

True

Software testing involves the execution of a software component or system component to evaluate one or more properties of interest. True/False

True

Strings are immutable which means once a String object is created its contents cannot be changed. True/False

True

The MAIN method tells the program where to begin running code as it is the entry or starting point for the program. True/False

True

The body of a method can be empty. True/False

True

new is the reserved word used to create an object. True/False

True

Multiple constructors can be created with different parameters True/False

True (Overloaded)

Functions/Methods are (two possible): Written once, called many times Harder to comprehend Cause code to trace linearly There to reduce code size

Written once, called many times There to reduce code size

To assign "Hello" to the upper left corner of a 2D array you would use which set of indices [0][0] [0,0] [1][1] [1,1]

[0][0] and [0,0]

Pseudocode is A) a machine. B) an informal high-level description of the operating principle of a computer program or algorithm. C) a formal programming language.

an informal high-level description of the operating principle of a computer program or algorithm.


Ensembles d'études connexes

Introduction to Government Insurance Programs

View Set

Psych 100 - Brains, Bodies, Behavior

View Set

International Business final exam (exam 2)

View Set

Lab + Diagnostic Test 1 (Based on Class of 2019 Quizlet)

View Set