Computer Section 2 Notes (Igcse)
Computer Section 2 Notes (Igcse)
Chapter 7
A series of steps or phases that software goes through from its initiation to completion. The
cycle is divided into 4 phases -
1) Analysis
A process of investigation, leading to the specification of what the program is required to do. It
uses abstraction and decomposition tools.
- Abstraction: the key elements required for the solution of the program are kept and any
unnecessary details and information that are not required is discarded.
- Decomposition: a complex problem is broken down into smaller parts, which can then be
subdivided into even smaller parts. That can be solved more easily.
2) Design
Uses the program specification from the analysis stage to show how the program should be
developed.
3) Coding
The writing of a program or suit of programs.
4) Testing
Systematic checks done on a program to make sure it works under all conditions.
A computer system is made up of software, data, hardware, communications and people; each
computer system can be divided up into a set of sub-systems.
Each sub-system can be further divided into sub-systems and so on until each sub-system just
performs a single action.
» inputs - the data used by the system that needs to be entered while the system is active
» processes - the tasks that need to be performed using the input data and any other
previously stored data
» outputs - information that needs to be displayed or printed for the users of the system
» storage - data that needs to be stored in files on an appropriate medium for use in the
future.
● Flowcharts: shows diagrammatically the steps required to complete a task and the order
that they are to be performed. These steps, together with the order, are called an
algorithm. standard flowchart symbols include -
Advantages
- It is similar to normal program code, so can be converted into program easily.
- It doesn’t require any special graphics software
- Is good to use when program is very lengthy
- Can be written quickly
- Takes up less space than Flowchart
- Can be easily edited. Easy to rewrite any part of it.
Disadvantages
- More technical than flowchart
- Can be harder to understand than flowchart.
The pseudocode for conditional statements
1) IF…THEN…ELSE…END IF
For an IF condition the THEN path is followed if the condition is true and the
ELSE path is followed if the condition is false. There may or may not be an ELSE path. The end
of the statement is shown by ENDIF.
IF Condition A
THEN
PRINT “true”
ELSE
PRINT “false”
END IF
>> Nested IF
CASE Of Choice
1: Condition A
2: Condition B
3: Condition C
OTHERWISE PRINT “…”
END CASE
Counter <- 0
WHILE Counter < 10 DO
PRINT “…”
Counter <- Counter + 1
ENDWHILE
Counter <- 0
REPEAT
PRINT “…”
Counter <- Counter + 1
UNTIL Counter > 9
7.3 Explaining the purpose of an algorithm
An algorithm sets out the steps to complete a given task. This is usually shown as a flowchart or
pseudocode, so that the purpose of the task and the processes needed to complete it are clear
to those who study it.
● Totalling
Total <- 0
FOR Counter <- 1 TO 10
INPUT X
Total <- Total + X
NEXT Counter
PRINT Total
● Counting
Count <- 0
FOR Counter <- 1 TO 10
IF Condition A
THEN
Count <- Count + 1
END IF
NEXT Counter
PRINT Count
● Maximum
(In maximum, store the minimum value)
Maximum <- 0
FOR Counter <- 1 TO 10
INPUT X
IF X > Maximum
THEN
Maximum <- X
END IF
NEXT Counter
PRINT Maximum
● Minimum
(In minimum, store the maximum value)
Minimum <- 0
FOR Counter <- 1 TO 10
INPUT X
IF X < Minimum
THEN
Minimum <- X
END IF
NEXT Counter
PRINT Minimum
● Linear Search
(Inspects each time in a list in turn to see if the item matches the value searched for)
INPUT N
COUNT <- 0
FOR I <- 1 TO 10
IF N = [value to be searched for]
THEN
COUNT <- COUNT + 1
END IF
NEXT I
IF COUNT > 1
THEN
PRINT “present”
ELSE
PRINT “not present”
END IF
● Bubble Sort
(Sorts items in a more meaningful order)
FOR I <- 1 TO N
FOR J <- 1 TO N - I
IF A[J] > A[J+1]
X <- A[J]
A[J] <- A[J+1]
A[J+1] <- X
END IF
NEXT J
NEXT I
7.5 Validation and Verification
Validation
The automated checking by a program that the data is reasonable before it is entered
1) Range Check
checks that the value of a number is between an upper value and a lower value
REPEAT
INPUT X
IF X < 0 OR X > 100
THEN
PRINT “value is out of range, please re-enter”
END IF
UNTIL X >= 0 OR X <= 0
2) Length Check
checks that the data entered contains an exact number of characters or a reasonable number of
characters
REPEAT
INPUT X
IF LENGTH(X) < 1 OR LENGTH(X) > 10
THEN
PRINT “value too short or too long, please re-enter”
END IF
UNTIL LENGTH(X) >= 1 OR LENGTH(X) <= 10
3) Type Check
checks whether the data entered if of a specific data type
REPEAT
INPUT X
IF X <> DIV(X,1)
THEN
PRINT “please enter a whole number”
END IF
UNTIL X = DIV(X,1)
4) Presence Check
checks to ensure some data has been entered and the value has not been left blank
Example:
REPEAT
INPUT X
IF X = “”
THEN
PRINT “please enter a value”
END IF
UNTIL X <> “”
5) Format Check
checks that the characters entered conform to a predefined pattern
INPUT X
IF LENGTH(X) = 7
THEN
IF IS_APLHABETIC(SUBSTRING(X,1,3)) AND IS_NUMERIC(SUBSTRING(X,4,7))
THEN
PRINT “valid”
ELSE
PRINT “invalid format, please re-enter”
END IF
ELSE
PRINT “please enter a 7-digit value”
END IF
6) Check Digit
Verification
Checks that the data has been accurately copied from one source to another
1) Double Entry
Data is entered twice, sometimes by different operators. The computer system compares both
entries and if they are different outputs an error message requesting that the data should be
entered again
2) Screen/Visul Check
A manual check completed by the user who is entering the data. When data is entry is complete
the data is displayed on the screen and the user is asked to confirm that it is correct before
continuing.
3) Proofreading
A user enters the data. Another user reads it to confirm that the data entered is correct.
A set of test data is all the items of data required to work through a solution.
1) Normal Data
Normal data should be used to work through the solution to find the actual results) and see if
they are the same as the expected result (s).
2) Abnormal Data
Test data should be chosen that would be rejected by the solution as not suitable, if the solution
is working properly.
3) Extreme Data
The largest and smallest values that normal data can take.
4) Boundary Data
At each boundary two values are required: one value is accepted and the other value is
rejected.
A trace table can be used to record the results from each step in an algorithm; it is used to
record the value of an item (variable) each time that it changes. The manual exercise of working
through an algorithm step by step is called a dry run.
Trace tables and test data can be used to identify and correct errors.
There are a number of stages when producing an algorithm for a given problem:
1) Make sure that the problem is clearly specified - the purpose of the algorithm and the
tasks to be completed by the algorithm.
2) Break the problem down into sub-problems; if it is complex, you may want to consider
writing an algorithm for each sub-problem.
3) Decide on how any data is to be obtained and stored, what is going to happen to the
data and how any results are going to be displayed
5) Decide on how you are going to construct your algorithm, either using a flowchart or
pseudocode.
6) Construct your algorithm, making sure that it can be easily read and understood by
someone else.
7) Use several sets of test data (Normal, Abnormal and Boundary) to dry run your
algorithm and show the results in trace tables, to enable you to find any errors.
8) If any errors are found, correct them and repeat the process until you think that your
algorithm works perfectly.
Chapter 8
Constructs of 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
● Operators use arithmetic for calculations and logic and Boolean for decisions.
● Variables - A variable in a computer program is a named data store that contains a value
that may change during the execution of a program.
● integer - a positive or negative whole number that can be used with mathematical
operators
● real - a positive or negative number with a fractional part. Real numbers can be used
with mathematical operators
● string - a variable or constant that is several characters in length. Strings vary in length
and may even have no characters (known as an empty string); the characters can be
letters and/or digits and/or any other printable symbol (If a number is stored as a string
then it cannot be used in calculations.)
● Boolean - a variable or constant that can have only two values TRUE or FALSE.
1. Variable Declaration:
To declare a variable in pseudocode, you typically use a keyword like DECLARE followed by the
variable name. Example:
2. Constant Declaration:
In pseudocode, constants are often declared using a keyword like CONSTANT followed by the
constant name and its value. Example:
Sequence
The order in which the steps of a program are executed
Selection
Allowing selection of different paths through the steps of a program.
Iteration
A section of program code that can repeat itself under certain conditions
Counting
Keeping tract of the number of terms an action is performed
Totalling
Keeping a total that values are added to
String handling
Operators
A special character or word in a programming language that identifies an action to be
performed
● Arithmetic Operator - an operator used to perform calculations
Operator Action
+ add
- subtract
* multiply
/ divide
● Logical Operator - an operator used to decide the path to take through. Program
if the expression formed is true or false
Operator Action
= equal to
● Boolean Operator - an operator that is used with logical operators to form more
complex expressions
Operator Action
AND both ture
OR either true
Nesting
The inclusion of one type of code construct inside another
When writing an algorithm, there are often similar tasks to perform that make use of the
same groups of statements. Instead of repeating these statements and writing new
code every time they are required, many programming languages make use of
subroutines, also known as named procedures or functions. These are defined once
and can be called many times within a program.
Parameters are the variables that store the values of the arguments passed to a
procedure or function. Some but not all procedures and functions will have parameters.
● Procedures
CALL ProcudureName
- Here is an example of a procedure without parameters in pseudocode:
PROCEDURE Stars
PRINT “*******”
ENDPROCEDURE
- The procedure can be called in the main part of the program as many times as it
is required in the following way:
CALL Stars
- The procedure with parameters are called like this: (assuming we want to print 7
stars)
CALL Stars(7)
● Functions
- To call a function in the main program we can assign the return value into a
variable :
Temp <- Celsius(Temp)
When procedures and functions are defined, the first statement in the definition is a
header, which contains:
» the name of the procedure or function
» any parameters passed to the procedure or function, and their data type
» the data type of the return value for a function.
A global variable can be used by any part of a program - its scope covers the whole
program.
A local variable can only be used by the part of the program it has been declared in - its
scope is restricted to that part of the program.
Library Routines
- Programming language development systems often provide library routines that can be
readily incorporated into programs.
- Library routines are pre-tested and ready for use, making programming tasks easier.
- Integrated Development Environments (IDEs) typically include a standard library of
functions and procedures.
- Standard library routines perform various tasks, including string handling.
8.2 Arrays
An array is a data structure containing several elements of the same data type; these elements
can be accessed using the same identifier name.The position of each element in an array is
identified using the array’s index.
Example:
DECLARE VariableName : ARRAY[1:NumberOfRows] OF DataType
Example:
DECLARE VariableName : ARRAY[1:NumberOfRows, 1:NumberOfColumns] OF DataTya
Note: When using a 2-D array with loop structures, there needs to be two loops, one for each
index.
computer programs store data that will be required again in a file. While any data stored in RAM
will be lost when the computer is switched off, when data is saved to a file it is stored
permanently. Data stored in a file can thus be accessed by the same program at a later date or
accessed by another program. Data stored in a file can also be sent to be used on other
computer(s).
using files
1) read
Read data from the file
Syntax-
OPEN <file name> FOR <file mode>
READ <variable>
CLOSEFILE <file name>
Example -
FOR I <- 1 TO 10
OPENFILE “file.txt” FOR READ
X <- file.txt
READ X
NEXT I
CLOSE FILE “file.txt”
NOTE: ‘CLOSEFILE’ statement using FOR..TO.. NEXT Loop can only be used when we know
the number of elements. If the number of elements is unknown we use the statement ‘EOF’
which stands for End Of File using a REPEAT…UNTIL Loop.
Example-
REPEAT
OPENFILE “file.txt” FOR READ
X <- file.txt
READ X
UNTIL EOF “file.txt”
2) Write
writes data to the file, any existing data stored in the file will be overwritten.
Syntax-
OPEN <file name> FOR <file mode>
WRITE <variable>
CLOSEFILE <file name>
Example -
FOR I <- 1 TO 10
OPENFILE “file.txt” FOR WRITE
X <- file.txt
WRITE X
NEXT I
CLOSE FILE “file.txt”
Here are examples of writing a line of text to a file and reading the line of text back from the file.
The pseudocode algorithm has comments to explain each stage of the task.
Chapter 9
9.1 databases
A database is a structured collection of data that allows people to extract information in a way
that meets their needs. That data can include text , numbers, pictures and anything that can be
stored in a computer. A single database contains only one table
the number of records in a database may vary as new records can be added and deleted from a
table as required. The number of fields in a database is fixed so each record contains the same
number of fields.
Validation in databases
● Database management software automatically provides some validation checks,
while others need to be set up by the developer during construction.
A data type classifies how the data is stored, displayed and the operations that can be
performed on the stored value.
Primary Key
A field in a database that uniquely identifies a record. It does not contain any duplicate data.
Counting the number of records where the field matches a specified condition
SELECT COUNT ( fieldsname )
FROM (tablesname)
WHERE (condition)
ORDER BY (sortingcondition) ;
=> ORDER BY Field1, Field2, etc. – this specifies a sort in ascending or alphabetical
order starting with the first field.
=> ORDER BY Field1, Field2 DESC – this specifies a sort in descending or reverse
alphabetical order starting with the first field.
Truth Tables
Truth tables are used to trace the output from a logic gate or logic circuit. The NOT gate is the
only logic gate with one input; the other five gates have two inputs.
Although, each logic gate can only have two inputs, logic circuit can have two or more inputs.
10.2 The function of the six logic gates
10.3 logic circuits,logic expressions, truth tables and problem
statements
● Problem Statement
can be used to create a logic expression, logic circuit and a truth table
● Logic or Boolean Expression
can be used to create logic circuit and complete a truth complete
● Truth Table
can be used to create a logic expression and logic circuit
● Logic Circuit
can be used to create a Boolean expression and truth table
This logic expression can be used to create a truth table as shown above