Computer Programming I - SSS 2 Note
COMPUTER PROGRAMMING I
Class: SSS 2
Term: Second Term
Week: 1
Topic: Computer Programming I
Duration: 80 Minutes (Double Period)
Learning Objectives
By the end of the lesson, students should be able to:
- Define an algorithm.
- Explain the importance of algorithms in problem-solving and programming.
- Identify the characteristics of a good algorithm.
- Explain the meaning of a flowchart.
- Identify common flowchart symbols and state their uses.
- Draw a simple flowchart for a familiar problem.
1. Introduction to Computer Programming
Computer programming is the process of designing and writing instructions that a computer can follow to perform a particular task or solve a problem.
Before writing instructions in a programming language, it is often useful to first understand the problem and plan the steps required to solve it. Two common tools used for planning solutions are algorithms and flowcharts.
2. Meaning of an Algorithm
An algorithm gives instructions in the correct order. It starts with a problem or task and provides a logical series of steps that leads to a desired result.
Algorithms are not limited to computers. People use step-by-step procedures in everyday activities such as preparing food, operating a device, solving mathematical problems and following directions.
Example of an Everyday Algorithm
Consider the task of making a cup of tea:
- Get a cup, tea bag, water and other required ingredients.
- Boil the water.
- Place the tea bag in the cup.
- Pour the hot water into the cup.
- Allow the tea to steep.
- Add milk or sugar if required.
- Remove the tea bag and serve.
These ordered instructions form an algorithm for preparing the tea.
3. Importance of Algorithms
Algorithms are important in programming and problem-solving because they:
- Provide a clear plan for solving a problem.
- Arrange instructions in the correct order.
- Make complex problems easier to understand.
- Help programmers identify errors before writing code.
- Make it easier to convert a solution into a programming language.
- Help different people understand the same solution.
- Can be used as a basis for creating flowcharts and computer programs.
4. Characteristics of a Good Algorithm
A good algorithm should have certain important characteristics.
| Characteristic | Explanation |
|---|---|
| Clear | Each instruction should be easy to understand and should not create unnecessary confusion. |
| Definite | Each step should have a specific meaning and should produce a clear action. |
| Finite | The algorithm must eventually come to an end after a limited number of steps. |
| Ordered | The instructions should be arranged in a logical sequence. |
| Effective | The steps should be practical and capable of producing the required result. |
| Input | Where necessary, an algorithm should identify the information or data required to solve the problem. |
| Output | The algorithm should produce a useful result or outcome. |
5. Writing an Algorithm
An algorithm can be written using simple statements. Programming syntax is not required when writing a basic algorithm.
Example: Algorithm for Adding Two Numbers
- Start.
- Enter the first number.
- Enter the second number.
- Add the first number and the second number.
- Display the answer.
- Stop.
The algorithm above describes the logical steps required to add two numbers.
Example: Algorithm for Finding the Larger of Two Numbers
- Start.
- Enter the first number.
- Enter the second number.
- Compare the two numbers.
- If the first number is larger, display the first number.
- Otherwise, display the second number.
- Stop.
6. Introduction to Flowcharts
A flowchart presents the steps of a solution visually. Instead of writing all instructions as sentences, the programmer uses symbols to represent activities such as starting, entering data, processing information, making decisions and displaying results.
Flowcharts are useful because they make the logical flow of a problem easier to see and understand.
7. Importance of Flowcharts
Flowcharts are useful in programming because they:
- Present the steps of a solution visually.
- Make algorithms easier to understand.
- Help programmers plan programs before writing code.
- Make errors or missing steps easier to identify.
- Help explain a program to other people.
- Provide documentation of how a process works.
8. Common Flowchart Symbols
Flowcharts use standard symbols. Each symbol has a particular meaning and function.
| Symbol | Name | Purpose |
|---|---|---|
| Terminator | Represents the beginning or end of a flowchart. | |
| Process | Represents an operation, calculation or instruction. | |
| Decision | Represents a condition where a choice must be made, usually producing Yes/No or True/False paths. | |
| Input/Output | Represents data entering the system or information being displayed. | |
| Flow Line | Shows the direction in which the process moves from one step to another. | |
| Connector | Connects different parts of a flowchart, especially when the diagram is large or continues elsewhere. |
9. The Main Flowchart Symbols in Detail
9.1 Terminator Symbol
The terminator is normally drawn as an oval or rounded shape. It indicates where a flowchart begins and where it ends.
It may contain words such as START and STOP.
9.2 Process Symbol
The process symbol is normally a rectangle. It represents an action or operation that must be performed.
For example, Add A and B can be represented as a process.
9.3 Decision Symbol
The decision symbol is normally a diamond. It represents a question or condition that determines which path the flowchart should follow.
For example:
Is the number greater than 10?
The answer may be Yes or No, with each answer leading to a different step.
9.4 Input/Output Symbol
The input/output symbol is normally drawn as a parallelogram. It represents information being entered into a system or information being displayed as output.
Examples include:
- Enter a student's score.
- Enter two numbers.
- Display the total.
- Print a student's result.
9.5 Flow Line
Flow lines are represented by arrows. They show the direction in which the process moves from one symbol to another.
10. Simple Flowchart Examples
10.1 Flowchart for Adding Two Numbers
The following flowchart shows the algorithm for adding two numbers from Section 5, drawn with the correct standard symbols:
10.2 Flowchart for Finding the Larger of Two Numbers
This flowchart uses a decision symbol because the program must choose between two paths. It matches the second algorithm in Section 5.
11. Algorithm and Flowchart: Difference
| Algorithm | Flowchart |
|---|---|
| Uses written steps to describe a solution. | Uses graphical symbols to represent a solution. |
| Usually easier to write quickly. | Can make the logical flow easier to visualise. |
| Instructions are presented as text. | Instructions are represented using symbols and arrows. |
| Can be converted into a flowchart. | Can be developed from an algorithm. |
12. Guidelines for Drawing a Good Flowchart
- Use standard flowchart symbols.
- Begin with a Start symbol and end with a Stop or End symbol.
- Arrange the steps in a logical order.
- Use arrows to show the direction of flow.
- Keep the diagram neat and easy to understand.
- Use clear and short statements inside symbols.
- Ensure decision paths are clearly labelled where necessary.
13. Class Activity
Activity: Create an Algorithm and Flowchart
Students should choose the problem of determining whether a student has passed or failed an examination.
- Write an algorithm for the problem.
- Identify the input required.
- Identify the decision that must be made.
- Identify the possible outputs.
- Draw a flowchart using the correct symbols.
For example, the decision may be: Is the student's score 50 or above?
14. Summary
- An algorithm is a finite sequence of clear steps for solving a problem or performing a task.
- Algorithms are useful for planning solutions before writing computer programs.
- A good algorithm should be clear, definite, finite, ordered and effective.
- A flowchart is a graphical representation of an algorithm.
- Flowcharts use standard symbols to represent different operations.
- The terminator represents the beginning or end of a flowchart.
- The process symbol represents an operation or instruction.
- The decision symbol represents a condition or choice.
- The input/output symbol represents data entering or leaving a system.
- Flow lines show the direction of the process.
15. Evaluation Questions
- What is an algorithm?
- State five characteristics of a good algorithm.
- Give three reasons why algorithms are important in programming.
- What is a flowchart?
- State five common flowchart symbols and their uses.
- What is the purpose of a decision symbol?
- What does a flow line represent in a flowchart?
- State two differences between an algorithm and a flowchart.
16. Assignment
- Write an algorithm for finding the sum of three numbers.
- Draw a flowchart representing the algorithm.
- Explain the purpose of the terminator, process, decision and input/output symbols.
17. Interactive Revision Quiz
Choose the correct answer for each question and click Mark Quiz to see your score.
Comments
Post a Comment