2.2 Programing Techniques Flashcards

1
Q

What’s a variable?

A

Variables can change the data value that is assigned to them while the program is running.
-lower case first letter

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

What’s a constant?

A

A constant is an assigned data value at the design time of a program that can’t be changed. If you attempt to change the value of a constant in a program then the interpreter or compiler will return an error. It’s fixed for the duration of the program.
-CAPITALS for naming

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

What can data values be stored as?

A

Constants or variables

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

What’s the name of constant or variable linked to?

A

A memory location, that stores the data value. The size of the memory location depends on the data type.

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

What are the five main data types for programming languages?

A
Integer
Real(or float)
Boolean
Character
String
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What’s a pseudocode representation, description and an example of an integer?

A

Pseudocode:INT
Description:Whole numbers only.
E.g: 0,928,-167

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

What’s a pseudocode representation, description and an example of an real(or float)?

A

Pseudocode:REAL
Description:Numbers that have a decimal part
E.g: 0.15,-5.78,10.0

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

What’s a pseudocode representation, description and an example of an Boolean?

A

Pseudocode: BOOL
Description: Can only take one of two values, usually TRUE or FALSE.
E.g: true/false, 1/0, yes/no

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

What’s a pseudocode representation, description and an example of an character?

A

Pseudocode:CHAR
Description:A single letter, number or symbol
E.g: D, o, 7, ;, €

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

What’s a pseudocode representation, description and an example of an string?

A

Pseudocode:STRING
Description:Used to represent text, it’s a collection of characters.
E.g: “€>ehruK3nj”

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

What’s the assignment operator?

A

=
It’s used to assign values to constants or variables.
-the name of the constant or variable on the left hand side of the =
-whatever your assigning should be on the right of the =

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

What do comparison operators do?

A

They compare the expression on the left hand side to the expression to their right hand side and produce a Boolean value.

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

What’re 6 comparison operators and what do they mean?

A
== :equal to
<> or != :not equal to
< :less than
> :greater than
<= :less than or equal to
>= :greater than or equal to
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What’s casting?

A

Languages have functions that allow you to manually convert between data types this is know as casting. This can be done using the int(), float(), bool(), str() commands.

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

What happens if you convert the integer 1 into a float?

A

It becomes 1.0

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

What happens if you change the integer 1 into Boolean?

A

It’s converted into the Boolean value True

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

What’s the exponential symbol, example and explanation?

A

Symbol:^ or **
Example: 2^3 =8
Explanation:it’s used to raise a number to a power

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

What’s the quotient symbol, example and explanation?

A

Symbol: DIV
Example: 20 DIV 3 =6
Explanation:it returns the whole number part of a division

19
Q

What’s the remainder(modulus) symbol, example and explanation?

A

Symbol: MOD or %
Example: 20 MOD 3 =2
Explanation:it gives the remainder of the division

20
Q

How can you find the ascii number of characters and vice versa?

A

ASC() -converts a character into the corresponding ascii number
CHR() -converts the ASCII number into the equivalent character

21
Q

What are strings normally written inside?

A

Speech marks “ “

But sometimes single quotation marks are used ‘ ‘

22
Q

How can strings be joined together and what’s the word for it?

A

By using the + operator and it’s called concatenation

23
Q

What are characters in string numbered from?

A

They start from 0 and increment by 1 each time

24
Q

What’re 5 string manipulation functions?

A

x.upper
x.lower
x.length
x[i]
x.subString(a, b)

25
Q

What’s the operation and effect on x = “Hello” of x.upper?

A

Operation:changes all character in string x to upper case
Effect:HELLO

26
Q

What’s the operation and effect on x = “Hello” of x.lower?

A

Operation:changes all the characters in the string x to lower case
Effect:hello

27
Q

What’s the operation and effect on x = “Hello” of x.length?

A

Operation:returns the number of characters in string x
Effect:5

28
Q

What’s the operation and effect on x = “Hello” of x[i]?

A

Operation:extracts the chapter in position i from x
Effect: x[1] = “e”

29
Q

What’s the operation and effect on x = “Hello” of x.subString(a,b)?

A

Operation:extracts a string starting from position a with length b from string x
Effect:x.subString(3,2) = “lo”

30
Q

What’s a sequence program flow?

A

Where the program runs the steps in the order they’re written

31
Q

What’s selection program flow?

A

Selection allows different paths through the code depending on the outcome of a condition.
▶ IF – THEN – ELSE – END IF
▶ Nested Ifs
▶ CASE

32
Q

What’s iteration program flow?

A

When a process or sequence in a computer program is repeated, this is an iteration. In a computer program, a common form of iterations is a loop.
▶ FOR – NEXT (Count Controlled)
▶ WHILE – END WHILE (Condition Controlled)
▶ REPEAT – UNTIL / DO – WHILE (Condition Controlled)

33
Q

What’re nested if statements?

A

When you put one if statement inside another.

  • Nested ifs allow you to check more conditions once you’ve established that the previous condition is true
  • if-elif can also check multiple conditions but only if the previous condition was false
34
Q

What’re switch case statements?

A

They check the specific value of a variable not just checking wether it’s true or false
They’re used when you want a program to perform different actions for different values of the same variable
-switch-case statements have a similar structure to if-elseif structure but they can test different values of a variable the down side however they can only check the value of one variable whereas if-elseif can check if multiple conditions are true

35
Q

What’re for loops?

A

Count controlled loops

They repeat what’s inside of them for a set amount of times

36
Q

What’re repeat loops?

A

Controlled by conditions

  • controlled by a condition at the end of the loop and keeps going until the condition is true
  • runs the code inside at least once
  • you get an infinite loop if the condition is never true
37
Q

What’re while loops?

A

Controlled by conditions

  • controlled by a condition at the start of the loop
  • keep going while the condition is true
  • never runs the code inside if the condition is initially false
  • get an infinite loop if the condition is always true
38
Q

What’re do while loops?

A

Condition controlled loop

  • controlled by a condition at the end of the loop
  • keeps going while the condition is true
  • always runs the code inside at least once
  • get an infinite loop if the condition is always true
39
Q

When using external files what’s the first thing you need to do?

A

Open the external file
This is done by using an open command and assigning it to a variable
E.g. newFile = openRead(“newfile.txt”) -this allows you to read data from it
newFile = openWrite(“newfile.txt”) -this allows you to write data from your program to the file

40
Q

How can you write lines of text to a file?

A

Variable_name.writeLine()

41
Q

What’s the last thing you must do after using an external file?

A

Variable_name.close()

42
Q

How do you read from an external file?

A

Variable_name.readLine()

43
Q

How can you tell a program to stop reading an external file when it’s reached the end?

A

Variable_name.endOfFile()

44
Q

What are the three basic programming constructs?

A

Sequence, selection, iteration