Topic 2 Programming Flashcards
Describe a variable.
A named location in the computers memory to store a single value which can change during the execution of a program. Eg radiusOfCircle
Describe a constant.
A named location in the computers memory to store a single value which CANNOT change during the execution of a program. Eg the value of Pi.
What is an identifier?
The NAME of a variable, constant, procedure or function.
What is meant by assignment?
Setting the specific value of a variable. Eg number = 2 means assign the value 2 to the variable called ‘number’.
List the arithmetic operators.
+, -, *, /, MOD, DIV, ^
Describe the arithmetic operator MOD
Modulus division. Returns the remainder after dividing one number by another. Eg 5 MOD 2 = 1
Describe the arithmetic operator DIV
Quotient division. Returns the whole number ignoring any remainder after dividing one number by another. Eg 5 DIV 2 = 2
Describe the the arithmetic operator ^
Exponential or power-of. Eg 3^2 = 9 (3 squared)
Describe the order or operations in arithmetic operators.
BIDMAS - Brackets, Indices, Division, Multiplication, Addition, Subtraction
What are relational operators used for?
To compare different items of data.
List/describe the 6 relational operators
= Equal To <> Not Equal To < Less Than > Greater Than <= Less Then or Equal To >= Greater Than or Equal To
What are logical operators used for?
To combine statements which can be evaluated as TRUE or FALSE.
Name the three logical operators.
AND, OR, NOT
Describe the AND logical operator
The overall statement is true only if ALL of the individual statements are true.
Describe the OR logical operator.
The overall statement is true if ANY of the individual statements are true.
Describe the NOT logical operator.
Used to reverse the logical state of other operators.
What are the three main programming constructs?
Sequence, Selection & Iteration
Describe the sequence construct.
Executing lines of code in the order they are written.
Describe the selection construct.
Choosing which lines of code to execute based on a condition being true or false.
Describe the iteration construct.
Repeating lines of code either for a set number of times, or while a condition is true.
List and describe the five main data types.
Integer - Whole numbers.
Real - Numbers which include fractions/decimals.
Boolean - one of two values - usually True or False.
Character - A single letter, number or symbol.
String - A sequence of characters.
What is meant by a ‘string literal’?
Characters enclosed in quotation marks.
Eg name = “Billy” - Billy is the string literal.
Describe ‘string concatenation’.
Joining two strings together. For example: fname = "Billy" sname = "Smith" fullname = fname + sname (concatenated)
Describe an array.
An array is a data structure which can store multiple data items using a single identifier/name. Elements of the array are accessed using an index number which starts from 0.
What is a two-dimensional array?
A data structure which uses two index numbers. The array would look like a grid/matrix and elements are accessed using the two indices.
For example array[2,4]
What is a sub-procedure or sub-program?
A self contained sequence of program instructions that perform a specific task.
Why are sub-programs useful?
- Help with decomposition of a problem
- Make programs shorter as they can be re-used
- Make code easier to read and test
- Can shorten development time
What are the two types of sub-program?
- Functions
- Procedures
What is the difference between a function and a procedure?
Functions return at least one value to the main program.
Procedures carry out a specific task without returning a value to the main program.
What is a parameter?
A value or piece of data passed into a function or procedure (sub-program).
What is validation?
Program code which checks that the data input is sensible, reasonable and appropriate.
For example:
In a program where the user was expected to enter a number between 1 and 10, validation would check:
a. A number was entered
b. That number lies between 1 and 10
Why is validation important?
Ensures that:
- number of user errors are minimised
- program behaves as expected in spite of user actions