click below
click below
Normal Size Small Size show me how
2.2.1
| Question | Answer |
|---|---|
| Programming Constructs | it is possible to nest constructs - Sequence - Iteration - Branching |
| Sequence | Computers will execute statements one after another, in the order they are presented Default construct |
| Iteration | Computers repeat a section of code (a loop) - Count(er)-controlled - Condition-controlled |
| Count(er)-controlled | Run a specified number of times - For loop |
| Condition-controlled | Run as long as a boolean expression is true - While loop - Do…until loop |
| Branching | (or selection) Allows a program to change direction depending on an outcome of a condition (Boolean expression) - if/else statements - switch/case statements - Assembly language: - BRA - BRP |
| Recursion | Where a procedure or function calls itself from within its own subroutine To stop infinite recursion + stack overflow, it: -Contain base case -Call itself for any input (not base case) -Base case reachable after a finite number of subroutine calls |
| Base case | stopping condition |
| Subroutine is called | program state (and all local variables) are stored on call stack, along with program line When finished, value is popped Same thing happens in recursion, just several times, running risk of stack overflow |
| Recursive (compared to iteration) | Iterative approaches should be favoured, but sometimes recursion is favourable or necessary. Pros More realistic + easier to code for some problems More elegant + easier to follow Cons More memory is needed Program may crash if stack overflow occurs |
| Variables | Named locations that store data Contents can be changed in execution, unlike constants Have data types + scope ( extent it can be seen within different parts of a program): If a local variable has the same name as a global one, it is prioritised |
| Local variable | Only accessible in the subroutine created in Created inside a subroutine Destroyed when the subroutine exits |
| Global variable | (generally avoided) accessed/used anywhere Typically created at the start of a program, outside of a subroutine Destroyed when the program ends Harder to debug + use more memory |
| Modularity | Concept of breaking down a large problem into smaller chunks, with aim of each module carrying out a single, specific task, making it easier to to test, read, share among a team subroutines shouldn't have effects on wider program (by value) |
| Procedure | perform a set task and takes in 0, 1 or more parameters |
| Functions | same as procedures, and returns a value |
| Parameter | a variable used within a subroutine, whose value is input into subroutine when called |
| Argument | the value passed into the parameter |
| two passing methods | - Passing by value - Passing by reference |
| Passing by value | (python) (favoured) A copy of the value is passed to the subroutine (turns into a local variable) The memory address of the real variable is not sent but the new one is More common, so always assume this method unless told otherwise :byVal code |
| Passing by reference | The parameter is set to point to the same memory location as the variable :byRef code prefix |
| Modules | proceeds or function |
| IDE | (Integrated Development Environment): single piece of software that provides a range of tools and features that help speed up and enhance program development. Features are combined together, and can be used simultaneously. |
| IDE key features | - Code editors - Error diagnostics - Runtime environments - Translators - Auto-documentation - Breakpoints |
| Code editors | text area for programmers to enter code directly into the IDE (often supports additional features as well) - Syntax highlighting - Autocomplete - Automatic indentation |
| Syntax highlighting | colours different parts of the program depending on what it is (e.g. variable, comment, reserved word) |
| Automatic indentation | whitespace is automatically placed before statements inside programming constructs like subroutines or loops |
| Error diagnostics | reports errors (mainly syntax) in the code and where they can be found; often suggests possible fixes |
| Runtime environments | software that supports the execution and running of programs to allow programmers to easily run code during development |
| Translators | a program that converts high-level code into executable machine code |
| Auto-documentation | tracks variables, modules and other comments to produce documentation that aides in program maintenance, debugging and support |
| Breakpoints | allow points to be set within the program where it will be paused when run to allow the programmer to try and detect where and why errors are occurring as the state of the variable are examined |
| Object-Oriented Techniques | Most problems can be solved using OOP best when u can encapsulate + model entities as objects E.g: GUI button (Or GUI in general) Attributes: size, colour, location Methods: clicked, hover, double-clicked When event triggered, alerts other objects |