Instructor : Muhammad Haris
All 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 GPAIf 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 GPAIf 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 followingIf second number is greater than 0
○ Divide themIf second number is less than 0
○ Multiply themIf 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 > 0YesNo
num2 < 0
ans = num1 * num2ans = num1 +num2
<= >
Yes<
No==
Another Example
For given roll number of a student, display his nameAssume 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 == 2YesNo
!= ==
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 codeDesign your solution for 4-5 cities only
Calculate base pay from given annual salary and pay typeBase pay = salary / Dividing Factor
Programming Fundamentals | Lecture-5 14
Pay type Description Dividing Factor
1 Weekly 52
2 Bi-monthly 24
3 Monthly 12