2.2 Programming Fundamentals Flashcards

(17 cards)

1
Q

What is sequence?

A

The order in which instructions are executed in a program.
In a computer language it means that programming statements are set out one after the other.

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

What is selection?

A

Determining which choices you have to make.
You can use conditional statements like IF and CASE

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

What is iteration?

A

The repetition of a task is called iteration.
It can include things like:
FOR loops
WHILE loops
REPEAT or DO loops

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

What does MOD do?

A

Calculates the remainder of a division operator.
e.g. 10 MOD 3 = 1

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

What does DIV do?

A

It divides two numbers and returns the whole number part of the result, discarding any remainder.
e.g. 9 DIV 2 = 4

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

What does .length do?

A

Finds the length of a string e.g. wordlength = subject.length

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

What does .subString do?

A

Returns the part of a string that you take out. e.g.

Letter = subject.subString (0,1)
0 is the starting index and 1 is the number of characters you want

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

What does .left do?

A

Returns the number of letters you want from the left of a string e.g.
Text = subject.left(4)
4 is the number of elements in the string that are outputted

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

What does .right do?

A

Returns the number of elements you want from the left of a string e.g.
Text = subject.right(3)
3 is the number of elements in the string that are printed out

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

What does .upper and .lower do?

A

Convert a string between lowercase and uppercase.

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

How to use open in file handling?

A

MyFile = open(“sample.txt”)

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

How to read to file?

A

// You must use the same file object name consistently e.g. myFile
// This will read in the next line in the file object
// and assign it to the inline String variable
inline = myFile.readLine()

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

How do you write to file?

A

myFile.writeLine(“Add new line\n”)

myFile = open(“sample.txt”)
myFile.writeLine(“Add new line”)
myFile.close()

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

What is the code for reading and writing to the file?

A

// Open the file and declare variables
myFile = open(“Names.txt”)
array String szNames[]
int iCount = 0
int iNumNames = 0

// Count how many names currently exist in the file
while NOT myFile.endOfFile()
myFile.readLine()
iNumNames = iNumNames + 1
endwhile

// Close and reopen the file to reset the cursor back to the start of the file
myFile.close()
myFile = open(“Names.txt”)

// Set the size of the array plus 1 for the new name
iNumNames = iNumNames + 1
szNames[iNumNames]

// Read in the file into the array
while NOT myFile.endOfFile()
szNames[iCount] = myFile.readLine()
iCount = iCount + 1
endwhile

// User enters a name which is added to the end of the array
szNames[iCount] = input(“Enter a name: ”)

// Write each line in the array to file
for i = 0 to iNumNames-1
myFile.writeLine(szNames[i] + “\n”)
next i

// Close the file
myFile.close()

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

How to use random numbers?

A

// Create a random integer between 1 and 6 inclusive.
int randNum = random(1,6)

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

What is a database?

A

A database is a collection of data or information which is held together in an organised or logical way.