Compsci Lecture - Final Exam

0.0(0)
studied byStudied by 8 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/161

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

162 Terms

1
New cards

Program design consists of

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

2
New cards

Pseudocode is

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

3
New cards

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

True

4
New cards

T/F - Software training involves the execution of a software component or system component to evaluate one or more properties of interest

True

5
New cards

IDE stands for

integrated development environment

6
New cards

debugging is the process of

solving errors in the source code

7
New cards

T/F - input is sending messages to the console/user

false

8
New cards

T/F - output is the process of reading information from the user, usually via keyboard or mouse

false

9
New cards

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

10
New cards

programming starts with

developing an algorithm

11
New cards

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

12
New cards

What would be the best datatype to represent a product? A variable that stores information about the number of time currently in stock in a grocery store

int

13
New cards

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

800.0

14
New cards

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

-5, 18

15
New cards

T/F - a String/string object is a primitive data type

false

16
New cards

What is the value of j after this code is executed?

BEGIN MAIN
  int i = 6, int j=10;
  j+=i;
END MAIN

16

17
New cards

Consider the expression: value >= 30

Which of the following is equivalent to this expression?

value > 30 OR value == 30

18
New cards

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 being executed?

Star Trek it is!

19
New cards

T/F - Imagine a game of Yahtzee where a roll of dice always returns an even number. 

Consider this code where the number is a 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?

true

20
New cards

T/F - an if statement does not need to have an else clause

true

21
New cards

T/F - If the variable isTested is a Boolean, then the statement below if a valid control expression: IF(isTested)

true

22
New cards

T/F in programming && is considered an arithmetic operator

false

23
New cards

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

24
New cards

The Boolean expression ((A AND B) AND (NOT(A AND B)) evaluates to

false in all cases

25
New cards

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

the code won’t terminate; it’s an infinite loop

26
New cards

Consider this code: 

BEGIN MAIN
  int y=1;
  int x=1;
  PRINTLINE(x++);
END MAIN

What will this code print?

1

27
New cards

T/F - a relational ooperator used when comparing primitive data types is !=

true

28
New cards

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

true

29
New cards

T/F - pseudocode form of writing should be used only when the logic of the program is complex

false

30
New cards

T/F -  Is this valid syntax for a FOR loop?

BEGIN MAIN
  FOR(CREATE j = 0; j < 1000; j++) 
  PRINT(j) 
  END FOR
END MAIN

true

31
New cards

T/F - Consider the following code:

BEGIN MAIN
   CREATE list[] = {5, 10, 15, 20}
END MAIN

This would cause an error since there is no length/size included in the statement.

false

32
New cards

Select the correct declaration for a 2D array of 5 rows and 10 columns

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

33
New cards

Which of the following correctly refers to the last element in the array of integers called numbers?

numbers[length of numbers-1]

34
New cards

T/F - an array index cannot be double, float, or String data types

true

35
New cards

 Consider the following code:

BEGIN MAIN
  CREATE values[7] = {1,2,3,4,5,6,7}
  PRINTLINE (values[7])
END MAIN

What would happen when this code is executed?

it would print nothing as there is no index 7

36
New cards

T/F - you can only nest FOR loops

false

37
New cards

Consider the following code:

BEGIN MAIN
  CREATE arrayOne[5]
END MAIN

It stores 5 elements with legal indices from 0 to 4

38
New cards

T/F - 2D arrays are declared in row, column order, meaning first value is number of rows, second value is number of columns

true

39
New cards

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

true

40
New cards

T/F - 2D arrays are still homogeneous

true

41
New cards

T/F - in general, the advantage of using a binary search over a linear search increases when searching larger sorted arrays

true

42
New cards

which of these sorts was not covered in the lecture slides?

merge

43
New cards

T/F - an array must be sorted for a Binary search to work properly

true

44
New cards

FOREACH loops cannot be used for which of the following tasks?

assignment

45
New cards

programming starts with

algorithm development

46
New cards

an algorithm is a

set of instructions

47
New cards

abstraction is the

level of detail

48
New cards

a good algorithm exhibits

precision, clarity, completeness, correctness, and simplicity

49
New cards

an algorithm can be described as

using a natural language, pictures and diagrams, and pseudocode or a specific programming language

50
New cards

all languages can

print to the screen

have variables and the ability to assign values to them

an entry point (a BEGIN and END) - a skeleton

can read text/numbers from the user

have basic operators

51
New cards

an application always contains a ____ method so that the program can be executed

MAIN

52
New cards

in object-oriented programming (OOP) language, MAIN is inside a _____

class

53
New cards

variable declaration indicates its ____ and possibly its _______ _____

type; initial value

54
New cards

a value is assigned using the assignment ________

operator

55
New cards

a constant value does not ______

change

56
New cards

data type tells

how much memory to allocate

the format in which to store data

the types of operations you will perform on data

57
New cards

primitive data types include

four integer types

two floating point types

character (char)

boolean

58
New cards

an expression is a combination of one or more _________ and ________

operators; operands

59
New cards

expressions evaluation follows ________ __________ ____

operator precedence rule (order of operations)

60
New cards

type conversion can be either ________ or _________ conversion

widening (promotion); narrowing (demotion)

61
New cards

arrays hold values of the ____ ____

same type

62
New cards

arrays are ______ in size

static

63
New cards

T/F - you can create an array of any type

true

64
New cards

you use a ____ to initialize or search arrays

loop

65
New cards

any time you have to visit an element in an array, you use ______ _____

nested loops

66
New cards

T/F - 2D arrays are like 1D arrays in nature

true

67
New cards

2D arrays use ______ _____ to traverse the array

nested loops

68
New cards

how many dimensions do array lists have?

1

69
New cards

array lists are _______ - they can grow and shrink

dynamic

70
New cards

searching an array list can be done either in ______ or ______ fashion

linear; binary

71
New cards

the linear search approach for array lists is slow and takes to the order of O(_)

O(n)

72
New cards

the binary search approach for array lists is much faster and takes to the order of O(_)

O(log(n))

73
New cards

T/F - bubble, selection, and insertion sort algorithms are relatively slow compared to other advanced sort methods

true

74
New cards

bubble, selection, and insertion sort algorithms perform to the order of O(_)

O(n²)

75
New cards

algorithm

a set of logical steps to accomplish a specific task; a set of instructions

76
New cards

abstraction

refers to the logical grouping of concept of objects; the level of detail

77
New cards

pseudocode

a mixture of languages not concerned with syntax, but concepts

78
New cards

skeletons

the smallest program you can write; define the entry/starting point of the program

79
New cards

variable

a name for a location in memory used to hold a data value

80
New cards

byte, int, short, long

float, double

char

boolean

what are the 8 primitive data types

81
New cards

expression

a combination of one or more operators and operands

82
New cards

true

T/F - while and do-while loops run an undetermined number of iterations

83
New cards

true

T/F - the for loop runs a predetermined number of iterations

84
New cards

counting loop

another name for a for loop

85
New cards

sentinel values

how the user controls a loop

86
New cards

sorting

the process of rearranging elements to be in a specific order

87
New cards

runtime stack

keeps track of active (currently running) methods in the program, and order of method calls

88
New cards

overloading

creating multiple functions with the same name but different parameters

89
New cards

object oriented programming

based on the concept of classes, from which objects are created

90
New cards

class

represents the concept of things in the real world; made of variables and methods

91
New cards

object

an entity in the real world that can be distinctly identified with a unique identity, state, and behavior

92
New cards
93
New cards

T/F - The following is an example of a valid program in Pseudocode

MAIN

false

94
New cards

T/F - Variables can be declared and initialized in one line of code

true

95
New cards

What type of error is present in the underlined C# code sample below?

public static void Main(string[] args)
{
  Console.WriteLine("Enter a number");
  int num = Convert.ToInt32(Console.ReadLine());
  int squared = num + num;
  Console.WriteLine(num + " squared is " + squared);
}

logic error

96
New cards

What type of error is present in the underlined C++ code sample below?

using namespace std;
int main()
{
    dble value = 12;
    cout << value << endl;
}

syntax error

97
New cards

Evaluate ((18 % 5) * 3) - (6 - 4) + 1
Assume all values are integers.

8

98
New cards

Evaluate as an integer: 5 + 3 / 2 * 4 – 2 % 1

9

99
New cards

Evaluate 10 - (40 + (20 / (10 - 5) * 2) / 4) + 50
Assume all values are integers.

18

100
New cards

T/F - In the equation 2 + 8 /4 * 2, the addition operation + is evaluated first.

false