Jamaica Gleaner

Problem solving and program design

- NATALEE A. JOHNSON Contributo­r Natalee Johnson teaches at Ardenne High School. Send questions and comments to kerry-ann.hepburn@gleanerjm.com

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

In the previous lesson, you were introduced to the defining diagram and the column headings of the diagram. Let us now determine what goes into each column. A reminder of the table structure is shown below.

The input is the source data provided. You can identify what is the input in a given problem by the following keywords: given, get, read or accept.

THE OUTPUT

The output is the end result required. You can identify what is the output in a given problem by the following keywords: print, display and output.

THE PROCESSING

The processing column is a list of what actions are to be performed to achieve the required output.

Let us look first at a real-world scenario. You are learning to bake a cake for the first time. How would you represent this problem, using the defining diagram concept? See the example below.

DEFINING DIAGRAM:

Let us now look at computer-related problem. Example 1 A program is required to read two numbers, calculate and print their difference. Steps in drawing the defining diagram using the example above.

1. Identify the input (that is, the data that is given). The keyword, read, identifies the input as two numbers, that is, any two numbers.

2. Identify the output. The keyword, print, identifies the output as the difference of the two numbers.

3. List the processing steps. Here, we list all the actions that must be performed in order to get the desired results. For example: What do we have to do to the two numbers in order to print their difference? 1. We must first get the numbers. 2. We must then calculate their difference. 3. We must then print the difference. See the defining diagram below.

DEFINING DIAGRAM: KEY THINGS TO NOTE:

1. In the defining diagram, the actions must be in a logical sequential order.

2. All the necessary actions must be explicitly stated. For example, the read action and the print action must not be assumed.

3. The processing section is NOT the solution to the problem. It is simply a list of the things that must be done in order to solve the problem. Example 2 A program is required to read three numbers, calculate and print their product.

DEFINING DIAGRAM PRACTICE QUESTIONS

Use a defining diagram to answer the following: 1. A program is required to read the unit cost and quantity of an item. Calculate and print the total cost of the item.

2. A program is required to accept a number and to find the square of the number. The program should also output the square of the number.

PROGRAM DESIGN

When we are solving problems on the computer, this is done by representi­ng the most efficient solution as an algorithm. This can be done after you have constructe­d the defining diagram. Before we look at the term algorithm, there are some key terms you must first be familiar with: variables, constant and data types.

When you ask the computer to read two numbers, find the sum of the two numbers then output the sum. When the computer reads the two values, it has to store the values somewhere in memory. Similarly, it will have to store the value of sum somewhere in order to provide an output to you, the user. These values are normally stored in what we call variables.

1. A variable is a named location in memory that stores a particular value. This value may be changed during the execution of a program. Examples of variable names include: ‘number’, ‘age’, ‘name’, ‘length’, and so on. You can have several different names, numbers, ages, etc.

2. A constant provides locations for storing data which do not change value during execution of a program. For example, if you were calculatin­g the total price of an item which included general consumptio­n tax (GCT), which is, for example, 17.1 per cent. The 17.1 would be treated as a constant value in the calculatio­n.

We have come to the end of this lesson. See you next week when we will continue to look at problem solving and program design. Remember, if you fail to prepare, you prepare to fail.

 ??  ??
 ??  ??
 ??  ??
 ??  ??
 ??  ??

Newspapers in English

Newspapers from Jamaica