2.3 Additional Programming Techniques Flashcards

1
Q

What is an array

A

An array is a static data structure that can hold a fixed number of data elements. Each data element must be of the same data type i.e. real, integer, string.

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

How are elements in an array identified

A

The elements in an array are identified by a number that indicates their position in the array. This number is known as the index. The first element in an array always has an index of 0.

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

How do we traverse through an array

A

To traverse (‘move through’) an array a for loop can be used to display each data element in order
For examples

for name in ScoobyGang :
print (name)

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

Inserting a value

A

In an array the size is fixed so you cannot insert new values, but you can change the value of elements that already exist. Overwriting the fourth element (Daphne) with a new value (Laura) will change it from Daphne to Laura.
ScoobyGang[3] = “Laura”

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

Deleting a value

A

In an array the size is fixed so you cannot delete values, but you can overwrite them as blank. Overwriting the second element (Shaggy) with a blank space makes it appear deleted.
ScoobyGang[1] = “ “

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

Searching for an array

A

For large arrays a for loop is needed to search through each element for a specific value. This example checks each name to see if it is equal to Velma.

for name in ScoobyGang :
if name == “Velma” :
print (name)

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

2D- Array

A

Often the data we want to process comes in the form of a table. The data in a two dimensional array must still all be of the same data type, but can have multiple rows and columns.

Each value in the array is represented by an index still, but now the index has two values. For example [3] [0] is ‘Daphne’. We measure row first, then column.

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

Searching for a two-dimensional array

A

To print a specific data element you can just use the index number like Daphne above. To search for a specific value you will need two for loops, one for the row and another for the values of each row.

The example to the right is looking for the value of ‘Velma’ and when it is round it prints the associated data from the whole row.

for row in ScoobyGang:
for name in row:
if name == “Velma”
print (row)

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

Records

A

Unlike arrays, records can store data of different data types.

Each record is made up of information about one person or thing.

Each piece of information in the record is called a field (each row name).

Records should have a key field - this is unique data that identifies each record. For example Student ID is a good key field for a record on students as no two students can have the same Student ID.

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

SQL

A

SQL (structured query language) is a language that can be used to search for data in a database.

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

What is the format of an SQL statement

A

SELECT field1, field2, field3
FROM table
WHERE criteria

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