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
Programming Fundamentals | Lecture-5 START READ m1, m2, GPA DISPLAY “Passed” STOP (m1 > 40  AND  m2 > 40)  OR  GPA > 2 Yes No 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
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”
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
Programming Fundamentals | Lecture-5 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
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
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 ==
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
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
Try this Yourself For given  day number  of the week, display the corresponding day Programming Fundamentals | Lecture-5 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 Pay type Description Dividing Factor 1 Weekly 52 2 Bi-monthly 24 3 Monthly 12
Programming Fundamentals | Lecture-5 BE PREPARED FOR  QUIZ IN NEXT LECTURE

Cs 1114 - lecture-5

  • 1.
  • 2.
    Consider this ExampleDetermine 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
  • 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.
    Another Example Determinewhether 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
  • 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.
    Try this YourselfDetermine 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
  • 7.
    Programming Fundamentals |Lecture-5 Decision Box Yes No > > <= < < >= == == != != != == <= <= > >= >= < Operator Opposite > <= < >= == != != == <= > >= <
  • 8.
    Decision leading toDecisions 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
  • 9.
    Consider this ExampleFor 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
  • 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.
    Another Example Forgiven 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
  • 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.
    Try this YourselfFor given day number of the week, display the corresponding day Programming Fundamentals | Lecture-5 Day Number Week Day 1 Monday 2 Tuesday 3 Wednesday 4 Thursday
  • 14.
    Tasks (tobe 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 Pay type Description Dividing Factor 1 Weekly 52 2 Bi-monthly 24 3 Monthly 12
  • 15.
    Programming Fundamentals |Lecture-5 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