Beruflich Dokumente
Kultur Dokumente
Zawar Hussain
Algorithm
A concept that pervades all areas of computer science.
Al-Khwarizmi Principle
• All complex problems can be broken into simpler
sub-problems.
• Solve a complex problem by breaking it down into
smaller sub-problems and then solve them (in a
specified order), one at a time.
• When all the steps are solved, the original problem
itself has also been solved.
• This process is called Algorithm.
Computer Programming
• Computer is a powerful tool
• It is not intelligent!
• In order to use computer to solve our problems, we
must tell it what we want done and the order in which
we want it done.
• These instructions are called computer program.
• This process is called computer programming.
• The person giving these instructions is called a
computer programmer.
Algorithms
• All computing problems
– can be solved by executing a series of actions in a specific order
• Algorithm
– A procedure determining the
• Actions to be executed
• Order in which these actions are to be executed
• Program control
– Specifies the order in which statements are to executed
Pseudocode
• Pseudocode
– Artificial, informal language used to develop algorithms
– Similar to everyday English
– Not actually executed on computers
– Allows us to “think out” a program before writing the code for it
– Easy to convert into a corresponding C++ program
– Consists only of executable statements
Example:
Begin
Input: Marks
If student’s Marks to 60
Print "Passed“
Else
Print “Failed“
End
Pseudo-code Primitives
Control Structures
• Sequential execution
– Statements executed one after the other in the order written
• Transfer of control
– When the next statement executed is not the next one in sequence
• Bohm and Jacopini: all programs written in terms of 3 control
structures
– Sequence structure
• Built into C++. Programs executed sequentially by
default.
– Selection structures
• C++ has three types - if, if/else, and switch
– Repetition structures
• C++ has three types - while, do/while, and for
Hard Problem
• Output
– Temperature in Celsius (C)
• Inputs
– Temperature in Fahrenheit (F)
• Process
5
C (F 32)
9
Flow Charts
Flow Charting
Decision Terminator
Connectors
Begin
Flow chart for
Converting
Get temp. in ‘F’
Fahrenheit
into Celsius
Calculate 5
C ( F 32)
9
Print ‘C’
Stop
Yes No
More students? Stop
START
INPUT
Step 1: Begin the calculations A, B
BEGIN Adder
Step 2: Input two values A and B Input A and B
C = A + B
Add A to B
Step 3: Add the values PRINT C
and store in C
END Adder
Step 4: Display the result
OUTPUT
Step 5: End the calculation
C
END
Natural language Flowchart Pseudo-code
Ghulam Ishaq Khan Institute of Engineering Sciences and Technology, Topi
Lecture 06:Algo. Flowcharts Pseudocode CS 101: Introduction to Computing
Questions?
Welcome to C++!