2 Programming Flashcards
What is declaration?
Declaration is telling the computer what the identifier (name) should be and what type of data should be stored for a variable
What is assignment?
Assignment is changing the value stored inside a variable. The value stored must match the data type of the variable
What is input?
Input is collecting data, usually through the keyboard
What is input in pseudocode?
OUTPUT “enter [something]..”
variable = USERINPUT
What is output?
Output is putting data onto the screen, usually as text
What is output in pseudocode?
OUTPUT “text”
What are the data types?
Character Real String Integer Boolean
What is Character data?
Character data is a single letter of text data
Eg. ‘a’
What is Real data?
Real data is fractional numbers.
Eg. ‘0.55’
What is String data?
String data is text data.
Eg. “Hello”
What is Integer data?
Integer data is whole numbers.
Eg. ‘12’
What is Boolean data?
Boolean data is a true or false value.
Eg. ‘True’ or ‘False’
What does the type of data determine?
The type of the data determines how it is stored and what you can do with the data.
What is casting?
Casting is the process of converting data from one type to another.
What are the reasons for casting?
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 do you cast to a string?
Casting to a string can be done by using the str function
Eg. str(3) gives “3”
How do you cast to an integer?
Casting to an integer can be done using the int function. Eg. int(3.4) gives 3
How do you cast to a real?
Casting to a real can be done using the real function.
Eg. real(“3.4”) gives 3.4
What are operators?
Operators are symbols that represent a specific function within a program
What are the Arithmetic operators?
Integer division
Modulo operator
Basic Operators
What is the integer division operator?
The integer division operator returns the quotient (whole part) of a division.
Eg. 5 DIV 2 would give 2.
What is the Modulo operator?
The modulo operator gives the remainder of the division of two numbers.
Eg. 5 MOD 2 would be equal to 1.
What are the basic operators?
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.
What is the relational operator?
Relational operators compare two values, and produce a True or False value.
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.
What are the Boolean operators?
AND
OR
NOT
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
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
What is the NOT boolean operator?
NOT negates a logical value
Eg.
NOT True = False
NOT False = True
What is Sequence?
Sequence is when the computer follows a series of steps in the same order every time it is run
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
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.
What is an If-statement?
If-statements is an easy way of checking if a condition is true
What is an If-statement in pseudocode?
IF condition1 Then .action1() ELSE IF condition2 Then .action2() ELSE .action3() ENDIF
What is a switch-case statement?
A switch-case statement checks the value of a single variable.
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
Which shape is used to show a selection on a flow diagram?
Diamond symbol
What is Iteration?
Iteration allows a group of statements to be repeated multiple times. Iteration statements are often called loops.
What is definite iteration?
Definite iteration repeats a block of code for a known number of time
What is definite iteration in pseudocode?
For i = 0 to 7
.action()
NEXT i
What is indefinite iteration?
Indefinite iteration is a block of code that will repeat while a specified condition is true.
What are the two indefinite iteration types?
While loop
Do-until loop
What is a While loop in pseudocode?
WHILE condition
.action1()
.action2()
ENDWHILE
What is a Do-until loop in pseudocode?`
REPEAT
.action1()
.action2()
UNTIL condition
Which shape is used in a flow diagram for iteration?
Diamond shape
What is a subroutine?
A subroutine is a names block of code within your program
What are the advantages of a subroutine?
- Code is easy to read
- More Efficient
- More Reliable
How does a subroutine make code easy to read?
There are fewer long blocks of code to understand
How does a subroutine make the program more efficient?
Blocks of code only have to be created once but can be reused multiple times
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
What are parameters?
Parameters are special values that can be used to pass values in a subroutine
What are arguments?
Arguments are the actual value passed into the subroutine
What are the two types of subroutine?
- Function
- Procedure
What is a function?
A function is a subroutine which returns a value
What is a procedure?
A procedure is a subroutine which does not return a value
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
What will be the scope of a variable defined within a subroutine?
Local scope
A variable with a local scope can only be accessed where?
A variable with a local scope can only be accessed within that subroutine
What is a global variable?
A global variable is a variable that can be accessed by any part of the whole program