Programming Y10 Assessment Flashcards
Describe what is meant by ‘data type’
The data type determines what type of value the variable will hold.
Define ‘integer’, ‘real’, ‘Boolean’, ‘character’ and ‘string’ data types
INT - 2/4 bytes - whole number,
REAL - 4/8 bytes - decimal numbers,
BOOL - 1 bit needed but 1 byte usually used - TRUE/FALSE,
CHAR - 1 byte - a single alphanumerical character
STRING - 1 byte per character - One or more alphanumeric characters
Declare and assign constants and variables
Constant) CONSTANT PRESSURE
Describe ‘iteration’
There are times when a program needs to repeat certain steps until told otherwise, or until a condition has been met. This process is known as iteration
Describe ‘Selection’ + example with multiple selections
Selection is a programming construct where a section of code is run only if a condition is met.
IF \_\_ THEN OUTPUT ‘_’ ELSE IF _ THEN OUTPUT ‘_’ ELSE OUTPUT ‘_’ ENDIF
Use and explain definite (count-controlled) iteration
When a program needs to iterate a set number of times, this is known as definite iteration and makes use of a FOR loop.
FOR k
Use and explain indefinite (condition-controlled) iteration:
• Indefinite iteration repeatedly executes a section of code until a condition is met - or no longer met. There are two types of indefinite iteration:
• WHILE loops - uses the statements WHILE and ENDWHILE
WHILE total < cost
coinValue
Use and explain nested structure
Including one programming construct within another.
• FOR x ← 1 TO 10
FOR y ← 1 TO 10
result ← y * x
OUTPUT y + “ * “ + x + “ = “ + result
ENDFOR
ENDFOR
Explain the need for meaningful identifiers
Making sure you use variable names that describe what the variable contains is very important. Poor variable names can make it difficult to work out what is going on in your program
Write code that accepts keyboard input
name ← USERINPUT
Write code to display output on a screen
OUTPUT “Hello” + name
Write code to perform string operations ‘length’, ‘position’, ‘substring’ and ‘concatenation’
- LEN(string)
* POSITION(string, character)
* SUBSTRING(x, y, string)
* Concatenation - multiple strings joined together : newString
Write code to cast one data type as another
- STRING_TO_INT(‘1)
* STRING_TO_REAL(‘1.0’)
* INT_TO_STRING(1)
* REAL_TO_STRING(1.0)
* INTs and REALs have quote marks, strings don’t!• CHAR_TO_CODE(‘b’)
Write code that performs arithmetic operations (addition, subtraction, division, multiplication)
- +
* -
* *
* /
Write code that performs relational operations (combinations of less than, equal to, not equal to and greater than)
- =
* ≠
* <
* >
* ≤
* ≥
Distinguish between low-level and high-level languages - examples and definitions
• Machine code is the set of instructions that a CPU understands directly and can act upon. A program written in machine code would consist of only 0s and 1s - binary. This is very difficult to write and debug. Even a very simple program could have thousands of 0s and 1s in it.
• Assembly language sits between machine code and high-level language in terms of ease of use. While high-level languages use statements to form instructions, assembly language uses mnemonics - short abbreviations. Each mnemonic directly corresponds with a machine code instruction.
High level - These languages are close to natural language - the spoken and written language of humans
Distinguish between interpreters, compilers and assemblers for program translation
• An interpreter translates source code into machine code one instruction at a time. It is similar to a human translator translating what a person says into another language, sentence by sentence, as they speak. The resulting machine code is then executed immediately. The process is called interpretation..
• A compiler takes the source code as a whole and translates it into machine code all in one go. Once converted, the object code can be run unassisted at any time. This process is called compilation.
The purpose of an assembler is to translate assembly language into machine code.Whereas compilers and interpreters generate many machine code instructions for each high-level instruction, assemblers create one machine code instruction for each assembly instruction
When is low-level language more suitable?
Low level languages are used to write programs that relate to the specific architecture and hardware of a particular type of computer.
2 Benefits of using programming language that is interpreted rather than compiled?
- Instructions are executed as soon as they are translated.
* Errors can be quickly spotted - once an error is found, the program stops running and the user is notified at which part of the program the interpretation has failed. This makes interpreters extremely useful when developing programs.
3 Benefits of using a programming language that is compiled instead of interpreted?
- Compiled programs run quickly, since they have already been translated.
* A compiled program can be supplied as an executable file. An executable file is a file that is ready to run. Since an executable file cannot be easily modified, programmers prefer to supply executables rather than source code.
* Compilers optimise code. Optimised code can run quicker and take up less memory