CSE 1321 Final Exam

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan 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, 18

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

1

Evaluate as an integer: 5 % 7 + 3 * 2 + 4 =

15

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

16

How many times will method1() be called with the following code? FOR (CREATE i=7, i < 10, i++) { method1(); }

3

BEGIN MAIN CREATE myArray[] = {9, -2, 30, -3, 98, 12}; CREATE max = array[0]; FOR (CREATE i = 1, i < 6, i++) IF(myArray[i] > max) max = myArray[i] END IF END FOR PRINT("The maximum value is " + max); END MAIN What is the length/size of myArray?

6

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); A. 800.0 B. 333.0 C. 333.3333333333 D. Error

A. 800

FOREACH loops cannot be used for which of the the following tasks? A. Assignment B. Printing C. Summing D. Searching

A. Assignment

Which of these sorts was not covered in the lecture slides? A. Merge B. Insertion C. Selection D. Bubble

A. Merge

A Method's signature is comprised of: A. Method Name and Parameter List. B. Method Name and Return Type. C. Return Type and Parameter List. D. Method Header and Body.

A. Method Name and Parameter List.

BEGIN MAIN CREATE myArray[] = {9, -2, 30, -3, 98, 12}; CREATE max = array[0]; FOR (CREATE i = 1, i < 6, i++) IF(myArray[i] > max) max = myArray[i] END IF END FOR PRINT("The maximum value is " + max); END MAIN What is the correct way to print the last element in myArray? A. PRINT (myArray[5]) B. PRINT (myArray[length+1]) C. PRINT (myArray(5)) D. PRINT (myArray[size])

A. PRINT (myArray[5])

This special input value is used to allow a user to end a loop: A. Sentinel B. Iteration C. Stop D. Stationary

A. Sentinel

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

A. 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 A. produce an index out of bounds error. B. output 0. C. output 7. D. produce a syntax error.

A. produce an index out of bounds error.

An object's method is called by: A. using the object's name, followed by a period and the method name. B. using the class name, followed by a period and the method name. C. using the method name only. D. using the object name only.

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

Which of the following is an advantage of creating and using methods in programs? A. Make code more obscure. B. Allow reuse of code. C. Increase complexity of code. D. Make program maintenance and updates harder.

B. Allow reuse of code.

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

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

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. int result = number % 2; if (result == 0) System.out.println("TRUE"); else System.out.println("FALSE"); What will the code display? A. Neither condition is satisfied B. TRUE C. Unable to determine D. FALSE

B. TRUE

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

B. classes and objects.

BEGIN MAIN CREATE myArray[] = {9, -2, 30, -3, 98, 12}; CREATE max = array[0]; FOR (CREATE i = 1, i < 6, i++) IF(myArray[i] > max) max = myArray[i] END IF END FOR PRINT("The maximum value is " + max); END MAIN What is the correct code to change the second element in the array to 42? A. myArray = 42 B. myArray[1] = 42 C. myArray[2] = 42 D. 42 = myArray[1]

B. myArray[1] = 42

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

B. no return statements.

Modularizing code by using functions or methods: A. requires a return statement. B. reduces redundant code. C. eliminates encapsulation. D. increases maintenance time.

B. reduces redundant code.

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

B. value > 30 OR value == 30

T/F: A DEFAULT CASE is required as part of a SWITCH statement.

False

T/F: A String (or string) object is a primitive data type.

False

T/F: All method (function) headers must include parameters.

False

T/F: All methods must have a return statement.

False

T/F: An object is a primitive data type.

False

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

False

T/F: In an IF...ELSE IF...ELSE IF structure, each statement whose expressions evaluate to true will run their block of code

False

T/F: In programming && is considered an arithmetic operator.

False

T/F: Input is sending messages to the console/user.

False

T/F: Keywords can be used as variable identifiers/names.

False

T/F: Methods can access and modify other methods' local variables easily.

False

T/F: Methods can return only primitive data types.

False

T/F: Only WHILE loops can be nested.

False

T/F: Output is process of reading information from user, usually via keyboard or mouse.

False

T/F: Pseudocode form of writing should be used only when the logic of the program is complex.

False

T/F: Strings are a primitive data type which support the '+' operation.

False

T/F: The bottom of the runtime stack is the currently running method.

False

T/F: The main difference between a DO...WHILE and a WHILE loop is that a WHILE loop cannot result in an infinite loop.

False

T/F: 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

T/F: You can only nest FOR loops.

False

T/F: count-- is equivalent to count = count + 1.

False

The execution of one pass of a loop is referred to as a(n):

iteration.

When a variable is declared within a method and its scope is within the method it is known as a(n)

local variable.

Creating multiple methods with the same name but different parameters (number of parameters and/or data types) is called:

overloading.

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.

What are actual parameters?

the actual value that is passed into the method by a caller.

What are formal parameters?

the identifier used in a method to stand for the value that is passed into the method by a caller. i.e. In Bold: "public static int Sum(int num1, int num2)"

What is a method header?

•The header is the method declaration. "public static int Sum(int num1, int num2)"

What is a constructor?

•Used to give initial values to ALL attributes •Is activated when someone creates a new instance of the class

What is procedural abstraction?

•Written the code once, but called it many times

Rules for Methods

•You cannot define a method inside of another method •Methods always reside in a class in C# and Java(as you've seen numerous time already) •Methods cannot see each other's variables •You've seen "private static" in our examples... more on this later Methods must be BEFORE the MAIN in C++

Pseudocode is?

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

What is an object?

an instance of a class

Programming starts with?

developing an algorithm.

T/F: Is this valid syntax for a FOR loop? for(int j = 0; j < 1000; j++) PRINT(J);

True

T/F: Methods can be called from non-MAIN methods.

True

T/F: Once an array is created, it cannot be resized during program execution.

True

T/F: Software testing involves the execution of a software component or system component to evaluate one or more properties of interest.

True

T/F: Strings are immutable which means once a String object is created its contents cannot be changed.

True

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

True

T/F: The body of a method can be empty.

True

T/F: new is the reserved word used to create an object.

True

Which of the following programming terms is enforced by declaring class attributes as private?

Encapsulation

METHOD printStatement(parameters: CREATE x) IF ((x * 2) == 8) PRINT x ELSE IF (x == 5) PRINT "End program." ELSE IF (x > 0) PRINT "Boo!" ELSE PRINT x*x END IF END METHOD BEGIN MAIN CALL printStatement(5) END MAIN What is returned from the PrintStatement Method to the MAIN method? A. 25 B. 5 C. No value is returned. D. Boo! E. End program.

C. No value is returned.

This means that a copy of a parameter's value is sent into a method: A. Pass by reference. B. Parameter list C. Pass by value. D. Pass the gravy.

C. Pass by value.

Which of the following does not have any effect in method overloading? A. Method name B. Types of parameters C. Return type D. Number of parameters

C. Return type

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; } A. x == 2 B. x == 0 C. The loop won't terminate. It's an infinite loop. D. x == 98

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

Arrays are homogeneous, which means: A. The index starts at 1. B. They can contain multiple types of data at the same time. C. They can only contain one type of data. D. They are static in size.

C. They can only contain one type of data.

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. A. float B. double C. int D. String

C. int

METHOD doSomething(CREATE z) IF (z % 2 == 0) FOR (CREATE count = 4, count > 0, count--) IF (count == 3) CONTINUE; END IF z = z + (count * z); PRINT(z + ","); END FOR END IF ELSE FOR (CREATE count = 0, count < 4, count++) IF (count == 5) continue; END IF z = z + (count * z); PRINT(z + ","); END FOR END ELSE END METHOD BEGIN MAIN doSomething(5); END MAIN A. 10,30,60, B. 10,30,60,100, C. 5,10,30,120,600 D. 5,10,30,120,

D. 5,10,30,120,

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

D. All of the other choices

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

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

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

D. false in all cases.

METHOD atlantaSportsTeams(parameters: CREATE y) SWITCH (y) CASE 1: RETURN "Atlanta Braves" CASE 2: RETURN "Atlanta Dream" CASE 3: RETURN "Atlanta Falcons" CASE 4: RETURN "Atlanta Gladiators" CASE 5: RETURN "Atlanta Hawks" CASE 6: RETURN "Atlanta United" DEFAULT: RETURN "Invalid Selection" END SWITCH END METHOD BEGIN MAIN CREATE choice choice = atlantaSportsTeams(4) PRINTLINE ("Go " + choice + "!") END MAIN What is returned from the atlantaSportsTeams method to the MAIN? A. No value is returned. B. Atlanted United C. Atlanta Dream D. Atlanta Falcons E. Atlanta Gladiators F. Atlanta Braves

E. Atlanta Gladiators

IDE stands for?

Integrated Development Environment

Consider two variables x and y. If the values of x =5 and y=10 if (x < 0) { System.out.println(" Mr. Spock"); } else { if (x > y) { System.out.println( "Captain Kirk"); } else { System.out.println( "Star Trek it is!!!"); } } What is displayed as the result of the code being executed:

Star Trek it is!!!

What are some aspects of classes?

Name, Attributes(variables), Constructors(special functions/methods), and Functions(methods: Get and Set)

How to declare new object?

Object o = new Object;

What is overloading?

Overloading is to create multiple functions with the same name, but different types of parameters (type and/or number).

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

True

What is the runtime stack?

The runtime stack keeps track of active (currently running) methods in the program, and order of method calls. The top of the stack represents the currently running (active) method in the program. The bottom represents main method often program. When a method finished, it is removed from the stack.

T/F: 2D Arrays are still homogeneous.

True

T/F: 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

T/F: A flowchart is a type of diagram that represents an algorithm, workflow or process.

True

T/F: A relational operator used when comparing primitive data types is !=.

True

T/F: A switch statement is similar to an if statement in that both are used to alter the flow of a program.

True

T/F: An array index cannot be of the double, float or String data types.

True

T/F: An array must be sorted for a Binary search to work properly.

True

T/F: An if statement does not need to have an else clause.

True

T/F: Every program needs a MAIN function or method to run.

True

T/F: Formal parameters in method headers require including the data type for each parameter in source code.

True

T/F: 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


Set pelajaran terkait

Module 17 - Cisco Switches and Routers Quiz

View Set

EMT Basic Chapter 9 Patient Assessment Quiz

View Set

module 7- methods of calculation for individualized drug dosing

View Set

Unit 4 -- 12-14 ---- worksheet 14

View Set

Chapter 2 - Intro to Programming in C

View Set

Stereotypes, Prejudice, Discrimination

View Set