Lecture 1.0 Introduction
Lecture 1.0 Introduction
Lecture 1.0 Introduction
Input Output
Processing
(Set of Instructions) (Report)
PROGRAM
It is like a recipe : Step by step guide, that need to be followed in the right
sequence
Properties:
Steps must be defined precisely (in detail) and clearly
Process must have an end – finite steps
The correct solution to an identified problem
ALGORITHM
Example : At a Public Phone
¢
MAKE A CALL
ALGORITHM
2. TASK : Write a solution algorithm to add 2 numbers and show the result.
1. Get min_temp
2. Get max_temp
3. Calculate average
avg_temp = (min_temp + max_temp) / 2
GENERAL STEPS IN PROGRAM
DEVELOPMENT
Define problem
Understand requirements
Determine input, output and processes
Outline solution
Break problem into smaller tasks or steps, draft solution
Develop outline to algorithm
Expand to precise steps – tasks and order
Test algorithm for correctness
Desk checking – walk through the logic of algorithm
Code the algorithm
Run on the computer
Using compiler and test data to check for errors
Document and maintain program
PROGRAM LIFE CYCLE
Includes :
Initialization
Giving specific/initial value to variables eg. Total = 0
Input definition
Data to be fed into the computer – from keyboard/file
Output definition
layout of the output – screen/printer
Processing requirements
Solution algorithm/sequence of steps required to transform input to the required output
Processing controls
Validation checks on input for accurate processing
Program test plan
A range of test data to ensure the correctness of the program. This includes the calculation of
expected result to verify the actual result produced.
(3) STRUCTURED PROG. DESIGN
aka implementation
(5) PROGRAM DEBUGGING
3 types of errors:
Syntax – error relating to the programming language used
Logical – error in programming logic
Run-time/execution – error during running/ execution of program
(6) PROGRAM TESTING
A program is required to
take in 2 numbers as
integers, then calculate
and display the sum.
Structured
A methodEnglish
of specifying unambiguous
narrative used to define procedural logic.
It lacks the precision of meaning and simplicity
when programming.
Example :
1. Accept first integer and second integer
2. Add first integer and second integer and
then put the result in sum
3. Display sum
Flow Chart
START
END
Top-Down Stepwise Refinement Method
Calculate
Sum
STRUCTURED CHART
Jackson Structured Program (JSP) Method
Uses the same principle of control
structures but concentrates on both data
structures and program structures
Sum
num1 num2
Calculate Sum
PROGRAM STRUCTURE
Jackson Structured Program (JSP) Method
List of Conditions
none
List of Actions
A. Input Action
1. Read num1
2. Read num2
B. Output Action
3. Print sum
C. Computation
4. Sum = num1 + num2
Jackson Structured Program (JSP) Method
ALLOCATION OF ACTIONS
Calculate Sum
1 2 4,3
Pseudocode
aka Schematic Logic
Understandable to user
Hierarchically structured and using indentation
to show this structure
Similar structure to the targeted programming
code
Comments are clearly marked
Pseudocode rules
Indentation
Control structures are clear
sequence steps are placed on separate lines, each is ended with
a semicolon. Continuation lines are indented if more than one
line is required.
Use of keywords to show
the structures e.g IF, THEN, ELSE, WHILE etc
The logic e.g. AND, OR, NOT
Keywords may be selected to be independent of the language
descriptions
Pseudocode rules
a. Initialization
none
b. Input Definition
number1 , number2, number3
c. Output Definition
The sum is = 99999.9
d. Processing Requirements
1. Read number1, number2, number3
2. Calculate total
total = number1 + number2 + number3
3. Print total
Problem analysis
(step-wise refinement method)
e. Processing Controls
none
a. InpInitialization
none
b. ut Definition
max_temp, min_temp
c. Output Definition
Average Temperature = 9999.9
d. Processing Requirements
1. Read max_temp, min_temp
2. Calculate average
avg_temp = (max_temp + min_temp) / 2
3. Print avg_temp
Problem analysis
(step-wise refinement method)
e. Processing Controls
1. Temperatures cannot be negative values
2. Average temperature is rounded to 1 d.p.
a. Initialization
no_test = 4
b. Input Definition
studentNo, test1, test2, test3, test4
c. Output Definition
Student No : XXXXXX
Grade : XXXXXXXXX
d. Processing Requirements
1. Read studentNo, test1, test2, test3, test4
2. Calculate average
avg_mark = (test1 + test2 + test3 + test4) / no_test
d. Processing Requirements (Cont..)
3. Decide Grade
If avg_mark >= 80
grade = “Distinction”
else
if avg_mark >= 65
grade = “Merit”
else
if avg_mark >= 50
grade = “Pass”
else
grade = “fail”
4. Print studentNo, grade
Problem analysis
(step-wise refinement method)
e. Processing Controls
1. Test mark should be in the range of 0 to 100
2. Average mark must be integer.
Problem analysis
(step-wise refinement method)
e. Test Data and Expected Results
Problem specification
Example 4
a. Initialization
total = 0 , num_count = 0
b. Input Definition
number
c. Output Definition
Average value = 9999.9
Problem analysis
(step-wise refinement method)
d. Processing Requirements
1. While num_count < 10
I. Read number
2. Calculate average
avg_num = total / num_count
3. Print avg_num
Problem analysis
(step-wise refinement method)
e. Processing Controls
1. Number must be > 0 and < 100
2. Average is rounded off to 2 d.p.