Pseudocode and General Stuff
Sample Pseudocode
BEGIN
CONSTANT StdDeduct = 10000
CONSTANT DepDeduct = 2000
CONSTANT Rate = 0.20
INPUT GrossIncome
INPUT NumDep
TotalDeduct ← StdDeduct + (NumDep * DepDeduct)
TaxableIncome ← GrossIncome - TotalDeduct
IncomeTax ← TaxableIncome * Rate
IF IncomeTax < 0
OUTPUT 'Income Tax is Negative !'
ELSE
OUTPUT IncomeTax
ENDIF
ENDCommon Pseudocode Keywords
BEGIN/ENDINPUT/OUTPUTIF/ELSE/ENDIFFOR/ENDFORWHILE/ENDWHILECONSTANT←— define<identifier> ← <value>
Array Declaration
DECLARE numbers : ARRAY[0:3] OF INTEGERData Validation
Purpose
To ensure that the data entered is sensible and reasonable
| Type | How it Works | Example |
|---|---|---|
| Existence Check | Checks if input is already in the system | Student name is in the database |
| Format Check | Checks if the data is in the correct format | Date in the format DD/MM/YYYY |
| Length Check | Checks if the length of the data is correct | Length of password |
| Presence Check | Checks if data is entered into a field | Username cannot be left blank |
| Range Check | Checks if the data value is within a certain range | Mark must be from 0 to 100 |
| Type Check | Checks if data is of the correct type | Number must be an integer (120), not a string (“120”) |
| Check Digit | The last one or two digits in data are used to verify whether the other digits are correct | NRIC/FIN number |
Data Verification
Purpose
To ensure the input data matches the original source
| Method | How it Works | Example |
|---|---|---|
| Double Entry | Data is entered twice to reduce the chance of errors | Creating a new password and entering it twice to reduce the chance of typos |
| Proofread | Checks that entered data is as intended | Reviewing an online form before submitting to ensure the data entered is correct |
Programming Errors
- Syntax error occurs when the syntax rules in the programming language is not adhered to (e.g. error in the syntax of a sequence of characters of tokens). Program will not compile until all syntax errors are corrected.
- Logical error is caused by wrong program design. This could happen when the algorithm for solving the program in incorrect. The program may be compiled and executed but does not give the expected output.
- Run-time error is detected at run-time e.g. stack overflow, division by 0, open a file that does not exist.
Modular Approach
Definition
| Aspect | Details |
|---|---|
| Definition | Modularity is the feature of designing a problem solution as a collection of well-defined separate modules, each serving a specific purpose and connected to the main program. |
| Module | A module is a complete part-program used within the main program. |
Advantages
| Advantage | Explanation |
|---|---|
| Encourages code reuse | Modules can be stored in a library and reused in other solutions. |
| Easier to debug | Modules are small and easier to test individually. |
| Easier to maintain and modify | Modules can be added or removed easily. |
| Supports teamwork | Different programmers can work on different modules simultaneously, and each module can be coded and tested separately. |
| Easier project management | Large projects become easier to monitor and control. |
Disadvantages
| Disadvantage | Explanation |
|---|---|
| Time-consuming planning | Extra time is needed to divide the problem into modules. |
| Larger memory usage | More memory space may be required. |
| Limited visibility | Programmers may not see all the code or documentation. |
| Over-modularisation | Too many modules can make the system unnecessarily complex. |
Incremental Approach
An incremental approach solves a small version of the problem first and gradually extends the solution to larger versions instead of recalculating from scratch.
Advantages
| Advantage | Explanation |
|---|---|
| Efficient testing and debugging | Small portions are added and tested step by step. |
| Early problem detection | Bugs can be identified and fixed early because development starts small. |
Disadvantages
| Disadvantage | Explanation |
|---|---|
| Code may become messy | The algorithm can become unstructured as it grows. |
| Harder to reuse code | The code may not be easily reusable in other algorithms. |