Instructor : Muhammad Haris All Rights Reserved to Department of Computer Science – GCU Lahore Programming Fundamentals
Instructor : Muhammad Haris
All Rights Reserved to Department of Computer Science – GCU Lahore
Programming Fundamentals
Recap of Previous Lectures To solve a problem using computers, we
need to do the following:1. Define the problem (in terms of inputs,
outputs and processing)
2. Design a solution for it (using a graphical approach)
○ Symbols used Oval – Start and Stop Parallelogram – Input and Output Rectangle - Processing Diamond - Decision box
Programming Fundamentals | Lecture-4 2
Recap of Previous Lectures Problems we looked at
Sum, Product, Difference of two numbersSquare or cube of a numberSolving an equation or a formula involving 3,
4 variables○ Example
Some formulae from elementary physics or an algebraic equation
Programming Fundamentals | Lecture-4 3
Recap of Previous Lectures Decision making is required in many
real-world problemsComputer programs can be very useful in
this regard
To incorporate decision making in our solutions we learnt the usage of “Decision box”
Programming Fundamentals | Lecture-4 4
Decision Rule
YesNo
Always in the form whose answer is
“Yes” or “No”
Recap of Previous Lectures We always make comparisons in a
decision box or Decision Rules are always in the form of comparisonsExamples
○ difference < 0○ sum > 0○ number2 != 0○ marks >= 50
Programming Fundamentals | Lecture-4 5
Recap of Previous Lectures To determine the usage of decision rule,
follow these steps1. Define inputs and outputs
2. Is decision-making required in this solution?
3. What are the basis of decision?○ the thing which is required to make a
decision will appear in the decision box
4. What kind of comparison is required in the decision box?
Programming Fundamentals | Lecture-4 6
Recap of Previous Lectures Problems we looked at
Checking negativity of a numberChecking equality of two numbersMultiplying or Dividing two numbers
conditionallyChecking status of a student
Programming Fundamentals | Lecture-4 7
Tasks (from previous lecture)
Find whether the sum of two numbers is greater than 50
Find whether the sum of two numbers is greater than the third number?
Divide a number by another if only if the second number is not equal to “0”
Determine whether a student is “passed” or “failed” from his marksA student securing marks less than 50 is
considered “failed”
Programming Fundamentals | Lecture-4 8
Decision Rules
So far1 decision rule in a decision boxExamples
○ difference < 0○ number2 != 0○ marks < 50
Programming Fundamentals | Lecture-4 9
difference < 0 number2 != 0 marks< 50
Consider This Example
Divide a number by another if the second number is greater than “0” and less than “10”
Divide a number by another if the second number is between “0” and “10” (also known as range check)
Programming Fundamentals | Lecture-4 10
OR
Programming Fundamentals | Lecture-4 11
START
READ num1, num2
DISPLAY answer
STOP
answer = num1 / num2
num2 > 0YesNo
More than 1 Decision Rule
Programming Fundamentals | Lecture-4 12
START
READ num1, num2
DISPLAY answer
STOP
answer = num1 / num2
num2 > 0 ANDnum2 < 10
YesNo
Another Example
Add two numbers if either of them is “0”
Programming Fundamentals | Lecture-4 13
Another Example
Determine status of a Students from marks of two of his subjectsIf marks for both the subjects are greater
than 40 he’s considered passed
Programming Fundamentals | Lecture-4 14
Another Example
Determine status of a Students from marks of two of his subjectsIf marks for any of the subjects is greater
than 40 he’s considered passed
Programming Fundamentals | Lecture-4 15
Programming Fundamentals | Lecture-4 16
BE PREPAREDFOR
ON-THE-SPOT TESTIN
NEXT LECTURE