FUNDAMENTALS OF COMPUTER
PROBLEM SOLVING
(CSC415)
by
AFIZA ISMAIL
College of Computing, Informatics and Mathematics
UiTM SHAH ALAM
Introduction
Chapter One
Contents
⚫ Basic Concept
⚫ Program Development Process
⚫ Program Control Structure
October 4, 2023 3
Basic Concept
⚫ Computer Programming
⚫ Program
⚫ Programmer
⚫ Programming Language
⚫ Compiler
⚫ Interpreter
⚫ Interactive Programming Environment
⚫ Algorithm
October 4, 2023 4
Basic Concept
Reasons for studying Concepts of Programming Languages :
1. Increased capacity to express ideas and solve problems.
⚫ Studying programming languages may increase the capacity
and ability of students to express their ideas in a formal,
computational form.
2. Increased ability to automate process
⚫ Programs are built mainly so that simple, or even complicated
processes to be executed automatically.
October 4, 2023 5
Basic Concept
⚫ Computer programming
• Craft of developing a computer program.
• Require knowledge, skill and creativity.
• Both skill and knowledge in problem solving
and programming language.
October 4, 2023 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.
October 4, 2023 7
Basic Concept
⚫ Computer program
• Turn data (input) into useful information
(output).
• Program uses variables to store data
Input Program Output
Example
Storage
October 4, 2023 8
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
• High Level language (Pascal, C, C++, Java etc)
October 4, 2023 9
Basic Concept
⚫ Machine Language
• Binary number codes understood by a
specific CPU.
⚫ Assembly Language
• Mnemonic codes that correspond to machine
language instructions
October 4, 2023 10
Basic Concept
⚫ A Machine-language Program Fragment and Its
Assembly-Language Equivalent
Memory Address Machine-Language Assembly-Language
Instructions Instructions
00000000 00000000 CLA
00000001 00010101 ADD A
00000010 00010110 ADD B
00000011 00110101 STA A
October 4, 2023 11
Basic Concept
⚫ Type of High-level languages
Language Application Area Origin Name
FORTRAN Scientific Programming Formula Translation
COBOL Business data Processing Common Business-Oriented
Language
Lisp Artificial Intelligent List processing
C System Programming Predecessor Language was named B
Prolog Artificial Intelligent Logic Programming
C++ Support objects and object Incremental modification of C (++ is
oriented programming the C incremental operator)
Java Supports Web Programming Originally name “Oak”
October 4, 2023 12
Basic Concept
⚫ Compiler
• A program that translates a high-level language
program into machine language as a complete unit
⚫ Interpreter
• A set of program that executes the instructions as they
were translated. Interpreter executes a program from
its high-level form.
⚫ Interactive Development Environment (IDE)
• A program that provides user with an environment for
editing, debugging and compiling the source code the
program on- line.
October 4, 2023 13
Basic Concept
⚫ Source file
• A file containing a program written in a high-level
language; the input for the compiler
⚫ Syntax
• Grammar rules of programming language
⚫ Object file
• File of machine-language instructions that is the
output of a compiler
⚫ Algorithm
• A precise step-by-step action to perform overall task of
the program.
October 4, 2023 14
Basic Concept
⚫ Compilation Process
Source File Compiler Object File
(Input) (Output)
October 4, 2023 15
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.
October 4, 2023 16
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
• How to identify input?
• Nouns and adjectives
• Keywords – accept, enter, receive, read
• Define the storage (variable) and data type to hold data
• Outline the process
• Arithmetic or logic operation
• Input-Process-Output (IPO) chart as tool
October 4, 2023 17
Program Development Process
⚫ Problem Analysis
• Evaluate the following problem statement and identify the input
and output.
Nation’s Air force has asked you to write a program to
label supersonic aircraft as military or civilian. Your
program is to be given the plane’s observed speed in
km/h and its estimated length in meters. For planes
traveling in excess of 1100km/h, you will label those
longer than 52 meters “civilian” and shorter aircraft
as “military”. For planes traveling at slower speeds,
you will issue an “aircraft type unknown” message.
October 4, 2023 18
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
• Speed >1100km/h AND Civilian
length > 52m
• Speed > 1100km/h AND Military
length <= 52m
• Speed <= 1100km/h Aircraft type unknown
October 4, 2023 19
Program Development Process
⚫ Program Design
• Developing an algorithm
• Tools used for Program Design are:-
• Flow Chart
• Pseudo Code
October 4, 2023 20
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
October 4, 2023 21
Program Development Process
⚫ A set of symbols and edges used in flow chart:
Terminal (Begin and End) Condition/Evaluation
To represent the process
Direction
Input/Output Operation
Example
October 4, 2023 22
Program Development Process
⚫ Desk-Check the algorithm
Speed Length Classification
1170 35 ?
1180 56 ?
900 66 ?
800 34 ?
October 4, 2023 23
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 Source Code
October 4, 2023 24
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.
• Does the program accept out of range value?
October 4, 2023 25
Program Development Process
⚫ Documentation
• User manual
• Program description
• capability, limitation, user guide
October 4, 2023 26
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
October 4, 2023 27
Program Control Structure
⚫ THREE types of control structure:
• Sequential Structure
• Selection Structure
• Iteration Structure (Repetition or loop)
October 4, 2023 28
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.
October 4, 2023 29
Program Control Structure
⚫ Sequential Structure
Begin
Statement 1
Statement 2
Statement n
End
October 4, 2023 30
Program Control Structure
⚫ Sequential Structure (Flow Chart)
Begin
Read Number1,
Number2
Compute Total
Compute Average
Print Total
and Average
End
October 4, 2023 31
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
October 4, 2023 32
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.
October 4, 2023 33
Program Control Structure
◼ One-way Selection (Flow Chart)
Begin
FALSE
Condition
TRUE
Statement (s)
End
October 4, 2023 34
Program Control Structure
⚫ One-way Selection (Example)
Begin
Read Score
FALSE
Score >= 50
TRUE
Status is “Passed”
End
October 4, 2023 35
Program Control Structure
◼ Two-way Selection (Flow Chart)
Begin
FALSE
Condition
TRUE
Statement (s) Statement (s)
End
October 4, 2023 36
Program Control Structure
⚫ Two-way Selection (Example)
Begin
Read Score
FALSE
Score >= 50
TRUE
Status is “Passed” Status is “Failed”
End
October 4, 2023 37
Program Control Structure
⚫ Two-way Selection (Example)
Begin
Read Score
FALSE
Score >= 50
TRUE
Status is “Passed” Status is “Failed”
End
October 4, 2023 38
Program Control Structure
◼ Multi-way Selection (Flow Chart)
Begin
FALSE
Condition 1
TRUE FALSE
Condition 2
Statement (s)
TRUE FALSE
Condition n
Statement (s)
TRUE
Statement (s) Statement (s)
End
October 4, 2023 39
Program Control Structure
◼ Multi-way Selection (Example)
Begin
FALSE
code = ‘M’
TRUE FALSE
code = ‘F’
gender is “Male”
TRUE
gender is “Female” Status is “Unknown”
End
October 4, 2023 40
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.
October 4, 2023 41
Program Control Structure
⚫ Counter Controlled loop flowchart:
Initialize counter
False
Test
True Exit loop
Statement(s)
update counter
October 4, 2023 42
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
Add number to total
Count + 1
October 4, 2023 43
Program Control Structure
⚫ Sentinel Controlled loop flowchart:
False
Test
Sentinel value
True
Statement(s)
Exit loop
October 4, 2023 44
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?
True Exit loop
Add score to total
Read Score
October 4, 2023 45
Program Control Structure
⚫ What are the differences between
counter controlled loop and sentinel
controlled loop?
October 4, 2023 46
Self Exercise
1. Write a flow chart to calculate and display an average of
three numbers using sequential design
2. Rewrite the above design, determine whether the average is
higher than 50 or not. Display the appropriate message for
each case.
3. Rewrite problem 1 using iteration any iteration approach.
4. Write a flow chart to calculate an average score of 20
students.
5. Write a flow chart to calculate an average of a series positive
numbers. The process will stop if number entered has a
negative value.
6. The cost to send a telegram to UK is RM15.50 for the first 15
letters and RM0.50 for the subsequent letters. Draw a
flowchart to calculate the cost of sending the telegram.
October 4, 2023 47
References
⚫ Jeri R. hanly, Essential C++ for Engineers and
Scientists, 2nd Edition, Addison Wesley
⚫ J. Glenn Brookshear, Computer Science An Overview,
8th Edition, Pearson Addison Wesley
October 4, 2023 48
Example 1
(Input – Process – Output)
Number1 (40) Calculate Total (70)
Number2 (30) total
Number1 [ 40 ]
Number2 [ 30 ]
Total [70 ]
Back
October 4, 2023 49
Example 2 (Flow Chart)
Begin
Read two
numbers
Calculate Total
Print Total
Back
End
October 4, 2023 50
Source Code
#include <iostream.h>
#include <string.h>
//program to classify the type of aircraft
main()
{
int speed, length;
char classfication[30];
cout << “Enter Observed speed : ”;
cin >> length;
cout << “Enter estimated length : ”;
cin >> length;
if (speed > 1100)
if (length > 52)
strcpy(classification,“civilian”);
else
strcpy(classification,“Military”);
else
strcpy(classification,“Aircraft type unknown”);
cout << “Classification is ” << classification << endl;
return 0;
}//end main() Back
October 4, 2023 51