Sei sulla pagina 1di 7

ICT1101 Programme Logic Formulation

Lesson

Lesson One: Introduction to Problem-Solving concepts


Objectives:
1.
2.
3.
4.

To understand the notation requirements in logic formulation


To understand the use of algorithms
To understand the concept of structured programming
List and describe the six problem-solving steps to solve a problem that
has an algorithm solution.

What is a program?
Program is a set of instructions or rules that solve a problem which is coded or
written using a particular computer language or programming language.
We use programming language to communicate with the computer, which can be
understood by both the user and the computer.
There are many programming languages available and basically programming
language is falls into two categories: High-level language and low-level
language.
Programming language said to be lower when it is close to the machine language.
High-level language is more English like.

Notation in Logic
What is a notation?
Notation is a system of figures or symbols used in a specialized filed to
represent numbers, quantities or values.
Each different language like C, Pascal and Java have their own unique
symbols (called syntax)
Wrongly using the symbols may lead to an error called syntax error

Page 1 of 7

ICT1101 Programme Logic Formulation

Lesson

To form a logic notation


For examples:
TOTAL is assigned the value of zero
Using the recommended notation, it can be rewritten as:
TOTAL = 0
- ADD 1 to COUNTER
COUNTER = COUNTER + 1

Patterns of Logic
The basic pattern in a program consists of 3 parts:
Beginning
Setting counters and total to an initial value
Obtaining initial values from an operator/user
Nominating files to be processed
Middle: usually involve in using any program structure
Obtaining data items to be processed from an operator/user or
from a file
Accessing a series of elements in a table
Accumulating totals and counters
End
To produce output
To close the files that have been processed
Algorithm Constructions
Any program will involve 3 steps of logic process:
Input : to accept the value from an operation at a terminal, or through
an initial expression. Keywords used like READ, INPUT and ENTER
Process: to perform process like calculation.
Output: to produce the result out on the terminal. Keywords like
PRINT, DISPLAY or OUTPUT.

Page 2 of 7

ICT1101 Programme Logic Formulation

Lesson

Example 1: construct an algorithm to find the sum of 3 numbers


READ a
READ b
READ c
Sum = a+b+c
DISPLAY Sum is , Sum
Program Logic Structures
Use the four logic structures:
The sequential structure - executes instruction one by one in sequence.
The decision structure - branches to execute one of two possible sets of
instructions.
The loop structure - executes a set of instruction many times.
The case structure - executes one set of instruction out of several sets.
Steps in problem solving
o It is important that people know how to make decisions well or otherwise time
and resource will be wasted. The six steps in problem solving, include the
following:
1. Identify the problem.
Any problem that given must be identified it before you can start solving it.
If you dont know what the problem is, you cannot solve it.
For example, a given assignment in the form of case studies.

2. Understand the problem.


This includes understanding the knowledge base of the person or machine for
whom you are solving the problem.
A different set of instructions might have to be used depending on this

Page 3 of 7

ICT1101 Programme Logic Formulation

Lesson

knowledge base.
For example, you must know what the case study is about? The knowledge
base cover in the case studies in order to find the resource.
3. Identify the alternative ways to solve the problem.
You might want to talk to other people to find other solutions than those you have
identified.
For example, you might have a discussion session with your classmates to identify
other ways of solving the problem of the case study or another resources needed in
completing the assignment.

4. Select the best way to solve the problem from the list of alternative solutions.
In this step, you need to identify and evaluate the pros and cons of each possible
solution before selecting the best one.
For example, from all the resources that have been gathered, identify the most
suitable one that relevant to the title of the case study.

5. List instructions that enable to solve problem using the selected solution.
List out the instructions in step-by-step using the selection solution to solve
problem.
For example, after identified the required resources, the instructions that may
needed is to analysis, study, summarize and make conclusion.

6. Evaluate the solutions.


To evaluate or test a solution means to check its result to see if it is correct, and to
Page 4 of 7

ICT1101 Programme Logic Formulation

Lesson

see if it satisfies the needs of the person(s) with the problem.


If the result is either a correct solution, then the problem solver must start the
process again.
For example, the answer provided for the assignment whether is suitable/relevant to
the problem that given in the assignment.

Algorithm Constructions
Algorithm is a set of rules or instruction to solve a problem.
For example, construct an algorithm to fry an egg.
Issues in program writing and design

To improve your program, review the logic.


Dont optimize code based on a poor algorithm.
Use record to clarify the logic of your program.
Be sure your algorithm correct before starting the code.
Keep your logic simple and short (Keep It Simple & Short - KISS).
Understand clearly about the problem, before you start to design
Program should be easy to read, understand and maintain.
Program coding should be simple and short.
Dont optimize code unless it is absolutely necessary.
Coding should be well organized. Give comment for each calculation and
procedure.
Break complex problems into smaller parts.

Problem-solving With Computers

Page 5 of 7

ICT1101 Programme Logic Formulation

Lesson

Computers are built to deal with algorithm solutions, which are often difficult
or very time-consuming for humans.
Solving a complicated calculus problem or alphabetizing 10,000 names is
easy task for computer but the problem of how to throw a ball or how to speak
English is not, which cannot solved in the steps that make computer can
understand.
The field of computers that deals with heuristic types of problems is called
artificial intelligence.
Artificial intelligence enables a computer to do things like build its own
knowledge bank and speak in a human language.
People will process most heuristic solutions and computers will process many
algorithm solutions.

Page 6 of 7

ICT1101 Programme Logic Formulation

Lesson

Questions: Discussion in the class.


Q1: For each of the following tasks, write a set of numbered, step-by-step
instructions (a solution) so complete that another person could perform the task
without asking questions. Define the knowledge base of this person by listing
what you expect the person to know in order to follow your directions. For
example, for task a (below) make a cup of cocoa, the knowledge base might
include such things as knowledge of milk or water, refrigerator, pan, spoon,
cocoa, cup, range top or microwave, and so forth.
a. Make a cup of cocoa.
b. Sharpen a pencil.
c. Walk from the classroom to the student lounge, your dorm, or the cafeteria.
d. Start a car (include directions regarding what to do if the car doesnt start).
e. Get a glass of water from your kitchen.
Q2:
Write a solution to the problem of finding the largest number out of three
numbers. List the specific steps that would enable another person to find the
largest among three numbers presented.

Page 7 of 7

Potrebbero piacerti anche