2.2 Programming Techniques COMPLETE 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
What is the function of the comparison operator
Less than - checks if one value is less than another
26
What is the function of the comparison operator \<=?
Less than or equal to - checks if one value is less than or equal to another
27
What is the function of the comparison operator \>?
Greater than - checks if one value is greater than another
28
What is the function of the comparison operator \>=?
Greater than or equal to - checks if one value is greater than or equal to another
29
True or False: Comparison operators can only be used to compare numbers
False, these operators can be used with strings as well as numbers. The strings are compared alphabetically
30
Boolean Operator: AND
Ensures that the overall statement is true only of \*all\* the individual statements are true
31
Boolean Operator: OR
Ensures that the overall statement is true if \*any\* of the individual statements are true
32
Boolean Operator: NOT
Used to reverse the logical state of the other operators
33
In programming, what does sequence do?
Ensures that the commands are executed in the correct order
34
In programming, what does selection do?
Chooses between two or more options. Involves the use of combinations of if, else and elseif statements
35
When can if/else be used in programming?
if/else statements can be used if there are only two possible outcomes.
36
Why are elseif statements more efficient in programming?
As soon as the correct condition is found, none of the rest of the options are checked
37
Why are else statements used in programming?
To state what should happen if none of the options in the if or elseif statements are true
38
What are nested if statements?
If statements that are completely within another if statement
39
Every if statement always needs its own _____ statement
endif
40
\_\_\_\_\_\_\_\_\_ 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
Iteration
41
What is count controlled iteration?
Iteration used when the number of iterations is known before the loop is started
42
What is a condition controlled iteration?
Iteration used when the number of times a loop is executed is determined by a condition
43
Are while loops an example of count controlled iteration, condition controlled iteration or can they be either?
While loops can be count controlled or condition controlled
44
Are for loops an example of count controlled iteration or condition controlled iteration?
Count controlled
45
Are do...until loops an example of count controlled iteration or condition controlled iteration?
Condition controlled
46
What do for loops do?
Instruct the loop to be executed for a set number of times
47
What do condition controlled while loops do?
Continue while a condition remains true and stops when it becomes false
48
What makes a count controlled while loop less efficient than a for loop?
More lines of code are needed
49
What do do... until loops do?
Continue until a condition becomes true
50
In a while loop the variable to be tested must be ________ \_\_\_ _____ \_ _____ before the loop is started
Declared and given a value (initialised)
51
What must happen each time a while loop is ran?
Must be incremented or decremented
52
What is the difference between a while loop and a do... until loop?
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
53
What does concatenated mean?
Combined
54
Why must computers be aware of data types of values stored in variables?
So that data is interpreted and manipulated correctly
55
What is an integer?
A number without a fraction or decimal. Integers can be positive or negative
56
Give an example of an integer
Any whole number eg 0, 3, 100, 10369
57
What is a real number?
All numbers that exist and their fractions and decimals
58
Are integers real numbers?
Yes
59
Why is it more efficient to declare integers as integers?
So that less memory is needed
60
What are real numbers declared as in pseudocode/python?
'float'
61
Give an example of a real number
Any number, including decimals, such as 2, 3.9, 6.632, 9.37352
62
What is a character?
A single letter, number or symbol
63
Give an example of a character
Any letter, number or symbol eg C, 3, !
64
What can a string hold?
A list of characters of any length
65
What are strings enclosed in?
Single or double quotation marks
66
Give an example of a string
Anything enclosed in single or double quotation marks eg "Hello user3 your password is ?1pass69word"
67
Data used by a computer are presented in strings of...
1s and 0s
68
What happens if a computer is not told the data type?
It will not be able to use it correctly eg it may try to multiply text and display numbers as images
69
Data types must be declared in all/some programming languages
Some
70
What would int age declare?
That the variable "age" is to store integer numbers
71
What happens in languages that the data type does not have to be stated?
The type is inferred from the type of data first stored (eg age = 13 would imply that the variable age stores integers)
72
What is casting?
The conversion of one data type into another
73
What would str(integerVariable) do?
Convert an integer into a string
74
Casting must be done in all/some programming languages when concatenating variables and text in a print statement
Some
75
What would int(stringVariable) or float(stringVariable) do?
Convert a string into an integer or a real number
76
What is a string?
A string is a sequence of characters than contain letters, numbers and symbols
77
What does a string literal consist of?
Characters enclosed in quotation marks such as "A13!"
78
What is a string variable?
A string that can be declared, such as password = "A13!"
79
Is print("A13!") a literal string or a variable string?
A literal string
80
Is print(password) a literal string or a variable string?
A variable string
81
password = "A13!" Do print("A13!") and print(password) produce the same output?
Yes
82
password = "A13!" Why do print("A13!") and print(password) produce the same output?
Because the variable "password" is a string variable and it has a value of "A13!"
83
What does concatenation mean?
Joining
84
Strings can/cannot be concatenated
Can
85
Strings can be concatenated end to end to form larger strings using the _ symbol
+
86
The position of a character in a string is given by its...
Index number
87
What is the first index in a string?
0
88
"STRING" What is the index number of the letter N in this string?
4
89
What is string traversal?
The process of moving through a string one character at a time.
90
What can string traversal be used to do?
See if a string contains a particular character or group of characters
91
The ______ of a string must be found in order to create a loop to examine each character
Length
92
True/False: A loop can be set up to move through a string
True
93
Why must a loop be set up to run from 0 to the length of the string minus one?
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
What can be snipped out of a string?
Substrings or portions
95
myString = "RosieandJack" snip = myString.substring(2, 4) print(snip) What does the numbers 2 and 4 do in this string? What will this print?
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
What is the difference between an array and a variable?
Variables store one item of data that can change whereas arrays can store multiple items of data, not just one
97
What is an array?
A data structure that can store multiple items of data, called elements
98
What are items of data in an array called?
Elements
99
Elements are all of the same ____ \_\_\_\_ under the same \_\_\_\_\_\_\_\_\_
data type and identifier
100
How is an array created?
By specifying the elements stored in the array (declaring)
101
What does declaring an array mean?
Specifying the elements stored in an array.
102
array names = ["Alice", "Catherine", "David"] array scores = [10, 13, 17] What is this array doing?
Storing 3 people's names and their scores
103
What are elements in an array enclosed within?
Square brackets
104
What are elements in an array separated with?
Commas
105
What is an element? (Computer Science)
An item of data at a particular index
106
If the elements in an array are at index positions 0 to 4, what is the length of the array?
5
107
What is a two-dimensional array?
In a 2D array there is a second array at each index position of a one-dimensional array
108
What do two-dimensional arrays form?
A matrix
109
In a two-dimensional array, each element has ___ indices to indicate its position
Two
110
What would an array with the structure as shown be declared as?
array arrayName [5, 4]
111
Why would an array with the structure as shown be declared as array arrayName [5, 4]?
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
How is data assigned to an element in an array?
Index position
113
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
True
114
Before a file can be accessed or opened, it must be given a...
File handle
115
What is a file handle?
A reference assigned to a file so that the program can access it. eg myFile = openWrite("Sample.txt")
116
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
True
117
If you save a file and a file with that name already exists, what happens to the existing file?
It will be overwritten and the existing data will be lost
118
What does OpenAppend("filename.txt") do?
Prevent data being lost due to it being overwritten
119
Once a file has been read from or written to, it must be...
Closed (eg myFile.close())
120
True/False: A user can't open a file and write data directly to it from the keyboard
False - they can
121
True/False: A program can be coded to save data stored in variables to a text file
True
122
What does myFile. openRead("filename.txt") do?
Opens a file to read data
123
True/False: Data stored in a text file can be loaded into the variables of a program
True
124
What does the endOfFile() function do?
If the number to read in is not known, the endOfFile() function can be used
125
What is a record? (Computer Science)
A collection of data objects relating to a particular subject or entity
126
True/False: The data items stored in each record must be of the same data type
False, they can be of different data types eg integers and strings
127
What does DBMS stand for?
Database management system
128
Large volumes of data are usually stored in d\_\_\_\_\_\_\_\_
databases
129
How are databases created?
Using a DBMS (database management system)
130
How is data stored in a database?
Tables
131
What do column headings in a table in a database define?
Fields
132
Each record in a database must have a ___ \_\_\_\_\_ that is an item of data that is unique to that record
key field
133
Each Each column in a table in a database is a \_\_\_\_\_
Field
134
What is stored in each record of a database?
An item of data
135
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
can be different
136
What are records sometimes referred to as?
Structs
137
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
Can be different
138
What does SQL stand for?
Structured Query Language
139
What is SQL used for?
Creating, maintaining and accessing databases
140
What does SQL allow users to do?
Search for records that contain a particular item or items of data.
141
What keyword is used for searching with SQL?
WHERE
142
What keyword is used to display records with SQL?
SELECT
143
Are commands in SQL case-sensitive?
No - eg both select and SELECT will work
144
What is the wildcard symbol % used for in SQL?
Used as a substitute for one or many characters
145
What is the wildcard symbol \* used for in SQL?
To represent 'all fields', for example WHERE TUTORgROUP like "%x"; would return all records with a tutor group ending with an X
146
SELECT FirstName, Surname FROM Students; What is important about the syntax of this command?
There is a semi-colon at the end of the command
147
Why are commands written on a seperate linewhen searching with SQL?
To make them easier to understand
148
What is a sub-program?
A self-contained sequence of program instructions that performs a specific task
149
What does using sub-programs allow?
The production of more efficient code
150
When are sub-programs called?
Whenever it is needed to carry out that function
151
What is another name for sub-programs?
Subroutines
152
True/False: Sub-programs allow the production of structured code
True
153
True/False: Sub-programs make programs longer
False - the code only needs to be written once and can be called as many times as needed
154
True/False: Sub-programs make program code easier to read and test
True
155
True/False: Sub-programs make the development time of a program longer
False, they shorten the development time of a program
156
Do sub-programs make testing easier or harder?
Easier
157
Sub-programs make code more/less readable
More
158
What is a function?
A sub-program that returns a value to the main program when it is called
159
What is a procedure?
A sub-program that carries out a specific task but does not return values to the main program
160
Values passed to the function from the main program are stored in the sub-program's...
parameters
161
True/False: Sub-programs need to be defined
True
162
To create a sub-program, do you need to define it with its type and indicate where it ends?
Yes
163
What does "return velocity" do in a function?
The value of velocity is returned to the main program
164
What are variables used only within a sub-program and not in a main program called?
Local variables
165
What needs to be stated that stores the values that a function will use?
Parameters
166
True/False: Values of parameters are not passed to them by the main program when the function is called
False, they are
167
True/False: Sub-programs cannot be called from within the main program
False, they can
168
If the value of the local variable "velocity" is the result of a calculation performed in a function, what is it passed back to?
The specified global variable in the main program
169
averageVelocity = vspeed(distanceTravelled, tiemTaken) What does this line of code do?
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
Why is it best that you don't use the same names for local and global variables?
You could get into a muddle with the logic and mix them up
171
What are global variables?
Variables that exist within the main program and can be referenced in other lines of code
172
What do procedures do?
They do not return a value to the main program. They could print out a message for the user, for example
173
Parameters in a procedure are/are not passed from the main program
Are