Chapter 1 Intro
Chapter 1 Intro
PROGRAMMING AND
APPLICATIONS
(CSC430)
3
BASIC CONCEPT
Computer Programming
Program
Programmer
Programming Language
Compiler
Interpreter
4
BASIC CONCEPT
6
BASIC CONCEPT
Computer program
Hanly [2001], “List of instructions that direct the
computer to transform information from one form to
another.”
Information refers to the contains of specific memory
location.
It is written using programming language.
7
BASIC CONCEPT
Computer program
Turn data (input) into useful information (output).
Program uses variables to store data
Storage
8
EXAMPLE 1
(INPUT – PROCESS – OUTPUT)
Number1 [ 40 ]
Number2 [ 30 ]
Total [70 ]
9
BASIC CONCEPT
Programming Language
A set of rules, words and symbols are used to write a
computer program.
Generation of Programming language
Machine language
Assembly language
10
BASIC CONCEPT
Machine Language
Binary number codes understood by a specific CPU.
Assembly Language
Mnemonic codes that correspond to machine
language instructions
11
BASIC CONCEPT
A Machine-language Program Fragment and Its
Assembly-Language Equivalent
Memory Address Machine-Language Assembly-Language
Instructions Instructions
12
BASIC CONCEPT
Type of High-level languages
Language Application Area Origin Name
FORTRAN Scientific Programming Formula Translation
15
BASIC CONCEPT
Compilation Process
(Input) (Output)
16
PROGRAM DEVELOPMENT PROCESS
Computer programming is a process to develop
a computer program.
5 steps:
1. Problem analysis,
2. Program design,
3. Coding,
4. Testing, and
5. Documentation.
17
PROGRAM DEVELOPMENT PROCESS
Problem Analysis
A process of identifying the output, processes and input
of a program.
How to identify output?
Nouns and adjectives
Keywords – print, display, produce
18
PROGRAM DEVELOPMENT PROCESS
Problem Analysis
Evaluate the following problem statement and identify the
input and output.
19
PROGRAM DEVELOPMENT PROCESS
Input-Process-Output (IPO) chart
INPUT PROCESSING OUTPUT
speed Validate the speed and Classification
length length Can be one if the
following values
20
PROGRAM DEVELOPMENT PROCESS
Program Design
Developing an algorithm
Tools used for Program Design are:-
Flow Chart
Pseudo Code
21
PROGRAM DEVELOPMENT PROCESS
Algorithm is a precise step-by-step action to
perform overall task of the program.
Can be represented either using flowchart or
pseudo-code
22
PROGRAM DEVELOPMENT PROCESS
Direction
Input/Output Operation
Example
23
EXAMPLE 2 (FLOW CHART)
Begin
Read two
numbers
Calculate Total
Print Total
End 24
PROGRAM DEVELOPMENT PROCESS
Flow chart
Begin
Read Speed
Read Length
False
Speed > 1100
True
False
Length > 52
Classification = “Aircraft Type Unknown”
True Classification = “Military”
Classification = “Civilian”
Display classification
End 25
PROGRAM DEVELOPMENT PROCESS
Desk-Check the algorithm
Speed Length Classification
1170 35 ?
1180 56 ?
900 66 ?
800 34 ?
26
PROGRAM DEVELOPMENT PROCESS
Coding
Implement the flowchart or pseudo code into specific
programming language rules (syntax)
Identify the storage requirement
Compilation
Error correction
Syntax Error,
Logic Error or
Runtime Error
27
SOURCE CODE
#include <iostream.h>
#include <string.h>
//program to classify the type of aircraft
main()
{
int speed, length;
char classfication[30];
return 0;
}//end main()
28
PROGRAM DEVELOPMENT PROCESS
Testing
Program must be freed from syntax error
Use a set of test data to validate the output.
Program must produce receive valid input and produce
correct output.
Program must handle invalid input efficiently.
29
PROGRAM DEVELOPMENT PROCESS
Documentation
User manual
Program description
capability, limitation, user guide
30
PROGRAM CONTROL STRUCTURE
There are SIX basic operation:
1. Accept Input through keyboard or files
2. Produce Output and displayed it on screen of file
3. Assign value to a storage
4. Perform arithmetic and logic
5. Make decision using selection statement
6. Repeat the same action
31
PROGRAM CONTROL STRUCTURE
THREE types of control structure:
Sequential Structure
Selection Structure
Iteration Structure (Repetition or loop)
32
PROGRAM CONTROL STRUCTURE
Sequential Structure
ALL statement(s) will be executed from top to bottom.
Statement can be an input/output statement or a
processing statement.
33
PROGRAM CONTROL STRUCTURE
Sequential Structure
Begin
Statement 1
Statement 2
Statement n
End
34
PROGRAM CONTROL STRUCTURE
Sequential Structure (Flow Chart)
Begin
Read Number1,
Number2
Compute Total
Compute Average
Print Total
and Average
End 35
PROGRAM CONTROL STRUCTURE
Selection Structure
Provides alternative actions
Only one action will be executed
Three types:
One-way Selection
Two-way Selection
Multi-way Selection
36
PROGRAM CONTROL STRUCTURE
One-way Selection
A set of statements will be executed if and only the
condition is TRUE.
Two-way Selection
Either one of two set of statements will be
executed if the condition is TRUE.
Multi-way Selection
Has more than one conditions and alternative set
statements.
37
PROGRAM CONTROL STRUCTURE
FALSE
Condition
TRUE
Statement (s)
End
38
PROGRAM CONTROL STRUCTURE
Read Score
FALSE
Score >= 50
TRUE
Status is “Passed”
End 39
PROGRAM CONTROL STRUCTURE
FALSE
Condition
TRUE
End
40
PROGRAM CONTROL STRUCTURE
Read Score
FALSE
Score >= 50
TRUE
End 41
PROGRAM CONTROL STRUCTURE
Read Score
FALSE
Score >= 50
TRUE
End 42
PROGRAM CONTROL STRUCTURE
FALSE
Condition 1
TRUE FALSE
Condition 2
Statement (s)
TRUE FALSE
Condition n
Statement (s)
TRUE
End
43
PROGRAM CONTROL STRUCTURE
FALSE
code = ‘M’
TRUE FALSE
code = ‘F’
gender is “Male”
TRUE
End 44
PROGRAM CONTROL STRUCTURE
Iteration or loops
Perform the same operation more than once
A set of statements will be executed more than once
Example – Read 40 students’ score and compute the
total.
Can be controlled either by counter or sentinel
value.
45
PROGRAM CONTROL STRUCTURE
Counter Controlled loop flowchart:
Initialize counter
False
Test
update counter
46
PROGRAM CONTROL STRUCTURE
The following flowchart illustrate the process of
reading five (5) numbers and calculate the total
count = 0
False
count < 5
True
exit loop
Read a
number
Count + 1 47
PROGRAM CONTROL STRUCTURE
Sentinel Controlled loop flowchart:
False
Test
Sentinel value
True
Statement(s)
Exit loop
48
PROGRAM CONTROL STRUCTURE
The following flowchart illustrate the process of reading a
series of students’ scores and compute the total score. The
process will stop if the value of score read is equal to 999.
Read score
False
Score <> 999?
Read Score
49
PROGRAM CONTROL STRUCTURE
What are the differences between counter
controlled loop and sentinel controlled loop?
50
SELF EXERCISE
52