SlideShare a Scribd company logo
Instructor : Muhammad HarisAll Rights Reserved to Department of Computer Science – GCU Lahore
Programming Fundamentals
Consider this Example
 Determine status of a Student from
marks of two of his subjects and his
GPA
If either the marks for both of the subjects
are greater than 40 or GPA is greater than
2, he’s considered passed
Programming Fundamentals | Lecture-5 2
Programming Fundamentals | Lecture-5 3
START
READ m1, m2, GPA
DISPLAY “Passed”
STOP
(m1 > 40 AND m2 > 40)
OR GPA > 2
YesNo
DISPLAY “Failed”
Another Example
 Determine whether a student has got
Grade A from his total marks and his
GPA
If marks are greater than 80 and less than
90 OR GPA is greater than 3.7 and less 3.8,
he will be graded as “A”
Programming Fundamentals | Lecture-5 4
Programming Fundamentals | Lecture-5 5
START
READ tm, GPA
DISPLAY “A”
STOP
(tm > 80 AND tm < 90)
OR
(GPA > 3.7 AND GPA < 3.8)
YesNo
DISPLAY “Other than A”
Try this Yourself
 Determine whether a car is of mid-size
type or not from its price (in millions) and
engine capacity (in cc)
If price is between 1 million and 2 million or
if engine capacity is between 1000 and
1500, a car is considered to be a mid-size
car
Programming Fundamentals | Lecture-5 6
Programming Fundamentals | Lecture-5 7
Decision Box Yes No
> > <=
< < >=
== == !=
!= != ==
<= <= >
>= >= <
Operator Opposite
> <=
< >=
== !=
!= ==
<= >
>= <
Decision leading to Decisions
 In real-world problems, it frequently
happens that result of a decision leads
to further decision making
 This way computer programs prove to
be much more useful
Programming Fundamentals | Lecture-5 8
Consider this Example
 For two numbers, do the following
If second number is greater than 0
○ Divide them
If second number is less than 0
○ Multiply them
If second number is equal to 0
○ Add them
Programming Fundamentals | Lecture-5 9
Programming Fundamentals | Lecture-5 10
START
READ num1, num2
DISPLAY ans
STOP
ans = num1 / num2
num2 > 0
YesNo
num2 < 0
ans = num1 * num2ans = num1 +num2
<= >
Yes
<
No
==
Another Example
 For given roll number of a student,
display his name
Assume that there are only three students
(first three roll numbers of your section)
Programming Fundamentals | Lecture-5 11
Programming Fundamentals | Lecture-5 12
START
READ rollNo
DISPLAY “Ali”
STOP
rollNo == 2
YesNo
!= ==
Yes
<No
rollNo == 4
rollNo == 8
DISPLAY
“Rehman”
DISPLAY
“Hassan”
DISPLAY “No
Such Student”
YesNo
Try this Yourself
 For given day number of the week,
display the corresponding day
Programming Fundamentals | Lecture-5 13
Day Number Week Day
1 Monday
2 Tuesday
3 Wednesday
4 Thursday
Tasks (to be done by next lecture)
 Display the name of a city against given
city code
Design your solution for 4-5 cities only
 Calculate base pay from given annual
salary and pay type
Base pay = salary / Dividing Factor
Programming Fundamentals | Lecture-5 14
Pay type Description Dividing Factor
1 Weekly 52
2 Bi-monthly 24
3 Monthly 12
Programming Fundamentals | Lecture-5 15
BE PREPARED
FOR
QUIZ
IN
NEXT LECTURE

More Related Content

PPT
Fundamental Programming Lect 2
PPT
Fundamental Programming Lect 4
PPT
Fundamental Programming Lect 3
PPTX
Programming fundamentals lecture 1 0f c
PPTX
Programming fundamentals lecture 2 of c
PPTX
Programming Fundamentals
PPT
Cs 1114 - lecture-3
PPT
Introduction to problem solving in c++
Fundamental Programming Lect 2
Fundamental Programming Lect 4
Fundamental Programming Lect 3
Programming fundamentals lecture 1 0f c
Programming fundamentals lecture 2 of c
Programming Fundamentals
Cs 1114 - lecture-3
Introduction to problem solving in c++

What's hot (20)

PPTX
Flowcharts and pseudocodes
PPTX
Introduction to problem solving in C
PPT
Cs 1114 - lecture-5
PPT
2.3 Apply the different types of algorithm to solve problem
PPT
Class 7 lecture notes
PPT
Problem solving using Computer
PDF
1 introduction to problem solving and programming
PDF
Fundamentals of programming)
PPT
Problem Solving Techniques
PPT
Data structures & problem solving unit 1 ppt
PDF
Problem solving (C++ Programming)
PPTX
Algorithm &amp; flowchart
PPTX
Algorithm and flowchart
PPTX
Flowchart and algorithem
PPT
An introduction to Competitive Programming
PPT
03 algorithm properties
PPT
Dynamic programming 2
PPTX
Competitive Programming Guide
PPTX
Algorithm and flowchart2010
PPT
Flowcharts and pseudocodes
Introduction to problem solving in C
Cs 1114 - lecture-5
2.3 Apply the different types of algorithm to solve problem
Class 7 lecture notes
Problem solving using Computer
1 introduction to problem solving and programming
Fundamentals of programming)
Problem Solving Techniques
Data structures & problem solving unit 1 ppt
Problem solving (C++ Programming)
Algorithm &amp; flowchart
Algorithm and flowchart
Flowchart and algorithem
An introduction to Competitive Programming
03 algorithm properties
Dynamic programming 2
Competitive Programming Guide
Algorithm and flowchart2010
Ad

Viewers also liked (9)

PPTX
Programming fundamentals lecture 4
PPT
Fundamental Programming Lect 1
PPTX
Computer programs, flow chart & algorithm
PPT
Programming fundamentals lecture 1&2
PPT
01 c++ Intro.ppt
PPTX
Functional Programming Fundamentals
PPT
20. Object-Oriented Programming Fundamental Principles
PPTX
C++ ppt
PPT
Basics of c++ Programming Language
Programming fundamentals lecture 4
Fundamental Programming Lect 1
Computer programs, flow chart & algorithm
Programming fundamentals lecture 1&2
01 c++ Intro.ppt
Functional Programming Fundamentals
20. Object-Oriented Programming Fundamental Principles
C++ ppt
Basics of c++ Programming Language
Ad

Similar to Fundamental Programming Lect 5 (20)

PPT
Cs 1114 - lecture-7
PPT
Cs 1114 - lecture-4
PPT
Cs 1114 - lecture-6
PPT
Programming algorithms and flowchart.ppt
PPT
Cs 1114 - lecture-10
PPT
Chapter 3 Selection of Java Chapter 3 Selection of Java
PPT
Cs 1114 - lecture-9
DOCX
Mb0048 operations research
PPT
Copy of dti2143/dam31303 chap 1 problem solving and program design
PPT
Cs 1114 - lecture-8
PDF
28_09_2018 eMadrid seminar on MOOCs by Ralf Teusner, Hasso Plattner Institute...
PDF
15 min guide to gmat (1)
PPSX
Algorithm and flowchart
PPTX
Metode Perancangan Program #2 Selection and Repetition Control Structure-ITSB...
PPS
Test case design_the_basicsv0.4
PPT
Covidien Dc Work Keys 101 2
DOC
Lab 6 sem ii_11_12
PDF
The gmat-unlocked
PPT
Black Box Testing
Cs 1114 - lecture-7
Cs 1114 - lecture-4
Cs 1114 - lecture-6
Programming algorithms and flowchart.ppt
Cs 1114 - lecture-10
Chapter 3 Selection of Java Chapter 3 Selection of Java
Cs 1114 - lecture-9
Mb0048 operations research
Copy of dti2143/dam31303 chap 1 problem solving and program design
Cs 1114 - lecture-8
28_09_2018 eMadrid seminar on MOOCs by Ralf Teusner, Hasso Plattner Institute...
15 min guide to gmat (1)
Algorithm and flowchart
Metode Perancangan Program #2 Selection and Repetition Control Structure-ITSB...
Test case design_the_basicsv0.4
Covidien Dc Work Keys 101 2
Lab 6 sem ii_11_12
The gmat-unlocked
Black Box Testing

Recently uploaded (20)

PPT
Teaching material agriculture food technology
PDF
cuic standard and advanced reporting.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Approach and Philosophy of On baking technology
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Spectral efficient network and resource selection model in 5G networks
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Empathic Computing: Creating Shared Understanding
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
1. Introduction to Computer Programming.pptx
PPTX
A Presentation on Artificial Intelligence
PDF
Unlocking AI with Model Context Protocol (MCP)
Teaching material agriculture food technology
cuic standard and advanced reporting.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Approach and Philosophy of On baking technology
The Rise and Fall of 3GPP – Time for a Sabbatical?
Spectral efficient network and resource selection model in 5G networks
“AI and Expert System Decision Support & Business Intelligence Systems”
Empathic Computing: Creating Shared Understanding
Mobile App Security Testing_ A Comprehensive Guide.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
MYSQL Presentation for SQL database connectivity
Encapsulation_ Review paper, used for researhc scholars
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Accuracy of neural networks in brain wave diagnosis of schizophrenia
20250228 LYD VKU AI Blended-Learning.pptx
1. Introduction to Computer Programming.pptx
A Presentation on Artificial Intelligence
Unlocking AI with Model Context Protocol (MCP)

Fundamental Programming Lect 5

  • 1. Instructor : Muhammad HarisAll Rights Reserved to Department of Computer Science – GCU Lahore Programming Fundamentals
  • 2. Consider this Example  Determine status of a Student from marks of two of his subjects and his GPA If either the marks for both of the subjects are greater than 40 or GPA is greater than 2, he’s considered passed Programming Fundamentals | Lecture-5 2
  • 3. Programming Fundamentals | Lecture-5 3 START READ m1, m2, GPA DISPLAY “Passed” STOP (m1 > 40 AND m2 > 40) OR GPA > 2 YesNo DISPLAY “Failed”
  • 4. Another Example  Determine whether a student has got Grade A from his total marks and his GPA If marks are greater than 80 and less than 90 OR GPA is greater than 3.7 and less 3.8, he will be graded as “A” Programming Fundamentals | Lecture-5 4
  • 5. Programming Fundamentals | Lecture-5 5 START READ tm, GPA DISPLAY “A” STOP (tm > 80 AND tm < 90) OR (GPA > 3.7 AND GPA < 3.8) YesNo DISPLAY “Other than A”
  • 6. Try this Yourself  Determine whether a car is of mid-size type or not from its price (in millions) and engine capacity (in cc) If price is between 1 million and 2 million or if engine capacity is between 1000 and 1500, a car is considered to be a mid-size car Programming Fundamentals | Lecture-5 6
  • 7. Programming Fundamentals | Lecture-5 7 Decision Box Yes No > > <= < < >= == == != != != == <= <= > >= >= < Operator Opposite > <= < >= == != != == <= > >= <
  • 8. Decision leading to Decisions  In real-world problems, it frequently happens that result of a decision leads to further decision making  This way computer programs prove to be much more useful Programming Fundamentals | Lecture-5 8
  • 9. Consider this Example  For two numbers, do the following If second number is greater than 0 ○ Divide them If second number is less than 0 ○ Multiply them If second number is equal to 0 ○ Add them Programming Fundamentals | Lecture-5 9
  • 10. Programming Fundamentals | Lecture-5 10 START READ num1, num2 DISPLAY ans STOP ans = num1 / num2 num2 > 0 YesNo num2 < 0 ans = num1 * num2ans = num1 +num2 <= > Yes < No ==
  • 11. Another Example  For given roll number of a student, display his name Assume that there are only three students (first three roll numbers of your section) Programming Fundamentals | Lecture-5 11
  • 12. Programming Fundamentals | Lecture-5 12 START READ rollNo DISPLAY “Ali” STOP rollNo == 2 YesNo != == Yes <No rollNo == 4 rollNo == 8 DISPLAY “Rehman” DISPLAY “Hassan” DISPLAY “No Such Student” YesNo
  • 13. Try this Yourself  For given day number of the week, display the corresponding day Programming Fundamentals | Lecture-5 13 Day Number Week Day 1 Monday 2 Tuesday 3 Wednesday 4 Thursday
  • 14. Tasks (to be done by next lecture)  Display the name of a city against given city code Design your solution for 4-5 cities only  Calculate base pay from given annual salary and pay type Base pay = salary / Dividing Factor Programming Fundamentals | Lecture-5 14 Pay type Description Dividing Factor 1 Weekly 52 2 Bi-monthly 24 3 Monthly 12
  • 15. Programming Fundamentals | Lecture-5 15 BE PREPARED FOR QUIZ IN NEXT LECTURE

Editor's Notes

  • #10: Note: A decision box always leads to two paths, not more than two. But in this example you can see more than two paths. Hence one decision box is not sufficient to achieve this solution