Topic 2 - Programming Flashcards

1
Q

What’s Declaration

A

Before variables can be used, they must be declared.
Declaring a variable means telling the computer:
What the identifier (name) should be.
What type of data will be stored.

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

What’s assignment

A

Changing the value stored inside a variable is called assignment.
The value assigned to a variable 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

Why do some languages not need to declare the variable

A

Some languages don’t need you to declare variables before you use them:
These languages automatically declare the variable before the first assignment.

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

What’s input

A

Input is collecting data, usually by the keyboard.
This is written in pseudocode as:
OUTPUT “Please enter [something]…”
variable = USERINPUT

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

What’s output

A

Output is putting data to the screen, usually as text.
This is written in pseudocode as:
OUTPUT “Text goes here”

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

What’s a string

A

Text data.
Example:
“Hello, world!”.

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

What’s a character

A

Character
A single letter of text data.
Example:
‘a’.

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

What’s a Boolean

A

A True or False value.
Examples:
True.
False.

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

What’s a real

A

Fractional numbers.
Examples:
0.42, 1.00.

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

What’s an integer

A

Whole numbers.
Examples:
12, 0, -142.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
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
12
Q

What are casting functions

A

Casting to a string can be done using the str function. E.g:
str(3) gives “3”.
Casting to an integer can be done using the int function. E.g:
int(3.4) gives 3.
Casting to a real can be done using the real function. E.g:
real(“3.4”) gives 3.4.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
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
14
Q

What’s a modulo operators

A

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

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

What’s integer division

A

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

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

How do we test for comparisons

A

We can compare two numbers using the less than and greater than signs. For example:
2 < 3 evaluates to True.
2 > 3 evaluates to False.
We can test for less than or equal, or greater than or equal like this:
2 ≤ 3 evaluates to True.
3 ≥ 3 evaluates to True.

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

How do you test for equality

A

We can test if two values are equal using the equality operator. For example:
2 = 2 would evaluate to True.
We can test if two values are not equal using the not-equal-to operator:
2 ≠ 2 would evaluate to False.

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

What do ORs do

A
OR evaluates to True if any of the two operands are True:
True OR True = True.
True OR False = True.
False OR True = True.
False OR False = False.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What do NOTs do

A

NOT negates a logical value.
NOT True = False.
NOT False = True

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

What do ANDs

A
AND evaluates to True if and only if both operands are True.
True AND True = True.
True AND False = False.
False AND True = False.
False AND False = False.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What happens in a sequence algorithm

A

In a sequence algorithm, the computer follows a series of steps that are executed in the same order every time it runs.
This is often not very useful for longer codes because we cannot use any selection or iteration structures

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

What happens in a flow chart

A

The flow chart for a sequence program will have the blocks one by one.
One arrow will connect each block to the next block.
There will be no diamond shapes, so the diagram will be mainly:
Ovals.
Rectangles.
Parallelograms.

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

What’s selection

A

Selection allows us to execute a section of code depending on whether a condition is met or not

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

What’s Does an if statement do

A

An if-statement is an easy way of checking if a condition is true.

25
Q

What’s a switch case statement

A

A switch-case statement checks the value of a single variable

26
Q

What’s used to show selection in a flow diagram

A

The diamond symbol is used to show selection in a flow diagram.

27
Q

What’s definite iteration

A

A block of code will repeat a known number of times.

28
Q

What does a flow diagram use for iteration

A

A flow diagram for iteration uses the diamond shape

29
Q

What’s indefinite iteration

A

A block of code will repeat while a specified condition is true

30
Q

What are the advantages of subroutines

A

Easier to read:
There are fewer long blocks of code to understand.
More efficient:
Blocks of code can be written once and reused many times.
More reliable:
Each subroutine can be individually tested to make sure it works.

31
Q

What are parameters and arguments

A

Parameters are special variables used to pass values into a subroutine.
Arguments are the actual values that are passed in.

32
Q

What are the types of subroutines

A

A function is a subroutine which returns a value.

A procedure is a subroutine which does not return a value

33
Q

What’s a local scope

A

A variable defined within a subroutine will have local scope.
This means that they can only be accessed within that subroutine

34
Q

What’s a global scope

A

A variable can be made global by adding the ‘global’ keyword in front of it when it is first used.
Global variables may be accessed by any part of the whole program

35
Q

What are arrays

A

An array is a data structure that stores a fixed number of values under a single identifier.
The values must be of the same type.

36
Q

What are array elements

A

Each piece of data inside an array is called an element.
Each element has an index, which is its position within the array.
We start counting the indices from 0.

37
Q

What are arrays in pseudo code

A
An array of ten items can be created using the following syntax:
array name_of_array[10]
Values can be assigned as follows:
name_of_array[0] = "Hello"
Values can be accessed as follows:
OUTPUT name_of_array[0]
38
Q

What’s concatenation

A

Concatenation is joining two strings together.
This can be done with the + sign. E.g:
“Hello “ + “World” = “Hello World”.

39
Q

How do you asses a character

A

Remember, strings are just lists. So we can access a specific character in the exact same way as we access a list element:
string[3] would get the fourth character

40
Q

How do you know the length of a string

A

The length of a string is given by the len function:

len(“Hello”) would give 5.

41
Q

What’s a substring

A

A substring is a part of a longer string.
In pseudocode, we use the function:
substring(startPos, endPos, string)
This takes a substring starting at the ‘startPos’th character, and ending at the ‘endPos’th character.

42
Q

What are lists

A

Lists store multiple elements under the same identifier.

There can be a variable number of elements - they never get full

43
Q

What are list is in pseudocode

A

A list can be declared as follows:
pupils = []
Values can be added to the end of the list as follows:
pupils.append(“Alice”)
Values can be accessed as follows:
print(“The first student is “ + pupils[0])

44
Q

What’s a 2D list

A

A 2D list is a data structure where lists are filled with other lists.
This can be used to represent a 2D surface, or records.

45
Q

How do you access elements lists

A

To access an individual list, we can access the list as usual:
list = my2DList[4]
To access an individual element, we use this syntax:
list[5][0]
This would get the first element of the sixth list.

46
Q

What are the uses of 2D lists

A

2D lists are often used to represent a 2D surface, for example a chess board:
Each element of the 2D list could contain the chess piece in that location.
2D lists can be used to represent a database:
Each inner list can store a record of the database.
The outer list can store each record.

47
Q

What are text files

A

Text files consist of string data that can be read and processed by many applications

48
Q

What are files

A

Files allow us to store data so that it persists even when our program is not running.
This allows programs to ‘carry on where they left off’ when they are executed.

49
Q

What are binary files

A

Binary files consist of binary data that is read and processed by specific applications

50
Q

Why do we need to be carful when we access files

A

We must be careful with the way we access files so that we do not accidentally corrupt them

51
Q

How do we open files

A

First we open the file for use, so that the operating system knows that we are using it.
We can do this using:
openRead(“filename.txt”)
openWrite(“filename.txt”)

52
Q

How do we assign the variable

A

The file must be assigned to a variable so that we can keep refering to it.
This can be done as follows:
myFile = openRead(“filename.txt”)
myFile = openWrite(“filename.txt”)

53
Q

How do we read and write files

A

We can now read or write to the file using 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

54
Q

Why do we close files and how

A

Finally, we must close the file so that it is free for another program to access.
We can do this using:
myFile.close()

55
Q

What does structured data refer to

A

any data that resides in a fixed field within a record or file so that it can be easily entered, stored, queried, and analysed

56
Q

What are records

A

Records are made up of fields.

For example, a person could be represented as a record where the fields include their name, age, and address

57
Q

What are Comma separated values (CSV) and what do they do

A

One method of storing a record is using comma separated values.
Each record is put on its own line.
Each field is separated by a special character such as a comma

58
Q

What are the pros and cons of records

A
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