Computer Programming I - SSS 2 Note

Computer Programming I - SSS 2 | CMPNOTE

COMPUTER PROGRAMMING I

Subject: Digital Technologies
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:

  1. Define an algorithm.
  2. Explain the importance of algorithms in problem-solving and programming.
  3. Identify the characteristics of a good algorithm.
  4. Explain the meaning of a flowchart.
  5. Identify common flowchart symbols and state their uses.
  6. 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.

Key idea: An algorithm provides a step-by-step solution to a problem, while a flowchart represents those steps using diagrams and standard symbols.
From problem to result: Problem, Algorithm, Flowchart, Program, Result Problem Algorithm Flowchart Program Result
Figure 1: Planning a solution before writing a computer program.

2. Meaning of an Algorithm

Algorithm is a finite sequence of clear and well-defined steps used to solve a problem or perform a particular task.

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:

  1. Get a cup, tea bag, water and other required ingredients.
  2. Boil the water.
  3. Place the tea bag in the cup.
  4. Pour the hot water into the cup.
  5. Allow the tea to steep.
  6. Add milk or sugar if required.
  7. Remove the tea bag and serve.

These ordered instructions form an algorithm for preparing the tea.

Seven steps for making a cup of tea shown in order ๐Ÿ›’ 1. Get items ♨️ 2. Boil water ๐Ÿต 3. Add tea bag ๐Ÿšฐ 4. Pour water ⏳ 5. Let it steep ๐Ÿฅ› 6. Milk / sugar ☕ 7. Serve
Figure 2: The steps for making tea must be followed in the correct order, just like an algorithm.

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.
Remember: A good algorithm should be clear, definite, finite and logically ordered, and it should lead to the required result.
An algorithm takes input, processes it and produces output INPUT PROCESS OUTPUT The algorithm (finite, clear, ordered)
Figure 3: A good algorithm identifies its input, processes it in clear steps and gives an output.

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

  1. Start.
  2. Enter the first number.
  3. Enter the second number.
  4. Add the first number and the second number.
  5. Display the answer.
  6. Stop.

The algorithm above describes the logical steps required to add two numbers.

Example: Algorithm for Finding the Larger of Two Numbers

  1. Start.
  2. Enter the first number.
  3. Enter the second number.
  4. Compare the two numbers.
  5. If the first number is larger, display the first number.
  6. Otherwise, display the second number.
  7. Stop.

6. Introduction to Flowcharts

Flowchart is a graphical representation of an algorithm or process using standard symbols connected by arrows.

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.

The six common flowchart symbols: terminator, process, decision, input/output, flow line and connector START / STOP Terminator Beginning or end Add A and B Process Operation or instruction Yes / No? Decision Condition or choice Enter / Display Input / Output Data in or information out Flow Line Direction of the process A Connector Joins parts of a flowchart
Figure 4: The six common flowchart symbols and what each one means.
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.

Two terminator symbols labelled START and STOP START STOP
Figure 5: Terminator symbols.

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.

A process symbol containing the text Add A and B Add A and B
Figure 6: Process symbol.

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.

A decision symbol asking Is the number greater than 10, with Yes and No paths Is the number greater than 10? Yes Yes-path step No No-path step
Figure 7: A decision symbol has one way in and two ways out (Yes and No).

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.
Input and output symbols: Enter two numbers, Display the total Enter two numbers Display the total
Figure 8: Input/Output symbols (parallelograms).

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:

Flowchart for adding two numbers: Start, enter first number, enter second number, add, display answer, Stop START Enter first number Enter second number Add the two numbers Display the answer STOP
Figure 9: Flowchart for adding two numbers.

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.

Flowchart for finding the larger of two numbers using a decision symbol START Enter first number Enter second number Is the first number larger? Yes No Display first number Display second number STOP
Figure 10: Flowchart with a decision symbol. The two paths join again before STOP.

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.
Important: A flowchart is not simply a collection of shapes. The symbols must be connected logically so that a reader can follow the complete process from the beginning to the end.

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.

  1. Write an algorithm for the problem.
  2. Identify the input required.
  3. Identify the decision that must be made.
  4. Identify the possible outputs.
  5. 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

  1. What is an algorithm?
  2. State five characteristics of a good algorithm.
  3. Give three reasons why algorithms are important in programming.
  4. What is a flowchart?
  5. State five common flowchart symbols and their uses.
  6. What is the purpose of a decision symbol?
  7. What does a flow line represent in a flowchart?
  8. State two differences between an algorithm and a flowchart.

16. Assignment

  1. Write an algorithm for finding the sum of three numbers.
  2. Draw a flowchart representing the algorithm.
  3. 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.

1. What is an algorithm?

2. Which characteristic means that an algorithm must eventually end?

3. Why are algorithms useful in programming?

4. What is a flowchart?

5. Which symbol represents a decision in a flowchart?

6. What does the process symbol normally represent?

7. Which symbol is commonly used for input and output?

8. What is the purpose of arrows in a flowchart?

9. Which of the following is a characteristic of a good algorithm?

10. Which statement correctly compares an algorithm and a flowchart?

Comments

Popular posts from this blog

Complete Computer Studies/ICT Curriculum for JSS 1 to SSS 3

90 Objective Examination Questions in Major Subjects

Number Base System