Comp Sci 2.2 Programming Fundamentals

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

1/82

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No study sessions yet.

83 Terms

1
New cards

In programming, which construct involves executing instructions one after the other in the order they are written?

Sequence

2
New cards

Which programming construct uses $if$ statements or $switch/case$ to choose a path based on a condition?

Selection

3
New cards

The process of repeating a block of code using loops is known as _.

Iteration

4
New cards

What is the specific name for a loop that repeats a set number of times, such as a $for$ loop?

Count-controlled iteration

5
New cards

What type of iteration repeats until a specific condition is met, such as a $while$ or $do\ until$ loop?

Condition-controlled iteration

6
New cards

Arithmetic Operator: What is the purpose of the $+$ operator?

Addition

7
New cards

Arithmetic Operator: What is the purpose of the $/$ operator?

Division

8
New cards

Arithmetic Operator: What is the purpose of the $MOD$ (Modulo) operator?

It returns the remainder after a division.

9
New cards

Arithmetic Operator: What is the purpose of the $DIV$ operator?

It returns the quotient (the whole number of times a number goes into another).

10
New cards

Evaluate the expression: $7\ DIV\ 2$.

$3$

11
New cards

Evaluate the expression: $7\ MOD\ 2$.

$1$

12
New cards

Arithmetic Operator: What does the symbol $\text{^}$ represent in OCR Exam Reference Language?

Exponentiation (to the power of).

13
New cards

Comparison Operator: What does the symbol $==$ represent?

Equal to

14
New cards

Comparison Operator: What does the symbol $!=$ represent?

Not equal to

15
New cards

Comparison Operator: What does the symbol $<=$ represent?

Less than or equal to

16
New cards

Comparison Operator: What does the symbol $>=$ represent?

Greater than or equal to

17
New cards

Boolean Operator: Which operator returns $True$ only if both conditions being compared are true?

AND

18
New cards

Boolean Operator: Which operator returns $True$ if at least one of the conditions being compared is true?

OR

19
New cards

Boolean Operator: Which operator reverses the logical state of its operand?

NOT

20
New cards

Data Type: What is the most appropriate data type for a whole number like $7$ or $-12$?

Integer

21
New cards

Data Type: What is the most appropriate data type for numbers with a decimal point like $3.14$?

Real (or Float)

22
New cards

Data Type: What is the most appropriate data type for a variable that can only be $True$ or $False$?

Boolean

23
New cards

Data Type: What is the most appropriate data type for a single letter, number, or symbol?

Character

24
New cards

Data Type: What is the name for a collection of characters stored as a single unit?

String

25
New cards

In programming, the process of converting one data type to another is called _.

Casting

26
New cards

What would be the result of the casting operation $int("5")$?

The string "5" is converted into the integer $5$.

27
New cards

String Manipulation: What does the $.length$ function return?

The number of characters in a string.

28
New cards

String Manipulation: What is the purpose of the $.substring(start, length)$ method?

It extracts a specific part of a string based on a starting position and a defined length.

29
New cards

String Manipulation: Which methods are used to change the case of a string to all capitals or all small letters?

$.upper$ and $.lower$

30
New cards

String Manipulation: What does the term 'concatenation' mean?

Joining two or more strings together to form a new string.

31
New cards

File Handling: What is the first step required to link a program to an external file?

Using the $open()$ command.

32
New cards

File Handling: Which command is used to retrieve a single line of data from an opened file?

$.readLine()$

33
New cards

File Handling: Why is it essential to use the $.close()$ command after finishing with a file?

To disconnect the file and prevent data loss.

34
New cards

File Handling: Which command is used to save a new line of data into an external file?

$.writeLine()$

35
New cards

Data Structures: What is a 1D array?

A list of items that are all of the same data type.

36
New cards

Data Structures: How is data typically structured and accessed in a 2D array?

As a table or grid using two indices, typically $[row, column]$.

37
New cards

How would you access the item in the second row and first column of a 2D array named $board$ (using 0-indexing)?

$board[1, 0]$

38
New cards

SQL: Which keyword is used to specify which fields (columns) should be displayed in a database search?

SELECT

39
New cards

SQL: Which keyword is used to specify the table where the database search should look?

FROM

40
New cards

SQL: Which keyword is used to provide criteria to filter a database search?

WHERE

41
New cards

What is the primary difference between a procedure and a function?

A function returns a value to the main program, whereas a procedure performs a task without returning a value.

42
New cards

Variables that are declared inside a sub-program and only exist within that sub-program are called _.

Local variables

43
New cards

What is a 'global variable'?

A variable that can be accessed and updated from anywhere within the program.

44
New cards

Why is the use of local variables considered memory efficient?

They only exist and take up memory while the sub-program is running.

45
New cards

Programming Techniques: What is the purpose of using constants instead of variables?

To store values that do not change during the execution of a program (e.g., $PI$).

46
New cards

How do you define a constant in OCR Exam Reference Language?

Using the $const$ keyword (e.g., $const\ vat = 0.2$).

47
New cards

Which command in OCR Exam Reference Language would you use to generate a whole number between $1$ and $6$?

$random(1, 6)$

48
New cards

In OCR Exam Reference Language, how is a comment denoted?

Using double forward slashes ($//$).

49
New cards

What is the purpose of the $global$ keyword in code?

To declare that a variable is accessible throughout the entire program.

50
New cards

In a $for$ loop, what keyword is used to determine the increment value if it is not $1$?

$step$ (e.g., $for\ i = 2\ to\ 10\ step\ 2$).

51
New cards

What is the difference between a $while$ loop and a $do\ until$ loop regarding when the condition is checked?

A $while$ loop checks the condition before the code runs; a $do\ until$ loop runs the code at least once before checking.

52
New cards

How do you mark the end of an $if$ statement in OCR Exam Reference Language?

$endif$

53
New cards

In a $switch$ statement, what keyword identifies the code to run if none of the specific $case$ conditions are met?

$default:$

54
New cards

String Handling: If $subject = "ComputerScience"$, what is the result of $subject.substring(3, 5)$?

"puter" (starting at index 3, taking 5 characters).

55
New cards

String Handling: What does $subject.left(4)$ return if $subject = "ComputerScience"$?

"Comp"

56
New cards

String Handling: What does $subject.right(3)$ return if $subject = "ComputerScience"$?

"nce"

57
New cards

What is the 0-indexed result of $ASC('A')$?

It returns the numerical ASCII value for the character 'A' (which is $65$).

58
New cards

What does the function $CHR(97)$ return?

The character 'a' (the character associated with the ASCII value 97).

59
New cards

How do you check for the end of a file in a loop using OCR Reference Language?

By using the $.endOfFile()$ function (e.g., $while\ NOT\ myFile.endOfFile()$).

60
New cards

How do you create a new empty text file named "test.txt" in code?

$newFile("test.txt")$

61
New cards

Arrays: How would you declare a 1D array named $colours$ with $5$ elements?

$array\ colours[5]$

62
New cards

Arrays: How would you declare a 2D array named $gameboard$ with $8$ rows and $8$ columns?

$array\ gameboard[8, 8]$

63
New cards

SQL: Write a simple SQL query to find all data from a table named $Cars$ where the $Colour$ is 'Red'.

$SELECT\ *\ FROM\ Cars\ WHERE\ Colour = 'Red'$

64
New cards

How do you define the start and end of a function in OCR Exam Reference Language?

$function\ name()$ and $endfunction$

65
New cards

How do you define the start and end of a procedure in OCR Exam Reference Language?

$procedure\ name()$ and $endprocedure$

66
New cards

When calling a function named $calculate(x)$, how should you handle the value it provides?

Store it in a variable (e.g., $result = calculate(x)$) or use it directly in a statement (e.g., $print(calculate(x))$).

67
New cards

What is the result of $bool("True")$ in casting?

The Boolean value $True$.

68
New cards

What is the result of $float("4.52")$ in casting?

The Real/Float number $4.52$.

69
New cards

In a $for$ loop, what keyword signifies the final value of the counter?

$to$ (e.g., $for\ i = 0\ to\ 9$).

70
New cards

Evaluate the comparison: $5\ !=\ 5$.

$False$

71
New cards

Evaluate the comparison: $10\ >=\ 10$.

$True$

72
New cards

What is the output of $print("Hello" + "World")$?

"HelloWorld"

73
New cards

Data Types: What data type would be best to store the number of students in a class?

Integer

74
New cards

Data Types: What data type would be best to store the price of an item?

Real (Float)

75
New cards

Data Types: What data type would be best to store whether a user has a discount card?

Boolean

76
New cards

Data Types: What data type would be best to store a postcode like "SW1A 1AA"?

String

77
New cards

In code, $x = input("Prompt")$. What data type is the input usually received as by default?

String

78
New cards

How do you obtain a random real number between $-1.0$ and $10.0$?

$random(-1.0, 10.0)$

79
New cards

In a $switch$ statement, what follows the keyword $case$?

A specific value to compare against the switch variable and a colon ($:$).

80
New cards

Why is indentation used in programming constructs like $if$ and $while$?

To clearly show the structure and which block of code belongs to the construct.

81
New cards

Evaluate the logic: $(5 > 3)\ AND\ (2 > 4)$.

$False$ (because the second part is false).

82
New cards

Evaluate the logic: $(5 > 3)\ OR\ (2 > 4)$.

$True$ (because the first part is true).

83
New cards

What is the result of $NOT(True)$?

$False$