# Chapter 7: The Program Development Life Cycle and Computer Systems
## 7.1 The Program Development Life Cycle
The program development life cycle is divided into five stages:
- Analysis
- Design
- Coding
- Testing
- Maintenance
This chapter and Chapter 8 will discuss the first four stages: analysis, design,
coding, and testing.
### 7.1.1 Analysis
Before any problem can be solved, it needs to be defined and set out so anyone
working on the solution understands what is needed. This is called the
‘requirements specification’ for the program.
- **Abstraction**: Keeps the key elements required for the solution to the problem
and discards any unnecessary details and information.
- **Decomposition**: Breaks down a complex problem into smaller parts, which can
then be subdivided into even smaller parts that can be solved easily.
### 7.1.2 Design
The program specification from the analysis stage is used to show how the program
should be developed. When the design stage is complete, the programmer should know:
- What is to be done (all the tasks that need to be completed).
- How each task is to be performed.
- How the tasks work together.
This can be documented using:
- Structure charts
- Flowcharts
- Pseudocode
### 7.1.3 Coding and Iterative Testing
The program or set of programs is developed. Each module of the program is written
using a suitable programming language and then tested to see if it works.
- **Iterative testing**: Tests are repeated until the module performs as required.
### 7.1.4 Testing
The completed program or set of programs is run many times with different sets of
test data to ensure that all the tasks completed work together as specified in the
program design.
## 7.2 Computer Systems, Sub-systems, and Decomposition
A computer system is made up of software, data, hardware, communications, and
people. Each computer system can be divided into a set of sub-systems.
### 7.2.1 The Computer System and Its Sub-systems
To understand how a computer system is built and how it works, it is often divided
into sub-systems. This division can be shown using top-down design to produce
structure diagrams.
- **Top-down design**: Decomposition of a computer system into a set of sub-
systems, then breaking each sub-system down into smaller sub-systems until each
sub-system performs a single action.
- **Stepwise refinement**: The process of breaking down into smaller sub-systems.
### 7.2.2 Decomposing a Problem
The component parts of any computer system are:
- Inputs
- Process
- Outputs
- Storage
### 7.2.3 Methods Used to Design and Construct a Solution to a Problem
The following methods are used by IGCSE Computer Science students:
- Structure diagrams
- Flowcharts
- Pseudocode
#### Structure Diagrams
Structure diagrams can be used to show top-down design. They illustrate how a
computer system solution can be divided into sub-systems, with each level giving a
more detailed breakdown.
#### Flowcharts
A flowchart shows the steps required to complete a task and the order in which they
are to be performed. These steps, together with the order, are called an algorithm.
- **Flowchart Symbols**:
- **Begin/End**: Terminator symbols are used at the beginning and end of each
flowchart.
- **Process**: Shows actions, such as when values are assigned to variables.
- **Input and Output**: Shows the input of data and output of information.
- **Decision**: Used to decide which action is to be taken next.
- **Flow Lines**: Use arrows to show the direction of flow.
#### Pseudocode
Pseudocode is a simple method of showing an algorithm using English keywords
similar to those used in high-level programming languages.
- **Assignment Statements**: A value is assigned to an item/variable using the `<--
` operator.
- **Conditional Statements**: Used to decide which action should be taken based on
the values of variables.
- **IF ... THEN ... ELSE ... ENDIF**: The THEN path is followed if the condition
is true, and the ELSE path is followed if the condition is false.
- **CASE OF ... OTHERWISE ... ENDCASE**: The value of the variable decides the
path to be taken.
#### Iteration
Loop structures are used to perform iteration:
- **FOR ... TO ... NEXT**: A set number of repetitions.
- **REPEAT ... UNTIL**: A repetition completed at least once.
- **WHILE ... DO ... ENDWHILE**: A repetition that may never be completed.
### Examples of Algorithms
#### Example 1: Adding Two Numbers
**Pseudocode:**
```
DECLARE N1 : INTEGER
DECLARE N2 : INTEGER
DECLARE Sum : INTEGER
OUTPUT "Enter the first number"
INPUT N1
OUTPUT "Enter the second number"
INPUT N2
Sum <-- N1 + N2
OUTPUT "Sum = ", Sum
```
#### Example 2: Finding the Area of a Rectangle
**Pseudocode:**
```
DECLARE Length : INTEGER
DECLARE Width : INTEGER
DECLARE Area : INTEGER
OUTPUT "Enter the length"
INPUT Length
OUTPUT "Enter the width"
INPUT Width
Area <-- Length * Width
OUTPUT "Area = ", Area
```
#### Example 3: Checking if a Number is Positive or Negative
**Pseudocode:**
```
DECLARE Num : INTEGER
OUTPUT "Enter a number"
INPUT Num
IF Num >= 0
THEN
OUTPUT "positive"
ELSE
OUTPUT "negative"
ENDIF
```
#### Example 4: Finding the Greater of Two Numbers
**Pseudocode:**
```
DECLARE A : INTEGER
DECLARE B : INTEGER
OUTPUT "Enter the first number"
INPUT A
OUTPUT "Enter the second number"
INPUT B
IF A > B
THEN
OUTPUT "the greater number is ", A
ELSE
OUTPUT "the greater number is ", B
ENDIF
```
#### Example 5: Determining a Student's Final Grade
**Pseudocode:**
```
DECLARE Mark : INTEGER
OUTPUT "Enter a number"
INPUT Mark
IF Mark >= 50
THEN
OUTPUT "Pass"
ELSE
OUTPUT "Fail"
ENDIF
```
#### Example 6: Calculating the Value of F
**Pseudocode:**
```
DECLARE X : INTEGER
DECLARE F : INTEGER
OUTPUT "Enter a number"
INPUT X
IF X >= 0
THEN
F <-- X
ELSE
F <-- -1 * X
ENDIF
OUTPUT F
```
#### Example 7: Printing Numbers from 1 to 10
**Pseudocode:**
```
DECLARE N : INTEGER
FOR N <-- 1 TO 10
OUTPUT N
NEXT N
```
#### Example 8: Entering Five Different Types of Animals
**Pseudocode:**
```
DECLARE Name : STRING
FOR S <-- 1 TO 5
OUTPUT "Enter the animal's name"
INPUT Name
OUTPUT "THE ", S, "animal in the zoo ", Name
NEXT S
```
#### Example 9: Finding the Sum of Numbers from 1 to 10
**Pseudocode:**
```
DECLARE SUM : INTEGER
DECLARE A : INTEGER
SUM <-- 0
FOR A <-- 1 TO 10
SUM <-- SUM + A
NEXT A
OUTPUT SUM
```
#### Example 10: Outputting Numbers Between 1 and 7
**Pseudocode:**
```
DECLARE A : INTEGER
FOR A <-- 1 TO 7
OUTPUT A
NEXT A
```
#### Example 11: Outputting Numbers Between 30 and 50
**Pseudocode:**
```
DECLARE A : INTEGER
FOR A <-- 30 TO 50
OUTPUT A
NEXT A
```
## Conclusion
The program development life cycle and the use of structure diagrams, flowcharts,
and pseudocode are essential tools in computer science for designing and
constructing solutions to problems. These tools help in breaking down complex
problems into manageable parts and in clearly communicating the steps required to
solve them.