2 Programming Flashcards

1
Q

What is declaration?

A

Declaration is telling the computer what the identifier (name) should be and what type of data should be stored for a variable

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

What is assignment?

A

Assignment is changing the value stored inside a variable. The value stored must match the data type of the variable

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

What is input?

A

Input is collecting data, usually through the keyboard

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

What is input in pseudocode?

A

OUTPUT “enter [something]..”

variable = USERINPUT

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

What is output?

A

Output is putting data onto the screen, usually as text

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

What is output in pseudocode?

A

OUTPUT “text”

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

What are the data types?

A
Character
Real
String
Integer
Boolean
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is Character data?

A

Character data is a single letter of text data

Eg. ‘a’

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

What is Real data?

A

Real data is fractional numbers.

Eg. ‘0.55’

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

What is String data?

A

String data is text data.

Eg. “Hello”

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

What is Integer data?

A

Integer data is whole numbers.

Eg. ‘12’

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

What is Boolean data?

A

Boolean data is a true or false value.

Eg. ‘True’ or ‘False’

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

What does the type of data determine?

A

The type of the data determines how it is stored and what you can do with the data.

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

What is casting?

A

Casting is the process of converting data from one type to another.

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

What are the reasons for casting?

A

One of the most common reasons for casting is output.
Output must be formatted as a string, and so we may need to convert a certain piece of data to a string.
All input also comes as a string, and must then be converted to other data types.

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

How do you cast to a string?

A

Casting to a string can be done by using the str function

Eg. str(3) gives “3”

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

How do you cast to an integer?

A

Casting to an integer can be done using the int function. Eg. int(3.4) gives 3

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

How do you cast to a real?

A

Casting to a real can be done using the real function.

Eg. real(“3.4”) gives 3.4

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

What are operators?

A

Operators are symbols that represent a specific function within a program

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

What are the Arithmetic operators?

A

Integer division
Modulo operator
Basic Operators

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

What is the integer division operator?

A

The integer division operator returns the quotient (whole part) of a division.
Eg. 5 DIV 2 would give 2.

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

What is the Modulo operator?

A

The modulo operator gives the remainder of the division of two numbers.
Eg. 5 MOD 2 would be equal to 1.

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

What are the basic operators?

A
Addition is done using a + sign.
Subtraction is done using a - sign.
Division is done using a / sign.
Multiplication is done using a * sign.
Exponentiation is done using a ^ sign.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What is the relational operator?

A

Relational operators compare two values, and produce a True or False value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What are the Equality operators?
We can test if two values are equal using the equality operator. Eg. 4 = 4 is True We can also test if two values are not equal using the not-equal-to operator Eg. 4 ≠ 4 would evaluate to False.
26
What are the Boolean operators?
AND OR NOT
27
What is the AND Boolean operator?
``` The AND boolean operator evaluates if both operands are True Eg. True AND True = True True AND False = False False AND True = False False AND False = False ```
28
What is the OR boolean operator?
``` The OR boolean operator evaluates to True if only one of the operands are True. Eg. True OR True = True True OR False = True False OR False = False False OR True = True ```
29
What is the NOT boolean operator?
NOT negates a logical value Eg. NOT True = False NOT False = True
30
What is Sequence?
Sequence is when the computer follows a series of steps in the same order every time it is run
31
When might sequence not be useful?
Selection may not be useful for longer code where as we can't use any selection or iteration structures
32
What is selection?
Selection allows us to have decisions made in our program | Selection allows us to execute a section of code depending on whether a condition is met or not.
33
What is an If-statement?
If-statements is an easy way of checking if a condition is true
34
What is an If-statement in pseudocode?
``` IF condition1 Then .action1() ELSE IF condition2 Then .action2() ELSE .action3() ENDIF ```
35
What is a switch-case statement?
A switch-case statement checks the value of a single variable.
36
What is a switch-case statement in pseudocode?
``` SWITCH X: .CASE "A": . print("X is A") .CASE "B": . print("X is B") .DEFAULT: . print("X is not A nor B") ENDSWITCH ```
37
Which shape is used to show a selection on a flow diagram?
Diamond symbol
38
What is Iteration?
Iteration allows a group of statements to be repeated multiple times. Iteration statements are often called loops.
39
What is definite iteration?
Definite iteration repeats a block of code for a known number of time
40
What is definite iteration in pseudocode?
For i = 0 to 7 .action() NEXT i
41
What is indefinite iteration?
Indefinite iteration is a block of code that will repeat while a specified condition is true.
42
What are the two indefinite iteration types?
While loop | Do-until loop
43
What is a While loop in pseudocode?
WHILE condition .action1() .action2() ENDWHILE
44
What is a Do-until loop in pseudocode?`
REPEAT .action1() .action2() UNTIL condition
45
Which shape is used in a flow diagram for iteration?
Diamond shape
46
What is a subroutine?
A subroutine is a names block of code within your program
47
What are the advantages of a subroutine?
- Code is easy to read - More Efficient - More Reliable
48
How does a subroutine make code easy to read?
There are fewer long blocks of code to understand
49
How does a subroutine make the program more efficient?
Blocks of code only have to be created once but can be reused multiple times
50
How do subroutines make the program more reliable?
If there are bugs in the program, each subroutine can be tested individually to make sure it works
51
What are parameters?
Parameters are special values that can be used to pass values in a subroutine
52
What are arguments?
Arguments are the actual value passed into the subroutine
53
What are the two types of subroutine?
- Function | - Procedure
54
What is a function?
A function is a subroutine which returns a value
55
What is a procedure?
A procedure is a subroutine which does not return a value
56
What is the scope of a variable?
The scope of a variable is the group of areas of the code from which it can be accessed
57
What will be the scope of a variable defined within a subroutine?
Local scope
58
A variable with a local scope can only be accessed where?
A variable with a local scope can only be accessed within that subroutine
59
What is a global variable?
A global variable is a variable that can be accessed by any part of the whole program
60
How can a variable be made to have a global scope?
A variable can be made global by adding the 'global' keyword in front of it the first time it is used
61
What is an array?
An array is a data structure that stores a fixed number of values under a single identifier.
62
When storing values in an array what must the values all be?
The values must be of the same type.
63
When are Arrays useful?
Arrays are useful when you have lots of related data that you don't want to store in multiple variables
64
What is an element?
An element is each piece of data inside an array
65
What is an element's index?
An element's index is it's position within the array. The counting of the elements starts at zero
66
How would you create an array of x number of items in pseudocode?
array name_of_array[10]
67
How would you assign values in an array?
name_of_array[x] = "Hello" | x is the element number you wish to put the value number into
68
How can you access values within an array?
OUTPUT name_of_array[x] | x is the element number you wish to access
69
What do lists store?
Lists store multiple elements under the same identifier.
70
What is the maximum number of elements a list can have?
There can be a variable number of elements - they never get full.
71
How can lists be declared?
A list can be declared as follows: | list = []
72
How can values be added to the end of the list?
Values can be added to the end of the list as follows: | list.append["value"]
73
What is a 2D list?
A 2D list is the data structure which consists of a list of lists.
74
To access an individual list in a 2D list?
list = my2DList[4]
75
How would you access an individual element in a 2D list?
list[5][0] | This would get the first element of the sixth list
76
What are the uses of a 2D list?
A 2D list could be used for a 2D surface or a database
77
How can a 2D list be used for a database?
Each inner list can store a record of the database | The outer list can store each record
78
What is a string?
Strings are special cases of arrays or lists, where each element is a character
79
What is concatenation?
Concatenation is joining two strings together. This can be done with the + sign. Eg. "Hello" + "World" = "Hello World"
80
How would we access a character in a string?
str[3] | This accesses the 4th character in the string
81
How would we see the length of a string?
Use the len function | Eg. len("Hello") would give 5
82
What are the string operations?
- Length - Substring - Concatenation
83
What is the purpose of files??
Files allow us to store data so it continues even when the program is not running Files allows programs to carry on where they left off when they are executed
84
What are text file made up of?
String data
85
What is binary files mad up of?
Binary data
86
Why should we be careful with the way we handle data?
We should be careful with the way we handle data so we do not accidentally corrupt them
87
How do we open a file so the operating system knows we are using it?
We can use these commands: openRead("filename.txt") openWrite("filename.txt")
88
How do we assign a variable to a file?
``` MyVariable = openRead("filename.txt") MyVariable = openWrite("filename.txt") ```
89
How do we read/write in a file?
We use the following commands: myFile.readLine() will return the next line of a file as a string. myFile.writeLine() will write a line to the file. myFile.endOfFile() will return True if we reach the end of the file.
90
How do we close a file?
We can close a file using the following command: | myFile.close()
91
What is structured data?
Structured data refers to any data that resides in a fixed field within a record or file so that it can be easily entered, stored, queried, and analysedof records
92
What are the pros and cons of records?
Pros: Very simple, text-based format. Can be read by many applications. Easy to use in programs. Cons: Inefficient for large datasets. Can only store text data. No built-in means of sorting or searching.
93
What are comma separated values (CSV)?
CSV is one method of storing a record Each record is stored on its own line Each field is separated by a special character such as a comma
94
What are records made up of?
Fields
95
What are identifiers?
Identifiers are the names given to variables, constants, and subroutines
96
How should variables be named?
Variables should be be lowercase and an underscore should separate each word. They should also have descriptive names Eg. this_is_my_variable
97
How should constants be named?
Constants should be named the same as variables (an underscore separates each letter and they should have descriptive names) but unlike variables the letters are uppercase
98
How should subroutines be named?
Subroutines should have lowercase names, with each word separated by an underscore Eg. calculate_sum() Subroutines should have descriptive names where possible
99
What is Whitespace?
Whitespace is key to good code, since it is used to separate blocks of code and make code easier to read.
100
When should blank lines generally be used?
Subroutines should be separated by a blank line. Blank lines can be used sparingly in subroutines to show sections of the subroutine. Other lines of code should not have blank space around them.
101
What are comments?
Comments are lines of code that are ignored completely by the computer They are used to add description to your code to make it easy to understand
102
Why is indentation necessary in some coding languages?
Indentation is necessary in some languages to control program flow
103
Which character is used for comments in pseudocode?
#
104
What is an interface?
An interface is a collection of comments which describe a subroutine. An interface includes: List of parameters and their types. Return value and its type. What the subroutine does.
105
What do validation and sanitation protect against?
Validation and sanitation can help to protect against malicious inputs such as SQL injection attacks
106
What is input sanitation?
Input sanitation involves the removal of unwanted characters from input data Any data entered by users which might be executed or become part of a query should first be sanitised.
107
What is input validation?
Input validation is the process of making sure that input data meets certain criteria. If a user's data is rejected, they should be informed and asked to enter it again
108
What are the input validation rules?
``` Input validation rules include: Type checks Range checks Presence checks Format checks Length checks ```
109
What are type checks?
Type checks check the type (e.g. Integer) of the input
110
What are range checks?
Range checks check that the data is inside an allowed range, e.g. less than 100
111
What are presence checks?
Presence checks check that the required data has been input
112
What are format checks?
Format checks check that the data fits a set format, e.g. an email address has an @ symbol
113
What are length checks?
Length checks check that the number of characters entered is inside a permitted range.
114
What is Contingency planning?
Contingency planning is a course of action designed to help someone respond to a future event or situation that may happen This includes: Providing helpful prompt messages Providing error-recovery routes (e.g. an undo feature) Preventing access from certain parts of the system Using exception handling
115
What is authentication?
Authentication is the process of checking that a person or system is authorised to use a system.
116
What is the most common form of authentication?
The most common form of authentication is to require users to enter a username and password.
117
What happens when a user is authenticated?
Once a user has authenticated themselves, they should be able to see data relevant to themselves and no one else.
118
What are errors in software often called?
Bugs
119
What gets rid of bugs?
Debugging
120
What are the purposes of testing?
The purposes of testing are to check that a program: Works as intended under good conditions Copes with errors when given bad data
121
What does debugging means?
Debugging is to find the cause of the bug and fix it
122
Are bugs deliberate attempts to bring down systems?
No
123
What are some different types of testing in the development stages?
Performance and load testing Usability testing Functionality testing Security testing
124
When does terminal testing occur?
Terminal testing occurs at the end of development
125
What are the results of terminal testing used for?
The results of terminal testing are used to check how the software performs when given a certain set of test data.
126
When does Iterative testing occur?
Iterative testing involves testing code as it is written
127
What are the results of iterative testing used for?
The results of iterative testing are fed back into the development process
128
What is test data?
Test data involves using a range of data, both valid and invalid, to see how the program responds
129
What are the different types of data used in testing?
Valid data is correct and of the right format Extreme data is correct but on the edge of the valid range Invalid data is not within the acceptable range or is an invalid format Null data is where no data is entered to see what happens Erroneous data is of the wrong type altogether
130
What are test plans?
Test plans are created to make sure that testing is effective by detailing which test will be performed, which test data will be used, and what the intended outcome will be
131
When should a test plan be created?
A test plan should be made before development and is part of the design stage
132
What are High-level languages?
High-level languages include most programming languages such as Python, C++ and Java
133
What are High-level languages (HLLs) made up of?
High-level languages are made up of human-readable statements which makes it easy to understand
134
What does it mean when High-level languages (HLLs) are portable?
High level languages are portable, which means that they can be run on many different types of hardware
135
Why don't we always use High-level languages (HLLs)?
Computers can only process instructions in the form of binary numbers. We have to use special HLL software which translates our HLL source code into executable binary
136
What are Low-level languages (LLLs)?
Low-level programming languages are languages which are much closer to computer-understandable binary.
137
Why do we use Low-level languages (LLLs)?
LLLs provide exact control over the central processing unit LLLs need less translation, and often lead to faster code which is useful for computers with low specifications such as embedded systems
138
What are translators?
Translators are special software that convert source code into executable binary
139
What are compilers?
Compilers are software that translates the whole of a program in one go Eg. C, C++, Visual Basic and Swift
140
What are the pros of compilers?
Compilers produce an executable program: There is no need to repeat this process more than once per version of the software. Compilers hide the source code from the end user. This helps to protect developers' intellectual property. Compilers will provide a list of errors once it has attempted the compilation process. This can make debugging easier.
141
What are the cons of compilation?
The compilation process can be very slow, this slows development if small changes need to be made
142
What are Interpreters?
Interpreters are are a type of translator which convert high level languages to executable machine code Eg. Python and JavaScript
143
What are the cons of Interpreters?
Running an interpreted program is slower than a compiled program because we have to translate each line every time we run the software But it is quicker to get started which can be good for small changes Interpreters do not produce a compiled program file: The process must be repeated each time the program is run
144
What are the pros of interpreters?
Interpreters stop as soon as they encounter an error. This is useful for debugging Interpreted languages are portable. This means they can be run on many different types of CPU's as long as there is an interpreter available for the platform
145
What do assemblers do?
Assemblers translate assembly code into executable binary
146
What is Assembly?
Assembly is a low-level language where each instruction directly responds to a binary sequence and the assembler replaces the commands with the relevant binary
147
What are the pros of assemblers?
Assembly provides exact control over the hardware: This can lead to very efficient code that takes up little space in memory and is quick to execute. Assembly can be used on low specification machines.
148
What are the cons of assemblers?
Assembly is very difficult to use, and needs deep technical knowledge of the central processing unit and the memory.