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