Programming Fundamentals
Consider this Example <ul><li>Determine status of a Student from  marks of two of his subjects  and his  GPA </li></ul><ul...
Programming Fundamentals | Lecture-5 START READ m1, m2, GPA DISPLAY “Passed” STOP (m1 > 40  AND  m2 > 40)  OR  GPA > 2 Yes...
Another Example <ul><li>Determine whether a student has got Grade A from his  total marks  and his  GPA </li></ul><ul><ul>...
Programming Fundamentals | Lecture-5 START READ tm, GPA DISPLAY “A” STOP (tm > 80  AND  tm < 90)  OR  (GPA > 3.7  AND  GPA...
Try this Yourself <ul><li>Determine whether a car is of mid-size type or not from its price (in millions) and engine capac...
Programming Fundamentals | Lecture-5 Decision Box Yes No > > <= < < >= == == != != != == <= <= > >= >= < Operator Opposite...
Decision leading to Decisions <ul><li>In real-world problems, it frequently happens that result of a decision leads to fur...
Consider this Example <ul><li>For two numbers, do the following </li></ul><ul><ul><li>If second number is greater than 0 <...
Programming Fundamentals | Lecture-5 START READ num1, num2 DISPLAY ans STOP ans = num1 / num2 num2 > 0 Yes No num2 < 0 ans...
Another Example <ul><li>For given roll number of a student, display his name </li></ul><ul><ul><li>Assume that there are o...
Programming Fundamentals | Lecture-5 START READ rollNo DISPLAY “Ali” STOP rollNo == 2 Yes No != == Yes < No rollNo == 4 ro...
Try this Yourself <ul><li>For given  day number  of the week, display the corresponding day </li></ul>Programming Fundamen...
Tasks  (to be done by next lecture) <ul><li>Display the name of a city against given city code </li></ul><ul><ul><li>Desig...
Programming Fundamentals | Lecture-5 BE PREPARED FOR  QUIZ IN NEXT LECTURE
Upcoming SlideShare
Loading in …5
×

Cs 1114 - lecture-5

332 views

Published on

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
332
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • 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
  • Cs 1114 - lecture-5

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

    ×