Logic and Languages Flashcards
What does the arithmetic operator ‘modulus’ do? Give an example.
This finds the remainder from a floor division. For example, 16 // 3 = 5 and 5 x 3 = 15, so 16-15 = 1 so the remainder is 1.
What does the arithmetic operator ‘floor division’ do? Give an example.
Also known as ‘whole number division’ so only look at the numbers before the decimal point (the integers). For example, 16 // 3 = 5.3333.. therefore the whole number is 5.
What does the arithmetic operator ‘exponentiation’ do? Give an example.
It calculates the power of a number. For example 7**2 = 49
What is the python and pseudocode symbol for ‘modulus’?
16 MOD 3 (pseudocode)
16 % 3 (python)
What is the python and pseudocode symbol for ‘floor division’?
16 DIV 3 (pseudocode)
16 // 3 (python)
What is the python and pseudocode symbol for ‘exponentiation’?
7^2 (pseudocode)
7**2 (python)
What can logic statements be evaluated to? (1 mark)
True (1) or False (0)
What are the types of Boolean operators?
AND, OR & NOT
What is a truth table? (2 marks)
A truth table is a method of representing every possible output based on the inputs to a Boolean expression.
What is NOT also know as?
Negation
What is OR also known as?
Disjunction
What does the OR operator return?
The operator returns true if either of the conditions are true. It only returns false if both conditions are false.
What does the NOT operator do?
Takes one input an reverses it
What does the AND operator do?
Only returns true if both conditions are true, else it returns false.
What is the order of precedence?
NOT, then AND, then OR
How do you find out the number of rows on your truth table? (1 mark)
Do 2 (base) to the power of n (the number of inputs) E.g. 2^3 = 8 rows
What do comparison operators do? (1 mark)
Evaluate to a Boolean value
What do Boolean operators do? (2 marks)
Take Boolean inputs and evaluate to a Boolean value
What are the two types of testing? (2 marks)
Iterative testing
Final testing/terminal testing
What is iterative testing? (2 marks)
Iterative testing tests modules and parts of a program as the program is developed
What is final/terminal testing? (2 marks)
Final testing (also known as terminal testing) tests the whole program at the end of production
What is the purpose of testing? (2 marks)
To find errors and determine (then patch) vulnerabilities so the program functions as intended
What are the two types of errors? (2 marks)
Syntax error
Logic error
What is the syntax of a language? (1 mark)
It is the collection of rules that form its structure
What is a logic error? (2 marks)
Logic errors appear when the program’s execution appears to run as normal, but not as the programmer intended
What is a syntax error? (2 marks)
A syntax error is one where the programming code written doesn’t conform to the rules of the language
Why does a syntax error appear? (3 marks)
The compiler doesn’t know how to translate the program into
machine code so will give the programmer a syntax error. The program cannot be run until all syntax errors are fixed.
What does a test plan test for? (3 marks)
Boundary/extreme data
Erroneous/invalid data
Normal/typical data
What is normal data? Give an example. (2 marks)
Normal data is test data that is typical (expected) and should be accepted by the system. A number between 0-100, e.g. 5
What is boundary data? Give an example (2 marks)
Boundary data is test data at the upper or lower limits of expectations that should be accepted by the system. A number between 0-100, e.g. 0 and 100.
What is erroneous data? Give an example. (2 marks)
Erroneous data is test data that falls outside of what is acceptable and should be rejected by the system. A number between 0-100, e.g. “ade”
What is a trace table useful for? (3 marks)
Determining the purpose of an algorithm
Finding the output of an algorithm
Finding errors in an algorithm
How is a trace table used to help find errors in a program? (3 marks)
Variable names and outputs are put in columns. The programmer traces through the program line by line updating the values of variables and outputs. A row is used for each iteration.
What is a trace table? (2 marks)
This is where the programmer goes through the code, line by line, writing down the values of variables
What is the difference between iterative and final testing? (2 marks)
In iterative testing, the programmer will usually test the code with knowledge of how it works. Whereas in final testing, the program may be tested by the programmer or end-user
What is data validation? (2 marks)
Checks data meets a set of criteria before you process it and can ensure that data entered is of the right type.
What is the difference between validation and verification? (2 marks)
Validation can only check that the data entered is reasonable
Verification is used to double-check that the data has been typed in correctly
What are the types of validation checks?
Range check Type check Length check Presence check Format check
What is a range check? (2 marks)
A number or date is within a sensible/allowed range
What is a type check? (2 marks)
Data is of the right type, such as integer, letter or text
What is a length check? (2 marks)
Text entered is not too long or too short – for example, a password is between 8 and 15 characters
What is a presence check? (2 marks)
Checks that data has been entered, i.e. the field has not been left blank
What is a format check? (2 marks)
Checks that the format of, for example, a postcode or email address is correct
What is authentication? (2 marks)
Authentication – entering data twice or checking from an alternative source
What is an example of anticipating misuse? (2 marks)
Anticipating misuse – preventing too many entries of a password to make it harder for hackers to guess
What is the purpose of authentication routines? (2 marks)
Authentication routines are used to make sure a person is who they claim to be
What is the purpose of data sanitisation? (2 marks)
The purpose of data sanitisation is to hide or protect data so it can’t be seen or disclosed, it involves modifying an input to make it valid.
What are the types of data sanitisation? (2 marks)
Masking
Input sanitisation
What is input sanitisation? (2 marks)
The process of checking data and removing dangerous inputs which could otherwise be used to cause damage to a program
What is masking? (1 mark)
Hiding visible data
What is an example of input sanitisation? (2 marks)
SQL injections, which involves the use of SQL code in a website form to try and hack into a database
What is a common method of online authentication? (1 mark)
Password routines
What can a trace table test for? (1 mark)
Logic errors
How can programs be written in a way that makes them easily maintainable? (4 marks)
Indentation
Commenting
Use of sub programs
Appropriate naming conventions
How is a program maintained? (2 marks)
By improving the code, fixing bugs or adding new features to the program
Why are sub programs used? (2 marks)
To create reusable code where bugs can easily be fixed
What is appropriate naming conventions? (2 marks)
It is good use of variables and sub program names to make the programs easier to read
Why is indentation used? (2 marks)
Indentation makes it possible to easily see which lines of code are part of different structures (show nesting) - easier to read
Why is commenting used? (2 marks)
Commenting helps programmers understand what a program does and how it does it
What are programming languages? (2 marks)
They are formal constructed languages designed to communicate instructions to a machine.
What is an advantage of machine code? (2 marks)
It requires the least abstraction, which means the processor can execute the code directly - more optimised
What is machine code written in? (1 mark)
Binary or hexadecimal numbers
What are the disadvantages of machine code? (3 marks)
Writing programs is difficult
Writing programs is time-consuming
It is specific to a processor and corresponds to its instruction set (not portable)
What are some examples of low level language?
Machine code
Assembly code
What is an instruction set? (2 marks)
The complete set of all the instructions in machine code that can be recognised and executed by a CPU
What is assembly code made up of? (1 mark)
Simple mnemonics
What are some disadvantages of assembly code? (2 marks)
It is processor-specific
It has to be translated into machine code before it can be executed
Why is assembly language a low-level language? (2 mark)
As each instruction corresponds directly to a machine code instruction (have an almost one-to-one relationship with machine code)
What are some examples of high-level languages? (5 marks)
Python Java C++ Ruby C#
What are the advantages of high-level languages? (4 marks)
Easier to learn
Programs can be written faster in a high-level language
It is easier to understand and debug a high-level language
Not hardware-specific (portable) - therefore can be executed on many computers with the correct translator
Why are high-level languages usually slower to execute when compared to low-level languages? (4 marks)
High-level languages have a lot of abstractions and layers of code before they reach the hardware itself. This code then needs to be translated into machine code. Therefore more work needs to be done at runtime, whereas, less abstract languages can optimise more.
How is high-level language translated? (2 marks)
By a compiler or interpreter
What is a translator? (2 marks)
A program that converts code from one language into equivalent code written in another - as all code needs to be translated to machine code.
What are the types of translators? (3 marks)
Assembler
Interpreter
Compiler
What is an assembler? (2 marks)
Uses the processor’s instruction set to convert instructions in assembly code to the machine code equivalent
What is the output of an assembler? (1 mark)
An object file
How would optimisation occur in assemblers? (2 marks)
substituting subprogram calls as if they were inline
calculating the values of constants
What is the advantage of assembly code? (2 marks)
You can program directly, which is used for writing specific instructions for embedded systems (e.g. washing machine)
What is an embedded system? (2 marks)
A microprocessor designed to perform dedicated functions within a larger computing system. It includes RAM, ROM and a CPU.
What is a compiler? (2 marks)
A compiler translates a high-level language into machine code. It produces a compiled program that can be directly executed.
What is the code written by a programmer called? (1 mark)
source code
What is the code written by a compiler called?
object code
Where can object code be saved in? (2 marks)
Object code can be saved in a storage drive and run whenever required. It must either be placed in an executable file, a library file, or an object file.
What is the disadvantage of a compiler? (2 marks)
Error messages are only shown after scanning the whole code, which can be time-consuming when debugging.
What are some advantages of a compiler? (3 marks)
After translation, the compiler and source code is no longer needed - this means you can distribute your program without the source code
A compiled program executes faster as it is already in machine code
Once compiled, the source code cannot be edited or adapted
What is an interpreter? (2 marks)
An interpreter is another type of program that translates a high-level language into machine code
What are some advantages of an interpreter? (3 marks)
It translates each line of code and executes it immediately
If it reaches a line with a syntax error, it stops and displays an error message
Interpreted code can run on any computer with an interpreter which makes it more portable
What is the difference between a compiler and an interpreter? (2 marks)
A compiler scans through the whole code and translates it into machine code. An interpreter works line-by-line, it translates a line and then immediately executes it.
What are some examples of compiled programming languages? (2 marks)
Java
C++
What are some examples of interpreted programming languages? (4 marks)
JavaScript
PHP
Python
Ruby
What are some disadvantages of an interpreter? (3 marks)
Takes more time to execute as each instruction is translated before it is executed
The interpreter must be installed and source code is required to run the program
Source code can be edited or adapted
What is a virtual machine? (2 marks)
A process virtual machine is a programming environment that allows a program written for one type of machine, to run on other types of machines, without any changes being necessary.
What is bytecode? (3 marks)
Bytecode is source code that has been compiled into low-level code and can be interpreted on many different types of processors using an interpreter. It is an intermediate stage between high-level and low-level language.
Why is some language compiled to bytecode? (1 mark)
For performance
What language compiles to bytecode? (1 mark)
Java
What is an IDE? (1 mark)
Integrated Development Environment
What is the purpose of an IDE? (2 marks)
An application that provides a selection of tools for programmers, allowing them to code using additional tools all in one place
What are some examples of IDEs in programming languages? (3 marks)
Visual Studio (C#)
Eclipse (Java)
IDLE (Python)
What is a code editor? (2 marks)
The code editor is a text edit area that allows developers to write, edit and save a document of code.
What is an example of a visual code editor? (1 mark)
Syntax highlighting
What are runtime errors? (2 marks)
Runtime errors are errors which will cause the program or computer to crash even if there appears to be nothing wrong with the program code
What is a common cause of runtime errors? (2 marks)
Running out of memory - because instructions have been written in the wrong order.
Why use error diagnostics? (2 mark)
Error diagnostics help a programmer to find where they have made a mistake
What are some examples of error diagnostics? (3 marks)
Inline syntax highlighting
Debug mode
Line numbers
What are line numbers? (3 marks)
Line numbers allow a programmer to clearly see each new line of code
When errors are found, the line number that they occur on will also be stated
What is syntax highlighting? (3 marks)
Syntax highlighting is where the colour of the text changes to show different parts of the program. Errors are also highlighted/underlined.
What is a method of debugging code? (1 mark)
Breakpoints
What is variable watching? (2 marks)
Variable watching is the process of inspecting the value of a variable while the program is executing in debug mode
What are breakpoints? (1 mark)
A point in the program where the code will stop executing.
Why are breakpoints set? (2 marks)
Breakpoints are set by the programmer so that the IDE stops the program mid-way through running
What do breakpoints allow a programmer to do? (2 marks)
Step through the code line by line
They can watch variables as they change
What is the purpose of stepping? (2 mark)
It executes the code one line at a time to check for errors.
What is a runtime environment? (1 marks)
Allows the programmer to test their program while it is running
What are some examples of code editors? (3 marks)
Auto-completion
Syntax checks
Bracket matching
What does a runtime environment allow the programmer to do? (2 marks)
Execute the program line by line and give useful information to the programmer if the program was to crash
What is auto-completion? (2 marks)
As you start to type the first part of a function, it suggests or completes the function and any arguments or variables
What is bracket matching? (2 marks)
It uses pairs of brackets to mark out blocks of code- which allows the code to be read and understood more quickly.
What are syntax checks? (2 marks)
This recognises incorrect use of syntax and highlights any errors
What are some examples of IDEs? (6 marks)
Translator Build automation Debugging tools Run-time environment Syntax highlighting Auto documentation
What does the runtime environment allow the programmer to access? (1 mark)
The libraries that come with the programming language
What does auto-documentation do? (2 marks)
This explains the function and purpose of the code
What is build automation? (2 marks)
These tools save time by automatically doing the processes that would otherwise be done by hand (e.g. testing or compiling)
What are importing libraries? (2 marks)
Importing libraries provide functions that are not included in the core part of the programming language
What are constants? (2 marks)
Data values that stay the same every time a program is executed
What is the purpose of optimisation? (1 mark)
To make your code more efficient
Why do computers use binary? (1 mark)
So that computers can be based on logic circuits
What is the name of the electrical components that are contained in the CPU, consisting in one of two states (on/off)?
Transistor
What are the features of a low level language
Runs quickly
Requires less RAM
can manipulate hardware
Processor-specific has to be translated into machine code
What is the relationship between transistors, logic gates and logic circuits? (2 marks)
Logic gates are made of transistors.
Logic circuits are made of logic gates.