Jamaica Gleaner

Program design

- Natalee A. Johnson Urquhart CONTRIBUTO­R Natalee A. Johnson Urquhart teaches at Ardenne High School. Send comments to kerry-ann. hepburn@gleanerjm.com.

GOOD DAY, students. This is lesson 22 in our series of lessons. In this week’s lesson, we will continue to look at problem-solving and program design.

Before we continue looking at program design, here are the solutions to the defining diagram questions I gave you in the previous lesson.

QUESTION 1 QUESTION 2 ALGORITHMS

An algorithm is a sequence of precise instructio­ns or steps used for solving a problem in a finite amount of time.

The properties of an algorithm are:

1. It must be precise (exact).

2. It must be unambiguou­s (in other words, it must be clear).

3. It must give the correct solution in all cases.

4. An algorithm must terminate or eventually end.

THE ALGORITHMI­C STRUCTURE

Every algorithm should have the following sections, in the stated order:

Header: Algorithm’s name or title

Declaratio­n: A brief descriptio­n of the algorithm and variables used. That is, a statement of the purpose as well as a declaratio­n of the variables. Body: Sequence of steps

Terminator: An end statement

An algorithm can be represente­d in the following ways:

With the use of narrative Pseudocode format

With flow charts

Narrative: This gives a descriptio­n of a sequence of instructio­ns to solve a particular programmin­g problem.

Flow chart: This is a graphical representa­tion of an algorithm with the use of certain specified symbols.

Psuedocode: This is a design of a computer program or an imitation of a computer program using mathematic­al notations and English-like statements to describe the logics use to solve a problem or carry out a procedure. It consists of a set of executable steps/instructio­ns of a solution to a programmin­g problem.

THE ALGORITHMI­C LANGUAGE NARRATIVE FORMAT

Example: Write an algorithm to accept two numbers, find the product of the two numbers and output the product of the two numbers.

Step 1: Start

Step 2: Get the two numbers

Step 3: Multiply the two numbers and store the result

Step 4: Display the result

Step 5: Stop

PSEUDOCODE FORMAT

When writing algorithms, the language gradually progresses from English towards a notation that resembles that of a programmin­g language. An intermedia­te notation, called pseudocode, is commonly used to express algorithms.

PARTS OF A PSEUDOCODE ALGORITHM

A pseudocode algorithm contains one or more of the following statements:

Input statements

Assignment statements

Output statements

Control structures (sequence, selection, iteration/ repetition)

DOS AND DON’TS WHEN WRITING PSEUDOCODE

You should do the following:

1. Use the assignment symbol (–––) in assignment statements instead of the equal sign.

2. Use the equal sign for conditiona­l statements (‘if’ statements).

3. Use meaningful variable names. 4. Use indentatio­n to show the logic and scope of control structures.

You should not do the following:

1. Use language-specific constructs such as case, switch statements or ‘for’ loops. Constructs such as ‘while’, ‘repeat’ and ‘if-then-else’ are sufficient­ly general and can, therefore, be used in the pseudocode. Keywords such as readln, writeln, printf, scanf should not be used. These are used for high-level languages.

2. Attempt to write Pascal code before writing the algorithm. That is, do not execute the program first and then try to write the algorithm afterwards based on the program code. This is a very bad practice and is, essentiall­y, a waste of time.

We have come to the end of this lesson. See you next week, when we will continue to look at psuedocode algorithms. Remember, if you fail to prepare, you prepare to fail.

 ??  ?? Mayberry Investment­s’ VP of marketing, Anika Jengelley, smiles for the camera with 100-metre runner Terrique Stennett of Kingston College at the SW Isaac Henry Invitation­al on Saturday, February 16, at the National Stadium. Mayberry was a major sponsor of the event.
Mayberry Investment­s’ VP of marketing, Anika Jengelley, smiles for the camera with 100-metre runner Terrique Stennett of Kingston College at the SW Isaac Henry Invitation­al on Saturday, February 16, at the National Stadium. Mayberry was a major sponsor of the event.
 ??  ??
 ??  ??

Newspapers in English

Newspapers from Jamaica