2.2 Programming Techniques COMPLETE Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Identifier

A

Describe the data being stored

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Short Identifier

A

Easier to spell correctly each time they are used

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Long Identifier

A

Can be used if they are more descriptive e.g. firstName

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

True or False: Identifiers can be the same as reserved words

A

False, identifiers cannot be the same as reserved words such as print or while

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Can variables change whilst a program is running?

A

Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Can constants change whilst a program is running?

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How are values assigned to variables?

A

Values are assigned in assignment statements using the = symbol e.g. firstName = “David”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How are values assigned to constants?

A

Constants are assigned as cost Pi = 3.142 for example. They can then be used in calculations

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Can identifiers for variables and constants change throughout a program?

A

No - they must be consistent throughout the program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is used in camel case?

A

Upper and lower case characters (FirstName or PricePerKilo). The first word can be lower case

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is used in snake case?

A

Underscores are used to link words (first_name or price_per_kilo)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is an assignment?

A

The association of a piece of data with a variable or constant, e.g. index = 0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Can an assignment be done as an input?

A

Yes (e.g. name = input(“Please enter your name”).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

When can a variable be output?

A

At any time throughout the program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the function of the operator +?

A

Addition

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the function of the operator -?

A

Subtraction

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is the function of the operator *?

A

Multiplication

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is the function of the operator /?

A

Division

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is the function of the operator MOD?

A

Modulus division. Returns the remainder after the division of one number by another (26 MOD 4 = 2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is the function of the operator DIV?

A

Quotient division. Returns the quotient or the lowest integer (26 DIV 4 = 6)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is the function of the operator ^?

A

Exponential powers of (3^3 = 27)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

MDIBAS - This is an anagram for the order of operations in a calculation. What is the correct order and what does each letter stand for?

A

B - Brackets I - Indices D - Division M - Multiplication A - Addition S - Subtraction

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is the function of the comparison operator ==?

A

Equal to - checks if two values are equal. Two equal signs are used to distinguish it from assigning a value to a variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What is the function of the comparison operator !=?

A

Not equal to - checks if two values are not equal to each other

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

What is the function of the comparison operator

A

Less than - checks if one value is less than another

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

What is the function of the comparison operator <=?

A

Less than or equal to - checks if one value is less than or equal to another

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

What is the function of the comparison operator >?

A

Greater than - checks if one value is greater than another

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

What is the function of the comparison operator >=?

A

Greater than or equal to - checks if one value is greater than or equal to another

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

True or False: Comparison operators can only be used to compare numbers

A

False, these operators can be used with strings as well as numbers. The strings are compared alphabetically

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

Boolean Operator: AND

A

Ensures that the overall statement is true only of *all* the individual statements are true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

Boolean Operator: OR

A

Ensures that the overall statement is true if *any* of the individual statements are true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

Boolean Operator: NOT

A

Used to reverse the logical state of the other operators

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

In programming, what does sequence do?

A

Ensures that the commands are executed in the correct order

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

In programming, what does selection do?

A

Chooses between two or more options. Involves the use of combinations of if, else and elseif statements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

When can if/else be used in programming?

A

if/else statements can be used if there are only two possible outcomes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

Why are elseif statements more efficient in programming?

A

As soon as the correct condition is found, none of the rest of the options are checked

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

Why are else statements used in programming?

A

To state what should happen if none of the options in the if or elseif statements are true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

What are nested if statements?

A

If statements that are completely within another if statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

Every if statement always needs its own _____ statement

A

endif

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q

_________ is the process of repeating a set of instructions for a fixed number of times or until there is a desired outcome. It is executed by program constructs called loops

A

Iteration

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
41
Q

What is count controlled iteration?

A

Iteration used when the number of iterations is known before the loop is started

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
42
Q

What is a condition controlled iteration?

A

Iteration used when the number of times a loop is executed is determined by a condition

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
43
Q

Are while loops an example of count controlled iteration, condition controlled iteration or can they be either?

A

While loops can be count controlled or condition controlled

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
44
Q

Are for loops an example of count controlled iteration or condition controlled iteration?

A

Count controlled

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
45
Q

Are do…until loops an example of count controlled iteration or condition controlled iteration?

A

Condition controlled

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
46
Q

What do for loops do?

A

Instruct the loop to be executed for a set number of times

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
47
Q

What do condition controlled while loops do?

A

Continue while a condition remains true and stops when it becomes false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
48
Q

What makes a count controlled while loop less efficient than a for loop?

A

More lines of code are needed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
49
Q

What do do… until loops do?

A

Continue until a condition becomes true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
50
Q

In a while loop the variable to be tested must be ________ ___ _____ _ _____ before the loop is started

A

Declared and given a value (initialised)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
51
Q

What must happen each time a while loop is ran?

A

Must be incremented or decremented

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
52
Q

What is the difference between a while loop and a do… until loop?

A

In a while loop the condition is tested at the start of the loop whereas in a do… until loop it is tested at the end and will therefore be run at least once

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
53
Q

What does concatenated mean?

A

Combined

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
54
Q

Why must computers be aware of data types of values stored in variables?

A

So that data is interpreted and manipulated correctly

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
55
Q

What is an integer?

A

A number without a fraction or decimal. Integers can be positive or negative

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
56
Q

Give an example of an integer

A

Any whole number eg 0, 3, 100, 10369

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
57
Q

What is a real number?

A

All numbers that exist and their fractions and decimals

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
58
Q

Are integers real numbers?

A

Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
59
Q

Why is it more efficient to declare integers as integers?

A

So that less memory is needed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
60
Q

What are real numbers declared as in pseudocode/python?

A

‘float’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
61
Q

Give an example of a real number

A

Any number, including decimals, such as 2, 3.9, 6.632, 9.37352

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
62
Q

What is a character?

A

A single letter, number or symbol

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
63
Q

Give an example of a character

A

Any letter, number or symbol eg C, 3, !

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
64
Q

What can a string hold?

A

A list of characters of any length

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
65
Q

What are strings enclosed in?

A

Single or double quotation marks

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
66
Q

Give an example of a string

A

Anything enclosed in single or double quotation marks eg “Hello user3 your password is ?1pass69word”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
67
Q

Data used by a computer are presented in strings of…

A

1s and 0s

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
68
Q

What happens if a computer is not told the data type?

A

It will not be able to use it correctly eg it may try to multiply text and display numbers as images

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
69
Q

Data types must be declared in all/some programming languages

A

Some

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
70
Q

What would int age declare?

A

That the variable “age” is to store integer numbers

71
Q

What happens in languages that the data type does not have to be stated?

A

The type is inferred from the type of data first stored (eg age = 13 would imply that the variable age stores integers)

72
Q

What is casting?

A

The conversion of one data type into another

73
Q

What would str(integerVariable) do?

A

Convert an integer into a string

74
Q

Casting must be done in all/some programming languages when concatenating variables and text in a print statement

A

Some

75
Q

What would int(stringVariable) or float(stringVariable) do?

A

Convert a string into an integer or a real number

76
Q

What is a string?

A

A string is a sequence of characters than contain letters, numbers and symbols

77
Q

What does a string literal consist of?

A

Characters enclosed in quotation marks such as “A13!”

78
Q

What is a string variable?

A

A string that can be declared, such as password = “A13!”

79
Q

Is print(“A13!”) a literal string or a variable string?

A

A literal string

80
Q

Is print(password) a literal string or a variable string?

A

A variable string

81
Q

password = “A13!” Do print(“A13!”) and print(password) produce the same output?

A

Yes

82
Q

password = “A13!” Why do print(“A13!”) and print(password) produce the same output?

A

Because the variable “password” is a string variable and it has a value of “A13!”

83
Q

What does concatenation mean?

A

Joining

84
Q

Strings can/cannot be concatenated

A

Can

85
Q

Strings can be concatenated end to end to form larger strings using the _ symbol

A

+

86
Q

The position of a character in a string is given by its…

A

Index number

87
Q

What is the first index in a string?

A

0

88
Q

“STRING” What is the index number of the letter N in this string?

A

4

89
Q

What is string traversal?

A

The process of moving through a string one character at a time.

90
Q

What can string traversal be used to do?

A

See if a string contains a particular character or group of characters

91
Q

The ______ of a string must be found in order to create a loop to examine each character

A

Length

92
Q

True/False: A loop can be set up to move through a string

A

True

93
Q

Why must a loop be set up to run from 0 to the length of the string minus one?

A

Because strings use index numbers. eg The string “Rosie and Jack” has a length of 14, so the indices are 0 to 13. If there was no -1 there would be an error message as there is not an index 14

94
Q

What can be snipped out of a string?

A

Substrings or portions

95
Q

myString = “RosieandJack” snip = myString.substring(2, 4) print(snip) What does the numbers 2 and 4 do in this string? What will this print?

A

The first number is the starting point and the second number is the number of characters. This would print the word “siea” as the substring starts at index 2 (the letter “s”) and has a length of 4 characters

96
Q

What is the difference between an array and a variable?

A

Variables store one item of data that can change whereas arrays can store multiple items of data, not just one

97
Q

What is an array?

A

A data structure that can store multiple items of data, called elements

98
Q

What are items of data in an array called?

A

Elements

99
Q

Elements are all of the same ____ ____ under the same _________

A

data type and identifier

100
Q

How is an array created?

A

By specifying the elements stored in the array (declaring)

101
Q

What does declaring an array mean?

A

Specifying the elements stored in an array.

102
Q

array names = [“Alice”, “Catherine”, “David”] array scores = [10, 13, 17] What is this array doing?

A

Storing 3 people’s names and their scores

103
Q

What are elements in an array enclosed within?

A

Square brackets

104
Q

What are elements in an array separated with?

A

Commas

105
Q

What is an element? (Computer Science)

A

An item of data at a particular index

106
Q

If the elements in an array are at index positions 0 to 4, what is the length of the array?

A

5

107
Q

What is a two-dimensional array?

A

In a 2D array there is a second array at each index position of a one-dimensional array

108
Q

What do two-dimensional arrays form?

A

A matrix

109
Q

In a two-dimensional array, each element has ___ indices to indicate its position

A

Two

110
Q

What would an array with the structure as shown be declared as?

A

array arrayName [5, 4]

111
Q

Why would an array with the structure as shown be declared as array arrayName [5, 4]?

A

There are 5 indexes in the original array, and now 4 items of data in each position. For each of the elements 0 to 4, there are four items of data, 0 to 3.

112
Q

How is data assigned to an element in an array?

A

Index position

113
Q

True/False: Programming languages allow users to store data in files on storage decvices so that they are not lost when a program is closed

A

True

114
Q

Before a file can be accessed or opened, it must be given a…

A

File handle

115
Q

What is a file handle?

A

A reference assigned to a file so that the program can access it.

eg myFile = openWrite(“Sample.txt”)

116
Q

True/False: When a file is opened in write mode, a new file will be created with that tilename if it does not already exist

A

True

117
Q

If you save a file and a file with that name already exists, what happens to the existing file?

A

It will be overwritten and the existing data will be lost

118
Q

What does OpenAppend(“filename.txt”) do?

A

Prevent data being lost due to it being overwritten

119
Q

Once a file has been read from or written to, it must be…

A

Closed (eg myFile.close())

120
Q

True/False: A user can’t open a file and write data directly to it from the keyboard

A

False - they can

121
Q

True/False: A program can be coded to save data stored in variables to a text file

A

True

122
Q

What does myFile. openRead(“filename.txt”) do?

A

Opens a file to read data

123
Q

True/False: Data stored in a text file can be loaded into the variables of a program

A

True

124
Q

What does the endOfFile() function do?

A

If the number to read in is not known, the endOfFile() function can be used

125
Q

What is a record? (Computer Science)

A

A collection of data objects relating to a particular subject or entity

126
Q

True/False: The data items stored in each record must be of the same data type

A

False, they can be of different data types eg integers and strings

127
Q

What does DBMS stand for?

A

Database management system

128
Q

Large volumes of data are usually stored in d________

A

databases

129
Q

How are databases created?

A

Using a DBMS (database management system)

130
Q

How is data stored in a database?

A

Tables

131
Q

What do column headings in a table in a database define?

A

Fields

132
Q

Each record in a database must have a ___ _____ that is an item of data that is unique to that record

A

key field

133
Q

Each Each column in a table in a database is a _____

A

Field

134
Q

What is stored in each record of a database?

A

An item of data

135
Q

Some programming languages allow users to create a data structure similar to that in databases where the items of data can be different/are the same data types

A

can be different

136
Q

What are records sometimes referred to as?

A

Structs

137
Q

When structs are set up, the data type for each element is usually stipulated as the elements, unlike those stored in arrays, can be different/are the same data types

A

Can be different

138
Q

What does SQL stand for?

A

Structured Query Language

139
Q

What is SQL used for?

A

Creating, maintaining and accessing databases

140
Q

What does SQL allow users to do?

A

Search for records that contain a particular item or items of data.

141
Q

What keyword is used for searching with SQL?

A

WHERE

142
Q

What keyword is used to display records with SQL?

A

SELECT

143
Q

Are commands in SQL case-sensitive?

A

No - eg both select and SELECT will work

144
Q

What is the wildcard symbol % used for in SQL?

A

Used as a substitute for one or many characters

145
Q

What is the wildcard symbol * used for in SQL?

A

To represent ‘all fields’, for example WHERE TUTORgROUP like “%x”; would return all records with a tutor group ending with an X

146
Q

SELECT FirstName, Surname FROM Students;

What is important about the syntax of this command?

A

There is a semi-colon at the end of the command

147
Q

Why are commands written on a seperate linewhen searching with SQL?

A

To make them easier to understand

148
Q

What is a sub-program?

A

A self-contained sequence of program instructions that performs a specific task

149
Q

What does using sub-programs allow?

A

The production of more efficient code

150
Q

When are sub-programs called?

A

Whenever it is needed to carry out that function

151
Q

What is another name for sub-programs?

A

Subroutines

152
Q

True/False: Sub-programs allow the production of structured code

A

True

153
Q

True/False: Sub-programs make programs longer

A

False - the code only needs to be written once and can be called as many times as needed

154
Q

True/False: Sub-programs make program code easier to read and test

A

True

155
Q

True/False: Sub-programs make the development time of a program longer

A

False, they shorten the development time of a program

156
Q

Do sub-programs make testing easier or harder?

A

Easier

157
Q

Sub-programs make code more/less readable

A

More

158
Q

What is a function?

A

A sub-program that returns a value to the main program when it is called

159
Q

What is a procedure?

A

A sub-program that carries out a specific task but does not return values to the main program

160
Q

Values passed to the function from the main program are stored in the sub-program’s…

A

parameters

161
Q

True/False: Sub-programs need to be defined

A

True

162
Q

To create a sub-program, do you need to define it with its type and indicate where it ends?

A

Yes

163
Q

What does “return velocity” do in a function?

A

The value of velocity is returned to the main program

164
Q

What are variables used only within a sub-program and not in a main program called?

A

Local variables

165
Q

What needs to be stated that stores the values that a function will use?

A

Parameters

166
Q

True/False: Values of parameters are not passed to them by the main program when the function is called

A

False, they are

167
Q

True/False: Sub-programs cannot be called from within the main program

A

False, they can

168
Q

If the value of the local variable “velocity” is the result of a calculation performed in a function, what is it passed back to?

A

The specified global variable in the main program

169
Q

averageVelocity = vspeed(distanceTravelled, tiemTaken)

What does this line of code do?

A

Calls the function and passes the values of two gloval variable sto it as arguments in the correct order. In the sub-program these values are passed into the corresponding parameters

170
Q

Why is it best that you don’t use the same names for local and global variables?

A

You could get into a muddle with the logic and mix them up

171
Q

What are global variables?

A

Variables that exist within the main program and can be referenced in other lines of code

172
Q

What do procedures do?

A

They do not return a value to the main program. They could print out a message for the user, for example

173
Q

Parameters in a procedure are/are not passed from the main program

A

Are