Programming (PAPER 2) Flashcards
What are the five main data types
- What are the characteristics of each
Integer - Whole Numbers
Float / Real - Numbers with decimals
Boolean - One of two values, usually True or False
Character - A single letter, number or symbol
String - Used to represent text, is a collection of characters
How much memory is used for each main data type
Integer - 2 or 4 bytes
Float / Real - 4 or 8 bytes
Boolean - 1 bit needed but 1 byte is usually used
Character - 1 byte
String - 1 byte for every character in the string
What are the benefits of using the correct data type (3)
more memory efficient, robust, predictable
What is casting
- What are the five commands that do this
using functions to manually convert between data types
- int (), real (), float (), bool (), str ()
What function finds the ASCII number of characters (and vice versa)
ASC (), CHR ()
What are the 7 basic arithmetic operators (programming)
- What are the operators used for each
Addition, Subtraction, Division, Multiplication, Exponentiation, Quotient, Modulus
> +, -, /, *, ^ or **, DIV, MOD or %
What is the quotient
- What is the Modulus
the whole number value after diving a number e.g. 20 DIV 3 = 6
- the remainder e.g. 20 MOD 3 = 2
What two data types do Basic Arithmetic Operators work with
real or integer (or both)
What is the assignment operator
- What does it assign
=
- values to constants or variables
What do comparison operators do
compare the value on the left to that on their right and produce a True / False value (Boolean)
What are the 6 comparison operators
- What do they mean
== is equal to
<> or != is not equal to
< is less than
> is greater than
<= is less than / equal to
>= is more than / equal to
How can data values be stored
as constants or variables
Where is the name of a constant or variable linked to
- What does the size of this depend on
A memory location
- the data type
What is a constant
a value which has been assigned at design time and can’t be changed
What is a variable
can change value at any time
What are the standard naming conventions that programmers follow when naming constants and variables (2)
lower case first letter
no spaces
How are strings written
- What is the name for merging strings
- Which operator is this done with
- double quotes, but occasionally single quotes
- concatenation
- operator
How are the characters in a string usually numbered
starting from 0
What are the 6 common string manipulations
- What do each of them do
- What are these special functions known as
x.upper, x.lower, x.length, x.left(i), x.right(i), x.substring(a, b)
- Changes all characters in string x to upper case,
changes to lower case,
returns number of characters in string x,
Extracts first i characters from string x,
Extracts last i letters,
Extracts a string starting at position a with length b form a
- methods
What are substring, left and right methods also examples of
slicing - part of a string is extracted and returned as a new string
What does an IF statement allow for
allows you to check if a condition is true or false, and carry out different actions depending on the outcome
What is the usual structure for an IF statement
IF-THEN-ELSE
What is a nested If statement
- What do these allow you to do
an IF statement inside another one
- check more conditions once established that the previous one is true
What is the difference between IF-ELSEIF and nested IF statements
IF-ELSEIF statements only check more conditions if the previous condition is false
What is the alternate name for SWITCH statements
- What do these do
CASE SELECT
- check if a variable has specific values
What is written at the end of an IF and SWITCH statement
- endif
- endswitch
When are SWITCH statements used
when you want a program to perform different actions for different values of the same variable
What is written to introduce an IF or SWITCH statement
- if … then
- variable = …
switch variable:
What are the benefits and drawbacks of using Switch statements over IF statements
- Easier to maintain. neater to test different values of a variable
- only check the value of one variable, IF-ELSEIF statements can check if multiple conditions are true
What do FOR loops do
repeat the code inside them a fixed number of times
What three values do the number of times a code repeats depend on in a FOR loop
initial value, end value and step count
If no step count is provided for a for loop, what will it automatically be
1 step
With what code can the number of times the loop repeats can also be set as the program runs
for k = 1 to x
(x is a variable)
between which two words is the FOR loop repeated
for and next
What is a FOR loop concluded with
next k
What are the 4 differences between DO UNTIL and WHILE loops
DO UNTIL:
- controlled by condition at end of loop
- keeps going until condition is true
- always runs code within at least once
- infinite loop if condition is never true
WHILE:
- controlled by condition at start of loop
- keeps going while condition is true
- never run code inside if condition is initially false
- infinite loop if the condition is always true
When does a DO WHILE loop keep going
while the condition is true and always runs the code inside at least once
What are logic gates
- What are the three steps of what they do
special circuits built into computer chips
- receive binary data
- apply a Boolean operation
- output a binary result
What is written to show logic gates and circuits
logic diagrams
What are the three types of logic gate
AND, NOT, OR gates