0% found this document useful (0 votes)
8 views

Christmas Term - JS 2 ICT - Week 6-7 - Computer Programming Language II

computer programming
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Christmas Term - JS 2 ICT - Week 6-7 - Computer Programming Language II

computer programming
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Lesson Outlines:

Students should be able to:


 Define a program
 Define algorithm and flowchart
 State the functions of an algorithm
 State and describe the characteristics of algorithm
 List flow chart symbols
 State what each symbol stands for
 Use algorithm to solve programming problem
 Use flowchart to solve programming problems by showing the steps involved
A program is a sequence of instructions given to the computer to perform a
specific function.

Program Program is also called a software

Someone who writes a program for the computer is called a Programmer


 Planning of the house
 Designing a building plan
An algorithm is a sequence of steps designed to perform a particular task.

Computers are not intelligent enough to do things by itself - it is only capable


of doing what we tell it.

Algorithms
The idea of an algorithm is to describe exactly how to do something so that
any person (or computer!) can do it without
understanding how the person who wrote it was thinking.
They are usually written in any human language and some mathematical
notations.
Example:
 An algorithm to find the average of four numbers:

 start
 Step 1 – enter the first number; N1
 Step 2 – enter the second number; N2
 Step 3 – enter the third number; N3
 Step 4 – enter the fourth number; N4
 Step 5 - calculate the total (N1+N2+N3+N4); N5
 Step 6 – calculate the average (N5/4); N6
 Step 7 – print average (N6)
 Step 8 – end
In computing, algorithms are usually represented as a;
 program flowchart or
 in pseudo-code.

Program Flowchart (Flow and Chart)


A program flowchart is a pictorial/graphical representation of the steps
involved in an algorithm.
They use special symbols:
1.Precise − Algorithm should be clear and unambiguous. Each of its steps (or
phases), and their inputs/outputs should be clear and must lead to only one
meaning.
2.Input − An algorithm should have 0 or more well-defined inputs.
3.Output − An algorithm should have 1 or more well-defined outputs, and
should match the desired output.
4.Finiteness − Algorithms must terminate after a finite number of
steps/instructions are executed.
5.Feasibility − Should be feasible with the available resources.
6.Independent − An algorithm should have step-by-step directions, which
should be independent of any programming code.
 Uniqueness – results of each step are uniquely defined and only depend
on the input and the result of the preceding steps.
 Generality – the algorithm applies to a set of inputs.
Also, the characteristics of a good algorithm are:

 Use the internet and to go to “Google maps” (http://maps.google.com/) and


get driving directions from your home to Dowen College Lekki, Lagos.
 Explain how the algorithm for driving directions meet the algorithmic criteria of
precision, uniqueness, finiteness, input, output, and generality
1. Define a program 2
2. State four characteristics of a program 4
JS 2C
assignment 3. List the steps involved in program development 6
4. State the meaning of the terms
 source code, 2
 object code and state the process that connects them. 2
5. Define algorithm and flowchart. 4
Over
Evaluation 6. List flow chart symbols.
34
7

7. State what each symbol stands for. 7

1. A diagram that is used to represent an algorithm is called a/an (a) entity


relationship diagram (b) organogram chart. (c) program flow chart (d)
sequence flow chart (e) system flow chart
2. A set of instructions that describes the steps to be followed in order to carry
out an activity is called (a) Algorithm (b) Code (c) Flowchart (d) Guideline
(e) Program
Same as Week 6’s Lesson objectives
Examples of  Draw a flowchart to add
flowcharts two numbers together
Examples of  Draw a flowchart to compute
the area of a rectangle given
flowcharts length =15 and breath =10
 Draw a flowchart to determine who passed or failed a test given
the pass mark to be above 60

Examples of
flowcharts
Examples of  Here is a simple flowchart
flowcharts used in showing a simple
summation process
 This flowchart shows doing
a homework by a student
 This flowchart shows how
profit and loss can be
calculated
 Example 1. Design an algorithm and the corresponding flowchart for
adding the test scores as given below:

26, 49, 98, 87, 62, 75

 a) Algorithm

1. Start

2. Sum = 0

3. Get the first testscore

4. Add first testscore to sum

5. Get the second testscore

Evaluation …
6. Add to sum

7. Get the third testscore

8. Add to sum

9. Get the Forth testscore

10. Add to sum

11. Get the fifth testscore

12. Add to sum

13. Get the sixth testscore

14. Add to sum

15. Output the sum

16. Stop
Example 2: The problem with this
algorithm is that, some of the steps
appear more than once, i.e. step 5 get
second number, step 7, get third number,
etc. One could shorten the algorithm or
flowchart as follows:
1. Start

Evaluation … 2.
3.
Sum = 0
Get a value
4. sum = sum + value
5. Go to step 3 to get next Value
6. Output the sum
7. Stop
 Create a flowchart to add 10 and
20 and print out the sum

STEPS
Evaluation …  Initialise sum = 0 (process)
 Enter the numbers (I/O)
 Add them and store the result in sum
(process)
 Print sum (I/O)
 Create a flowchart to find
the sum of 5 numbers

STEPS
 Initialise sum = 0 and count =
0 (process)
 Enter n (I/O)
Evaluation …  Find sum + n and assign it to
sum and then increment count
by 1 (process)
 Is count < 5 (decision)
 If yes go to step 2
Else
 Print sum (I/O)
 Create a flowchart to log in to
facebook account

STEPS
 Enter www.facebook.com in browser
(I/O)
 Facebook homepage loads (process)

Evaluation …  Enter email ID and password (I/O)


 Is email ID and password valid/correct?
(decision)
 If no then log in error (process)
 Go to step 3
 Else
 Display facebook account (I/O)
 Stop
1. Design an algorithm and the corresponding flowchart for finding the sum
of the numbers 2, 4, 6, 8, …, n
2. Using flowcharts, write an algorithm to read 100 numbers and then
More display the sum.
3. Write an algorithm to read two numbers then display the largest.
Exercises 4. Write an algorithm to read two numbers then display the smallest
5. Write an algorithm to read three numbers then display the largest.
6. Write an algorithm to read 100 numbers then display the largest.

You might also like