14
Programming Definitions
Definitions Eng. Omar El Safty
General Programming Terms
1. Program
Definition:
• A list of instructions that does a specific task
• It can be written in high-level language or low-level language
2. Pseudocode
Definition:
Method that uses English words and mathematical notations to design the steps of a
program.
3. Flowcharts
Definition:
Diagram that designs the steps of a program by using a standard set of symbols joined by
lines to show the direction of flow.
4. Trace Table
Definition:
• Table that can be used to record the results from each step in an algorithm
• It is used to record the value of a variable each time it changes
• Used to document the dry run of program
5. Tracing (Dry Run)
The manual exercise of working through an algorithm step by step
6. Variable
Definition:
A named data store that contains a value that can change during the execution of a
program.
7. Constant
Definition:
A named data store that contains a value that does not change during the execution of a
program.
110
Definitions Eng. Omar El Safty
8. Comments
Definition:
Blocks of text in the pseudocode that are not executed used to explain the code.
9. Features of a maintainable program
• Use comments …
• … to explain the purpose of each section of code
• Use meaningful identifier names to …
• … clearly identify the purpose of variables, constants, arrays, procedures and
functions
• Use procedures and functions …
• … to avoid repeated code
• … and to simplify logic
• Use indentation and white space …
• … to make the program readable
10. Component parts after decomposition
• inputs – the data that needs to be entered to the system
• processes – the tasks that need to be performed using the input data and any
previously stored data
• outputs – information that needs to be displayed or printed for the users
• storage – data that needs to be stored in files for use in the future
11. Top-Down design
Definition:
The breaking down of a computer system into set of sub systems and then breaking each
subsystem into set of smaller ones until each sub system performs a single action.
Stepwise refinement definition:
Process of breaking down into smaller sub-systems
Module definition:
An individual section of code that can be used by other programs
111
Definitions Eng. Omar El Safty
12. Structure Chart // Structure Diagram
Definition:
Diagram that shows the design of a computer system in a hierarchal way, with each level
giving a more detailed breakdown of the system.
Purpose:
• To provide an overview of the system hierarchy
• To provide overview of how a problem is broken down
13. Ways to represent an algorithm
• Flowcharts
• Pseudocode
• Structure Diagrams
14. Basic concepts (constructs) to use when developing a
program:
• Data use – variables, constants and arrays
• Sequence – order of steps in a task
• Selection – choosing a path through a program
• Iteration – repetition of a sequence of steps in a program
• Operator use – arithemtic operations for calculation and logical and boolean
operators for decisions
Program Development Lifecycle
15. Stages of Program Develeopment Lifecycle
Analysis
• Identification of the problem and requirements
• May include breaking down the problem into smaller parts
• Includes abstractions (removal of details)
Design
• Drawing flowcharts to solve the problem
• Writing pseudocode statement to solve the problem
• Decomposing the problem into smaller parts using structure diagrams
Coding
• Writing program code solutions (using a programming language)
• May include early testing
Testing
• Testing the program code using test data
112
Definitions Eng. Omar El Safty
Tasks performed in analysis:
• abstraction
• decomposition
• identification of the problem and requirements (requirement specification)
Abstraction Definition:
• simplifying the problem
• selecting elements required
• filtering out irrelevant characteristics from those elements
Decomposition Definition:
• breaking down a complex problem into smaller parts
• which can then be divided into even smaller parts that can be solved easily
Tasks performed in design:
• decomposition
• structure diagrams
• flowcharts
• pseudocode
Tasks performed in coding:
• writing program code
• iterative testing
Iterative Testing Definition:
• tests are conducted to each sub-system of the program
• errors are corrected
• tests are repeated until the sub-system performs as required
Tasks performed in testing:
• testing program code…
• … using test data
Testing Definition:
• The completed program or set of programs is run many times…
• …with different sets of test data
• …to ensure all the completed tasks work together as specified in the program design
113
Definitions Eng. Omar El Safty
16. Operators
Operators definition and purpose:
A special character or word in programming that identifies an action to be performed
Arithmetic Operators Definition and purpose:
Operators that are used to perform calculations.
Logical Operators Definition and purpose:
Operators that allow the computer to decide whether an expression is true or false
Boolean Operators Definition and purpose:
Operators that are used that is used with logical operators to form a more complex
expression.
17. Program data types:
Data type Definition Examples
A positive or negative whole number be used 150
Integer
in mathematical operations -100
A positive or negative number that has a
100.5
Real fractional part that can be used in
-15.2
mathematical operations
Char A single character from the keyboard H
Hello World
String A sequence of characters
A312_@odq
Boolean Data with two possible values TRUE/FALSE
18. Sequential statements
Definition:
Statements are executed one after another according to their order.
19. Assignment Statement
• A statement that changes the value of a variable or an element in an array
• Example: Value <- 39 sets the value of the variable Value to 39
20. Prompt Message
Definition:
An output message that is displayed before the user input stating the input required
Purpose:
Helps the user to know what they are expected to input
114
Definitions Eng. Omar El Safty
21. Conditional/Selection statements
Definition:
Selective statement(s) are executed depending on meeting certain criteria.
Purpose:
To allow different paths through a program depending on meeting certain criteria.
22. IF .. THEN .. ELSE .. ENDIF
Definition:
A conditional structure with different outcomes for true and false.
Purpose:
It allows for checking complex conditions.
23. CASE .. OF .. OTHERWISE .. ENDCASE
Definition:
A conditional structure that allows selection to be made based on value of a variable.
Purpose:
Used to test for a large number of discrete values.
24. Iterative/Repetition statements
Definition:
One or more statements are repeated till a test condition is met or whilst a test condition
is TRUE.
Purpose:
To repeat same or similar code a number of times, which allows for shorter code.
Types:
• Count-controlled loops
• Pre-condition loops
• Post-condition loops
115
Definitions Eng. Omar El Safty
25. FOR .. TO .. NEXT (Count-controlled loop)
Definition:
A loop structure that iterates a set number of times.
Purpose:
used when a set (known) number of iterations are required
26. WHILE .. DO .. ENDWHILE (Pre-condition Loops)
Definition:
• A loop that iterates whilst a specified condition exists
• Criteria is pre-tested (It has criteria check at the start)
• It may never run
27. REPEAT .. UNTIL (Post-condition Loops)
Definition:
• A loop that iterates until a condition is met
• Criteria is post-tested (It has criteria check at the end)
• It iterates at least once
Differences between REPEAT ... UNTIL and WHILE ... DO ... ENDWHILE:
• In WHILE the criteria is pre-tested but in REPEAT..UNTIL the criteria is post-tested
• WHILE may never run while REPEAT.. UNTIL runs at least once
• WHILE iterates whilst a condition is TRUE but REPEAT UNTIL iterates till a condition
is TRUE
28. Standard methods of solution
• Totalling
• Counting
• Finding maximum/minimum value
• Finding Average (mean) value
• Searching using Linear Search
• Sorting using a bubble sort
29. Totaling
Definition:
The process of summing a list of number.
Example:
Sum ß Sum + Num
116
Definitions Eng. Omar El Safty
30. Counting
Definition:
The process of finding how many items are in a list.
Example:
Count ß Count + 1
Arrays
31. Array
Definition:
A data structure that holds a number of elements of the same data type
Purpose:
• To store multiple values under the same identifier making the code shorter
• Allows for simpler programming
Index definition
The position of an element in an array
Dimension definition
The number of indexes required to access an element in an array
32. One-dimensional (1-D) Array
Definition:
• a list / one column of items
• ... of the same data type
• ... stored under a single name
• ... with a single index to identify each element
Purpose of using arrays:
• Makes the program easier to design / code / test / understand
• Code will be more compact
• Code will be more organized
• Less likely to make errors
Declaring a 1D array:
DECLARE Numbers : ARRAY[1:10] OF INTEGER
OR
DECLARE Numbers[1:10] : INTEGER
117
Definitions Eng. Omar El Safty
33. Two-dimensional (2-D) Array
Definition:
• a table-like collection of items
• ... of the same data type
• … has row and columns
• ... stored under a single name
• ... with two indexes to identify each element
Declaring a 2D array:
DECLARE Marks: ARRAY[1:10, 1:3] OF INTEGER
OR
DECLARE Marks[1:10, 1:3] : INTEGER
.
Linear Search & Bubble Sort
34. Linear Search
Definition:
The process of finding an value within a list of elements
Steps:
• Loop over a list of items starting with the first element and finishing with the last
• Compares each element with a search value…
• … if it is equal to the search value, set a flag to TRUE
• … it is not move to the next element
• After iterating over all the elements the flag shows whether the element is found or
not
35. Bubble Sort
Definition:
The process of sorting a list of items either in alphabetical order or using numeric values
Steps:
• Loops over a list of items starting with the first and finishing with next-to-last
element
• Each element is compared with the next element
• … swaps the elements if the elements are in the wrong order
• … after reaching the last element the last element is now in the correct position
• This is repeated a number of times equivalent to the number of elements in the list…
• …to ensure that all elements are in the correct position
118
Definitions Eng. Omar El Safty
File Handling
36. Purpose of using files:
• Data is not lost when the computer is switched off (data is stored permanently)
• Data can be used by more than one program or reused when a program is run again
• Data can be transported from one computer to another
Functions / Procedures
37. Subroutine
Definition:
• Sub-program
• Used to perform a frequently used operation within a program
• Given a name and can be called when needed
• Can be reused by another program
• Written in High Level Language
Purpose of using subroutines (functions / procedures):
• to enable the programmer to write a collection of programming statements under a
single identifier
• to allow procedures to be re-used within the program or in other programs
• to enable different programmers to work on different procedures in the same
project
• to make programs easier to maintain due to program code being shorter
38. Function
Definition:
A subroutine that always returns a value.
39. Procedure
Definition:
A subroutine that doesn’t return a value.
119
Definitions Eng. Omar El Safty
40. Function/Procedure Definition
Definition:
• Setting-up the function/procedure
• Includes defining the:
• Function/Procedure name
• Parameter names and data types
• In case of a function, the return data type
• Done only once
41. Function/Procedure Call
Definition:
• Using/executing the function code with parameters values
• Can be done multiple times
Difference between function/procedure definition and function/procedure call
• Defining is done once, calling can be done multiple times
• Defining is setting up the function/procedure and calling is using the function
Describe what happens when a function is called during the execution of a program
• A call statement is used in order to make use of a function
• Parameters are be passed from the main program to the function
• The function performs its task..
• ..and returns a value to the main program
42. Local Variable
Definition:
• A variable that is defined inside the scope of a subroutine (function/procedure)
• Its scope is restricted to only the part of the program where it was defined
• Can be accessed only within the scope of the subroutine (function/procedure)
where it was defined
43. Global Variable
Definition:
• A variable that is defined outside the scope of a subroutine (function/procedure)
• Its scope covers the whole program
• Can be accessed from outside any function and from inside the scope of any
function
120
Definitions Eng. Omar El Safty
Differences between local and global variables:
• for local variables the scope is a defined block of code (procedure/function)…
• …while global variables the scope is the whole program
• For local variables value cannot be changed elsewhere in the program…
• … while global variables the value can be changed anywhere in the program
44. Parameter
Definition:
A variable that is used to pass values (from the main program) to a subroutine
(function/procedure)
Purpose:
• to pass values from the main program to a procedure / function
• …so that they can be used in the procedure / function
• allow the procedure / function to be re-used with different data
45. Return value
Definition:
A value that is passed from inside a function to the main program
46. Library Routines
Definition:
It is a list of programming instructions that is:
• Given a name
• Already available for use
• Pre-tested
Benefits of using library routines:
• Library routines make writing programs easier and faster as the code is already
written
• They make testing the program easier as the code has already been tested and
debugged
• Immediately available for use // They are readily available / speed up development
time
• Can perform a function that you may not be able to program yourself
121
Definitions Eng. Omar El Safty
Purpose of ROUND:
• To return a value rounded to a specified number of digits / decimal places
• The result will either be rounded to the next highest or the next lowest value
• ... depending on whether the value of the preceding digit is >=5 or <5
• Example of ROUND for example, ROUND(4.56, 1) = 4.6
Purpose of RANDOM:
• To generate (pseudo) random numbers
• ...(usually) within a specified range
• Allow example e.g. RANDOM() * 10 returns a random number between 0 and 10.
Purpose of DIV:
• To perform integer division of two numbers..
• .. with the fractional part discarded
• Example of DIV For example DIV(9,4) = 2
Purpose of MOD:
• To perform (integer) division when one number is divided by another
• .. and find the remainder
• Example: 7 MOD 2 = 1
Databases
47. Database
Definition:
A structured collection of related data that allows people to extract information in a way
that meets their needs.
48. Purpose of SQL keywords
Purpose of SELECT:
An SQL command that identifies the fields to be displayed
Purpose of FROM:
An SQL command that identifies the table to use
Purpose of WHERE:
An SQL command that identifies the search criteria // An SQL command to include only the
records that match a given condition.
122
Definitions Eng. Omar El Safty
Purpose of ORDERBY:
An SQL command that sorts the result of the query by a given column
Purpose of SUM keyword in SQL:
An SQL command that returns the sum of all values in a field
Purpose of COUNT keyword in SQL:
An SQL command that counts the number of records returned by the query
49. Database terms:
Term Definition Examples
Table A collection of related records Table of students
For a student the fields
could include:
A column that contains one specific piece of • Student name
Field
information and has one data type • Student ID
• Age
• Address
Field Name Title given to each field
A row within a table that contains data about a Details (all information) of
Record
single item, person or event one student
A field that contains unique data and can’t have Student ID field
Primary Key
duplicates
Validation & Verification
50. Validation
Definition:
The automated checking by a program that data to be entered is sensible.
123
Definitions Eng. Omar El Safty
51. Examples of validation checks:
Validation check Definition Examples
Checks that the data entered has the A person’s age should be a
Type Check
appropriate data type number not text.
Checks that some data has been entered An email address must be
Presence Check
and the value has not been left blank given for an online transaction
It checks that only numbers within a Exam marks between 0 and
Range Check
specified range are accepted 100 inclusive
It checks that data contains an exact A password with exactly 8
Length Check
number of characters characters in length
A company with IDs that start
It checks that the characters entered
Format Check with MS then three numbers
conform to a pre-defined pattern
would have a format of MS###
A digit that it is calculated from all the
Check Digit Used in barcodes
other digits and appended to the number
52. Verification
Definition:
Checking that the data has not changed during input to a computer or during transfer
between computers.
Purpose:
To ensure the accuracy of transcription.
Types:
• Screen/Visual Check
• Double Data Entry
53. Screen/Visual Check
Definition:
• Data is compared visually with the source document by a user
• The user is asked to confirm that the data entered is same as original
• If user finds a difference, the data is re-entered
124
Definitions Eng. Omar El Safty
54. Double Data Entry
Definition:
• Data is entered twice (sometimes by two different people)
• A computer checks that both entries are equal
• If they are not equal, an error message requesting to re-enter the data is displayed
Testing data
Definition:
Data used to check that a computer responds correctly to correct and incorrect values.
Purpose:
• check that the program works as expected
• check for errors
• check that the program rejects any invalid data that is input
• check that the program only accepts reasonable data
55. Types of test data:
Type Definition Examples
Correct data that should be The month can be any whole number
Normal Data
accepted in the range of 1 to 12
All the following values are not
allowed as inputs for the month:
Data outside the limits of
• Negative numbers
acceptability, or wrong type of data,
Abnormal Data • Any value greater than 12
and should be rejected
• Letters or non-numeric data
• Non-integer values
(e.g., 3.5,10.75, etc.)
Largest/smallest acceptable value The extreme values of month can be
Extreme Data
and should be accepted either 1 or 12
The extreme values of month can be
The largest/smallest acceptable
either 1 or 12
Boundary Data value and the corresponding
The (boundary) rejected values of
smallest/largest rejected value
month can be 0 and 13
125
Definitions Eng. Omar El Safty
Digital Logic
56. Logic gate
Definition:
A small physical device that controls the flow of electrical signals in a pre-determinant
way.
Purpose:
• To carry out a logical operation
• To control the flow of electricity through a logic circuit
• To alter the output from given inputs
Why data is stored as binary in computers?
• Computer use logic gates
• Logic gates use one of two values: 0 or 1
Types of logic gates:
• NOT
• AND
• OR
• XOR
• NAND
• NOR
Purpose (Explanation) of NOT gate:
• It has one input
• Output will be 1 if the input is 0
• Output will be 0 if the input is 1
Purpose (Explanation) of AND gate:
• It has two inputs
• Output will be 1 if both inputs are 1
• Output will be 0 if either input is 0
Purpose (Explanation) of OR gate:
• It has two inputs
• Output will be 1 if either input is 1
• Output will be 0 if both inputs are 0
126
Definitions Eng. Omar El Safty
Purpose (Explanation) of XOR gate:
• It has two inputs
• Output will be 1 if both inputs are different
• Output will be 0 if both inputs are 0
• Output will be 0 if both inputs are 1
Purpose (Explanation) of NAND gate:
• It has two inputs
• Output will be 1 if either input is 0
• Output will be 0 if both inputs are 1
Purpose (Explanation) of NOR gate:
• It has two inputs
• Output will be 1 if both inputs are 0
• Output will be 0 if either input is 1
57. Logic circuit
Definition:
A combination of logic gates to carry out a particular function
58. Truth Table
Definition and purpose:
A table is used to trace the output from a logic gate or a logic circuit considering all
possible combinations of 0s and 1s that can be input.
127