CSE Test 2
What are relational Operators?
"==" equals to "!=" not equals to ">" greater than "<" less than ">=" greater than or equal to "<=" less than or equal to
WHILE LOOP
(conditional statement) [if it's true] Execute all the code in between curly braces 1. It reassess at top of loop to see if the condition is still true 2. Will run 0 to infinite number of times 3. indeterminate
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,18
Consider the snippet of code: What will this code print? int y=1; int x=1; PRINTLINE(x++);
1
What are the characteristics of an array?
1. Can be broken down into elements 2. Series is of the same data type 3. Uses [ ] to create and access them 4. Starts with an index of 0 5. Fixed size
What are the five components of an algorithm?
1. Data Structures to hold data 2. Instructions to change data value 3. Conditional expressions to make decisions 4. Control structures to act on decisions 5. modules to make manageable by abstraction
What three things must a loop have?
1. Initialization - have an initial condition 2. Condition - Have a test to continue 3. Increment - make progress towards finishing
DO WHILE LOOP
1. Will run at least once 2. Do this line of code while it's true we loop 3. indeterminate Do { <insert code here> }while (loop - continuation- conditional);
What is the value of j after this code is executed? int i = 6, int j=10; j+=i;
16
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);
800
What is a variable?
A chunk of the computer's memory that can hold a value and a "type"
Selection Sort
A sorting routine that uses a nested loop process to systematically select the best value among the unsorted elements of the array for the next position in the array, starting with position zero all the way to the end.
What are mathematical operators?
Addition: + subtraction: - Multiplication: * Divison: / Modulus (remainder): %
What is a boolean expression?
An expression that resolves true or false
Binary Search
An ordered list is divided in 2 with each comparison.
What are the logical operators?
And && OR || NOT !
Bubble Sort
Bubble sort repeatedly pair-wise examine elements and swap them if needed
Select the correct declaration for 2D array of 5 rows and 10 columns: CREATE myArray[5,10] OR CREATE myArray[5][10] CREATE myArray(5,10) OR CREATE myArray(5)(10) CREATE myArray[10,5] OR CREATE myArray[10][5]
CREATE myArray[5,10] OR CREATE myArray[5][10]
What is the Basic Program Structure for any language?
Class Name Main Method Input/Read Statement, Output/Write Statement Assignment Statement
What is a string literal?
Contains 0 or more characters enclosed with double quotes
Name three words to describe arrays
Contiguous homogeneous static
Which of the following programming terms is enforced by declaring class attributes as private?
Encapsulation
A String (or string) object is a primitive data type.
False
All method (function) headers must include parameters
False
All methods must have a return statement
False
If x = 3, y = 1, and z = 5 then the following Boolean expression evaluates to true: ( x > 0) && (y == 0) || (z < 5)
False
In programming && is considered an arithmetic operator.
False
Input is sending messages to the console/user
False
Methods can only return primitive data types
False
Output is process of reading information from user, usually via keyboard or mouse.
False
Pseudocode form of writing should be used only when the logic of the program is complex.
False
Strings are a primitive data type which support the '+' operation.
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.
False
What is the best way to tackle a coding problem?
IMPO Input - what info do you need from the user? Memory - What do I need to store? Processing - What calculations do I need? Output - What will I display to the user?
ArrayLists have the following advantage over Arrays
Increase and decrease size dynamically Provide methods to add, insert, remove or find elements
What data types can a switch statement use?
Int type Char type string type - in java or C#
IDE stands for
Integrated Development Environment
What is the Skeleton Program
It defines the entry/starting point. Smallest program you can write - it does nothing. Begin Main End Main
What is implicit conversion?
It happens on its own going from a smaller type to a larger one
What is explicit conversions?
It has to be told to do it and going to larger to smaller
What is an expression?
It is a combination of one or more operators and operands
What is an algorithm?
It is a step by step procedure for solving a problem.
What is abstraction?
It is reducing information and detail to focus on essential characteristics.
What is pseudocode?
It is shorthand notation used in programming that combines informal programming structures and verbal descriptions of code
Consider the array declaration and instantiation: int[ ] arrayOne = new int[5]; Which of the following is true about arrayOne?
It stores 5 elements with legal indices from 0 to 4
FOR LOOP
Loops that have a predetermined beginning, end, and increment (step interval). run explicitly number of times - the number is specified or determinant for (block; block; block) { } for (at the beginning of the loop, do this; stop the loop if this is true; do this after each 'cycle' of the loop)
What is an expression a combination of?
Operators or symbols operands or variables/numbers
Postfix Increment
Postfix increment says to use my existing value then when you are done with the other operators; increment me. Int oldest = 44; Age = oldest ++;
Prefix Increment
Prefix increment says to increment me now and use my new value in any calculation. Int oldest =44; Age = ++oldest;
Consider two variables x and y. If the values of x =5 and y=10 if (x < 0) { cout << "Mr.Spock"; } else { if (x > y) { cout << "Captain Kirk"; } else { cout << "Star Trek it is!!!"); } }
Star Trek it is!!!
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; }
The loop won't terminate. It's an infinite loop.
What is the Operator Precedence?
The set of rules that dictates the order in which operators are evaluated in an expression. 1. Math 2. Relational 3. Logical
What is an operand?
They may be literals, constants, and variables
2D Arrays are still homogeneous.
True
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
A flowchart is a type of diagram that represents an algorithm, workflow or process.
True
A logical operator used when comparing primitive data types is !=.
True
An array index cannot be of the double, float or String data types.
True
An if statement does not need to have an else clause
True
Formal parameters in method headers require including the data type for each parameter in source code.
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
If the variable isTested is a Boolean, then the statement below is a valid control expression (in all three languages): if (isTested)
True
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? int result = number % 2; if (result == 0) cout << "TRUE"; else cout << "FALSE";
True
In general, the advantage of using a binary search over a linear search increases when searching larger sorted arrays.
True
Is this valid syntax for a FOR loop? for(int j = 0; j < 1000; j++) x--; // where x is a positive integer
True
Once an array is created, it cannot be resized during program execution.
True
Software testing involves the execution of a software component or system component to evaluate one or more properties of interest.
True
Strings are immutable which means once a String object is created its contents cannot be changed.
True
The MAIN method tells the program where to begin running code as it is the entry or starting point for the program.
True
The body of a method can be empty
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- IF...ELSE statements use a Boolean Expression as their condition to determine which code to run, while a SWITCH uses a single variable.
Linear Search
a method for finding a target value within a list. It sequentially checks each element of the list for the target value until a match is found or until all the elements have been searched.
Pseudocode is
an informal high-level description of the operating principle of a computer program or algorithm
Name the 8 primitive dative types
byte, short, int, long, float, double, boolean, and char
What is a continue statement?
causes the loop to stop its current iteration and begin the next one
Object Oriented Programming is categorized by use of
classes and objects
The parameters in the method call (actual parameters) and the method header (formal parameters) must be the same in
data type, sequence, quantity
Programming starts with
developing an algorithm
What is an undetermined loop?
don't know how many times a loop will run do while loop while loop
What is white space?
empty area and ignored in program but enhances readability
What is the return statement
exits a function and returns to the statement where the function was called
An object is a primitive data type
false
Array Lists can be multi-dimensional
false
you can only use FOR loops for arrays
false
The Boolean expression ((A and B) and (not(A and B)) evaluates to:
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.
int
When a variable is declared within a method and its scope is within the method it is known as a(n)
local variable
A distinguishing feature of methods that have the reserved word void in the method header is that they have
no return statement
Which of the following correctly refers to the last element in the array of integers called numbers?
numbers[length of numbers-1]
Elements in an ArrayList are stored as:
objects
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 an index out of bounds error.
Debugging is the process of
solving errors in the source code.
Program design consists of
steps a programmer should do before they start coding a program in a specific language.
Insertion Sort
taking a new item and place it correctly relative to the other items in the "finished" portion (left hand and right hand)
new is the reserved word used to create an object
true
An object's method is called by
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: value > 30 AND value == 30 value > 30 OR value == 30 NOT(value < 29) NOT(value > 31)
value > 30 OR value == 30
How can a break be used?
with a switch to make it act like a case structure or as part of a looping process to break out of the loop.