Cs 1114 - lecture-3

286 views
239 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
286
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Cs 1114 - lecture-3

  1. 1. Programming Fundamentals
  2. 2. Tasks (from previous lecture) <ul><li>Calculate area of a rectangle </li></ul><ul><ul><li>area = base  height </li></ul></ul><ul><li>Find Cube of a Number </li></ul><ul><li>Calculate Marks Percentage </li></ul><ul><ul><li>(marks obtained / total marks)  100 </li></ul></ul><ul><li>Calculate Sales Tax </li></ul><ul><ul><li>amount  (tax percent / 100) </li></ul></ul><ul><li>Find “no. of minutes” and “no. of seconds” for given “no of years” </li></ul>Programming Fundamentals | Lecture-3
  3. 3. Power of Computer Programs <ul><li>Once given the input </li></ul><ul><ul><li>They perform the instructions (or no. of steps as instructed by the programmer) themselves and give the desired output </li></ul></ul><ul><ul><ul><li>No matter how complex the problem is and how long they have to work on it </li></ul></ul></ul>Programming Fundamentals | Lecture-3 Now We Will Further Explore Their Power
  4. 4. Consider this Problem <ul><li>Find absolute value after subtracting one number from another </li></ul><ul><ul><li>Difference = number1 – number2 </li></ul></ul>Programming Fundamentals | Lecture-3
  5. 5. Difference of Two numbers Programming Fundamentals | Lecture-3 START READ number1, number2 difference = number1 - number2 DISPLAY difference STOP Will result in a negative value if number1 is smaller than number2
  6. 6. Is This Solution Correct? Programming Fundamentals | Lecture-3 START READ number1, number2 difference = number1 - number2 DISPLAY difference STOP difference = difference * -1
  7. 7. Analyze the Problem <ul><li>There exists two conditions </li></ul><ul><ul><li>Condition-1 </li></ul></ul><ul><ul><ul><li>Difference is positive </li></ul></ul></ul><ul><ul><li>Condition-2 </li></ul></ul><ul><ul><ul><li>Difference is negative </li></ul></ul></ul>Programming Fundamentals | Lecture-3
  8. 8. What is to be Done? <ul><li>There exists two conditions </li></ul><ul><ul><li>Condition-1 </li></ul></ul><ul><ul><ul><li>Difference is positive </li></ul></ul></ul><ul><ul><ul><ul><li>Do not do any conversion, because value is already positive </li></ul></ul></ul></ul><ul><ul><li>Condition-2 </li></ul></ul><ul><ul><ul><li>Difference is negative </li></ul></ul></ul><ul><ul><ul><ul><li>Convert it into a positive value by multiplying it by “-1” </li></ul></ul></ul></ul>Programming Fundamentals | Lecture-3
  9. 9. Should we design two different solutions? Programming Fundamentals | Lecture-1
  10. 10. What is Required? <ul><li>Need to design a solution in such a way which can decide for itself whether to multiply the difference by “-1” or not (by checking the value of difference) </li></ul><ul><li>The graphical shapes which we have learned so far are insufficient to provide this kind of “ decision making ” </li></ul>Programming Fundamentals | Lecture-3
  11. 11. Decision Box Programming Fundamentals | Lecture-3 Decision Rule Yes No Always in the form whose answer is “ Yes” or “No”
  12. 12. Programming Fundamentals | Lecture-3 START READ number1, number2 difference = number1 - number2 DISPLAY difference STOP difference = difference * -1 difference < 0 Yes No
  13. 13. Power of Computers <ul><li>Decision Making </li></ul><ul><ul><li>Programmers can instruct computers to make decisions while solving a problem </li></ul></ul><ul><ul><ul><li>As the complexity of problems increases, decision making process become more extensive </li></ul></ul></ul><ul><ul><li>This way computers prove very useful by performing laborious tasks of decision making </li></ul></ul>Programming Fundamentals | Lecture-3
  14. 14. Another Example <ul><li>Find smaller of two numbers </li></ul><ul><li>Input </li></ul><ul><ul><li>number1 </li></ul></ul><ul><ul><li>number2 </li></ul></ul><ul><li>Output </li></ul><ul><ul><li>smaller </li></ul></ul><ul><li>Processing </li></ul><ul><ul><li>Compare the numbers with each other and decide which one is smaller </li></ul></ul>Programming Fundamentals | Lecture-3
  15. 15. Programming Fundamentals | Lecture-3 START READ number1, number2 DISPLAY smaller STOP smaller = number1 number1 < number2 Yes No smaller = number2
  16. 16. Alternative Programming Fundamentals | Lecture-3 START READ number1, number2 STOP DISPLAY number1 number1 < number2 Yes No DISPLAY number2
  17. 17. Comparison Operators <ul><li>< (less than) </li></ul><ul><li>> (greater than) </li></ul><ul><li><= (less than equal to) </li></ul><ul><li>>= (greater than equal to) </li></ul><ul><li>== (equal to) </li></ul><ul><li>!= (not equal to) </li></ul>Programming Fundamentals | Lecture-3
  18. 18. Output a Message Programming Fundamentals | Lecture-3 DISPLAY “This is a message”
  19. 19. Try it Yourself <ul><li>Find whether a number is negative or not? </li></ul><ul><li>Find whether two numbers are equal or not? </li></ul><ul><li>Multiply two numbers if their difference is greater than 0 </li></ul>Programming Fundamentals | Lecture-3
  20. 20. Some Keywords <ul><li>Look for these keywords in problem statement in order to determine the usage of decision box </li></ul><ul><ul><li>If </li></ul></ul><ul><ul><li>If and only if </li></ul></ul><ul><ul><li>Whether </li></ul></ul>Programming Fundamentals | Lecture-3
  21. 21. Tasks (to be done by next lecture) <ul><li>Find whether the sum of two numbers is greater than 50 </li></ul><ul><li>Find whether the sum of two numbers is greater than the third number? </li></ul><ul><li>Divide a number by another if only if the second number is not equal to “0” </li></ul><ul><li>Determine whether a student is “passed” or “failed” from his marks </li></ul><ul><ul><li>A student securing marks less than 50 is considered “failed” </li></ul></ul>Programming Fundamentals | Lecture-3
  22. 22. Programming Fundamentals | Lecture-2 BE PREPARED FOR QUIZ IN NEXT LECTURE

×