CSE 1321 Midterm
Comparison/Relational Operators are:
"==" equals to "!=" not equals to ">" greater than "<" less than ">=" greater than or equal to "<=" less than or equal to
logical operators are:
(AND(&&) OR(||) NOT(!))
a string is actually:
- Strings are immutable which means once a String object is created its contents cannot be changed. (cant change in memory) - complex: can be broken down into characters
a variable is
- a chunk of the computers memory - can hold a value - int, float, char, string
what is an algorithm?
- a set of logical steps to accomplish a specific task - a set of directions/instructions -data and instructipns that work on data
List the eight simple or primitive data types and their range of values: 1) 2) 3) 4) 5) 6) 7) 8)
1) byte, 2) short, 3) int, 4) long, 5) float, (7 signifigant digits) 6) double, (14 signifigant digits) 7) boolean, (2 values, true and false) 8) char
skeleton program for 1) C# 2) C++ 3) Java
1) using System; class Program { public static void Main (string[] args) { } } 2) #include <iostream> int main() { return 0; } 3) class Main { public static void main(String[] args) { } }
print "hello world" in 1- C# 2- Java 3- C++
1- Console.WriteLine("hello world"); 2- System.out.println("hello world"); 2- cout << "hello world" << endl;
5 components of algorithms
1- data structures 2- instructions 3- conditional expressions 4- control structures 5- modules
What is the shortcut operator to add one (1) to a variable? A) ++ B) + + C) ** D) @@
A) ++
Mathematical Operators are:
Addition: + subtraction: - Multiplication: * Divison: / Modulus (remainder): %
Program design consists of: A) the ability to solve problems. B) steps a programmer should do before they start coding a program in a specific language. C) writing the code for a program. D) writing the documentation for a program.
B) steps a programmer should do before they start coding a program in a specific language.
Pseudocode is A) a formal programming language. B) a machine. C) an informal high-level description of the operating principle of a computer program or algorithm.
C) an informal high-level description of the operating principle of a computer program or algorithm.
What is the Basic Program Structure for any language?
Class Name Main Method Input/Read Statement, Output/Write Statement Assignment Statement
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?
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 abstraction?
It is reducing information and detail to focus on essential characteristics. (logical grouping of concepts pr objects)
What is the order of operations:
P - parenthesis E - exponents (2^2) M - multiplication D - division A - addition S - subtraction
Consider the expression: value >= 30 Which of the following is equivalent to this expression? a) value > 30 OR value == 30 b) NOT(value < 29) c) NOT(value > 31) d) value > 30 AND value == 30
a) value > 30 OR value == 30
{ public static void main (String[] args) { int 2 = 10; for (int count = 10; count > 5; count--) { if (count % 2 == 0) { z += count; } System.out. print(z + ","); } System.out.printin( ); } } What is the exact output of this code? a) 20, 24, 28, 30, 34 b) 20, 20, 28, 28, 34, c) 10,9, 8, 7, 6,
b) 20, 20, 28, 28, 34,
IDE stands for a) Initial Degree Expectations b) Integrated Development Environment c) Intramural Department Executive
b) Integrated Development Environment
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) false in all cases. c) true whenever only A is true or only B is true. d) true in all cases.
b) 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. a) double b) int c) float d) String
b) int (number of items in the store is going to be a whole number)
Consider this code: BEGIN MAIN int y=1; int x=1; PRINTLINE(x++); END MAIN What will this code print? a) 2 b) 0 c) 1 d) unknown
c) 1
Which statement below will be true after the following code terminates? BEGIN MAIN CREATE x = 0 WHILE (x < 100) { x *= 2; } END WHILE END MAIN a) x == 98 b) x == 2 c) The loop won't terminate. It's an infinite loop. d) x == 0
c) The loop won't terminate. It's an infinite loop. (0 * 2 will always be 0 so infinite loop)
Programming starts with: a) looking online for the answers. b) writing code until it works. c) developing an algorithm.
c) developing an algorithm.
What is the output of the following code? BEGIN MAIN int u = 3; int v = 5; u += v; v += u; u -= v; v -= u; PRINT (u + ", " + v); END MAIN a) 5, 3 b) -5,-3 c) 3, 5 d) -5, 18
d) -5, 18
What is the value of j after this code is executed? BEGIN MAIN int i = 6, int j=10; j+=i; END MAIN a) 10 b) 6 c) 4 d) 16
d) 16
What is the output of the following code? BEGIN MAIN int num1 = 500; int num2 = 200; int num3 = 300; double average = num1 + num2 + num3 / 3; PRINTLINE(average); END MAIN a) 333.33333333333 b) 333.0 c) Error message d) 800.0
d) 800.0
Consider two variables x and y. If the values of x =5 and y=10 BEGIN MAIN IF(x < 0) { PRINT "Mr.Spock" } ELSE { IF (x > y) { PRINT "Captain Kirk" } ELSE { PRINT "Star Trek it is!" } } END MAIN What is displayed as the result of the code is being executed? a) Nothing will be printed/displayed b) Captain Kirk c) Star Trek it is! d) Mr. Spock
d) Mr. Spock
Imagine a game of Yahtzee where a roll of dice always returns an even number. Consider this code where the number is variable that stores the value of the dice. BEGIN MAIN CREATE result = number % 2; IF (result == 0) PRINT "TRUE" ELSE PRINT "FALSE" END MAIN What will the code display? a) FALSE b) Unable to determine c) Neither condition is satisfied d) TRUE
d) TRUE
Debugging is the process of a) compiling the source code. b) publishing the source code to the client. c) writing source code. d) solving errors in the source code.
d) solving errors in the source code.
What is white space?
empty area and ignored in program but enhances readability
A String (or string) object is a primitive data type. true or 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 or false
false
In programming && is considered an arithmetic operator. true or false
false
Input is sending messages to the console/user. true or false
false
Output is process of reading information from user, usually via keyboard or mouse. true or false
false
Pseudocode form of writing should be used only when the logic of the program is complex. true or false
false
Strings are a primitive data type. true or false
false
A flowchart is a type of diagram that represents an algorithm, workflow or process. true or false
true
A relational operator used when comparing primitive data types is !=. true or false
true
A switch statement is similar to an if statement in that both are used to alter the flow of a program. true or false
true
An if statement does not need to have an else clause. true or 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 or false
true
If the variable isTested is a Boolean, then the statement below is a valid control expression: IF(isTested) true or false
true
Is this valid syntax for a FOR loop? BEGIN MAIN FOR(CREATE j = 0; j < 1000; j++) PRINT(j) END FOR END MAIN True or False
true
Logical operators are evaluated before relational operators. true or false
true
Software testing involves the execution of a software component or system component to evaluate one or more properties of interest. True or 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 or false
true
When assigning a value to a variable, the variable must be on the left of the assignment operator (=). true or false
true
count++ is equivalent to count = count + 1. true or false
true
3 types of loops:
while do... while for