Professional Documents
Culture Documents
C++ Lect 4
C++ Lect 4
Programming
Ms Qurat-ul-Ann
What Can a Program Do?
Ms Qurat-ul-Ann
Calculate
Ms Qurat-ul-Ann
Store
Ms Qurat-ul-Ann
Compare and Branch
• IF
• IF-ELSE
Ms Qurat-ul-Ann
Programs are Solutions
to Problems
Programmers arrive at these solutions by
using one or more of these devices:
Words
Logic flowcharts
Pseudocode
Programming language
Ms Qurat-ul-Ann
Algorithm
• A FINITE set of clear, executable steps that will
eventually terminate to produce the desired
outcome
• Logical design used to solve problems – usually a list
of actions required to perform task
Pseudocode
• Written like program code but more “English Like”
and doesn’t have to conform to language syntax
Flowchart
• Diagram that visually represents the steps to be
performed to arrive at solution.
Ms Qurat-ul-Ann
Example 1:
Ms Qurat-ul-Ann
In words
Input a set of 4 marks
Calculate their average by summing and dividing
by 4
if average is below 50
Print “FAIL”
else
Print “PASS”
Ms Qurat-ul-Ann
Logic Flowcharts
These represent the flow of
logic in a program and help
programmers “see”
program design.
It is a way of visually
presenting the flow of data,
the operations performed
within the system and the
sequence in which they are
performed.
Ms Qurat-ul-Ann
Common Flowchart Symbols
Common Flowchart Symbols
symbol.
The direction of arrows should be top to bottom
and left to right/right to left.
It should be simple and drawn clearly and neatly.
The branches of decision box must be labeled.
Ms Qurat-ul-Ann
Advantages / Disadvantages
Advantages
Provides convenient method to understand the
solution.
Helps in debugging process
Provides guide for coding.
Disadvantages
Not suitable for large programs.
Ms Qurat-ul-Ann
Calculate Pay
Ms Qurat-ul-Ann
The program computes the sum, average and
product of three numbers:
Ms Qurat-ul-Ann
Sum of two numbers
Ms Qurat-ul-Ann
START
Input
M1,M2,M3,M4 Example
GRADE(M1+M2+M3+M4)/4
Step 1: Input M1,M2,M3,M4
Step 2: GRADE (M1+M2+M3+M4)/4
Step 3: if (GRADE <50) then
Print “FAIL”
N Y
IS else
GRADE<50
Print “PASS”
end if
PRINT PRINT
“PASS” “FAIL”
Ms Qurat-ul-Ann
STOP
Pseudo code
Ms Qurat-ul-Ann
Pseudocode
Ms Qurat-ul-Ann
The program computes the average of three
numbers
Begin
input x
input y
input z
sum = x + y + z
avg = sum / 3.0
print avg
End
Ms Qurat-ul-Ann
Calculate Pay
Ms Qurat-ul-Ann
Sum Of Two Numbers
Begin
input x, y
sum = x + y
print sum
END
Ms Qurat-ul-Ann
Practice
Ms Qurat-ul-Ann
Practice
Solution
Ms Qurat-ul-Ann
OOPS!!!
ASSIGNMENT
Ms Qurat-ul-Ann