Software Development Techniques - Topic 02

2,804
-1

Published on

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

No Downloads
Views
Total Views
2,804
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
99
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Software Development Techniques - Topic 02

  1. 1. Topic 2 : Desk-Checking Er. Pradip Kharbuja Er. Pradip Kharbuja
  2. 2. What Makes a Good Algorithm? •A good algorithm has the following qualities: 1.Complete 2.Efficient 3.Readable 4.Maintainable 5.Documented 6.Robust Er. Pradip Kharbuja
  3. 3. Syntax •The words and symbols that make up a programming language are known as its syntax. •Java, C, Visual Basic and so on all have their own particular syntax. •Example of declaring variable as integer In Javainta; In Visual Basic Dim a as Integer Er. Pradip Kharbuja
  4. 4. Why Pseudocode? •No need to worry about programming language •We can focus on the logic of an algorithm rather than the programming language specific features •Pseudo code can be useful if you're unfamiliar with the programming language Er. Pradip Kharbuja
  5. 5. PseudocodeSyntax •There are many different styles of writing pseudocode. •There is no ‘correct’ form of pseudo code. •But we will use the following syntax : 1.When we need to hold some value, we use the word datato set up a container for it: syntax : Data <name> as <type> e.g. Data myAgeas whole number •Acceptable types for now are ‘whole number’, ‘real number’, ‘string’, ‘character’, ‘boolean' Er. Pradip Kharbuja
  6. 6. PseudocodeSyntax 2.When we need to get information from the user, we use the word input: syntax : Input <name> e.g. : Input myAge 3.When we need to display anything to the user, we use output. Enclose in quotation marks. e.g. : Output “Hello there!” •If we need to output the contents of some data, we also use output but omit the quotation marks: e.g. : Output myAge Er. Pradip Kharbuja
  7. 7. Task Take following inputs and display them: 1.First Name 2.Last Name 3.Age 4.Salary
  8. 8. Pseudocode Er. Pradip Kharbuja
  9. 9. Pseudocode Er. Pradip Kharbuja
  10. 10. Arithmetic Operators Er. Pradip Kharbuja % gives remainder e.g. 10 % 3 gives 120 % 4 gives 01% 3 gives 1
  11. 11. PseudocodeSyntax •We can put information/value in a data container like: •When we wish to perform arithmetic calculation on numerical data, we need a container for the answer and then we use the arithmetic symbols: Er. Pradip Kharbuja
  12. 12. PseudocodeExample -1 Er. Pradip Kharbuja
  13. 13. PseudocodeExample -2 •Write a pseudocodeto multiply two numbers. Er. Pradip Kharbuja
  14. 14. Desk-Check Desk checking is a manual (non computerised) technique for checking the logic of an algorithmor pseudo code, ensuring there are no bugs or mistakes present. This process is done manually without computer assistance becausepseudo code is not a real programming language. Desk checks are useful to check an algorithm (before coding) thereby confirming that the algorithm works as expected. Er. Pradip Kharbuja
  15. 15. What is in a Desk-Check? Desk-check results are documented on a table for easy reference. The table typically has columns for the line number variables a condition column, which is either true or false an input column an output column, which shows the end results. and remarks column Er. Pradip Kharbuja
  16. 16. Er. Pradip Kharbuja Again, there are no specific rules for pseudo code and desk-check
  17. 17. PseudocodeExample -1(with line number) Er. Pradip Kharbuja
  18. 18. Desk-Checking PseudocodeExample -1 Line No. myAge myNewAge Input Output Remarks 1 0 2 0 0 3 0 0 "Please enter your age" Output in Screen 4 21 0 21 User enters 21 5 21 22 myNewAge= myAge+ 1 6 21 22 "In next year you will be" Output 7 21 22 22 Output Er. Pradip Kharbuja
  19. 19. PseudocodeExample -2 •Write a pseudocodeto multiply two numbers. Er. Pradip Kharbuja
  20. 20. Desk-Checking PseudocodeExample –2 Line Num. firstNumber secondNumber answer Input Output Remarks 1 0 2 0 0 3 0 0 0 4 0 0 0 "Please enter a number" Output 5 20 0 0 20 Input 6 20 0 0 "Please enter a second number" 7 20 5 0 5 8 20 5 100 Process 9 20 5 100 "The answer is " 10 20 5 100 100 Er. Pradip Kharbuja
  21. 21. PseudocodeExample -3 Er. Pradip Kharbuja
  22. 22. Desk-Checking PseudocodeExample –3 Line Num. income taxRate myTax myNetPay Input Output Remarks 1 0 2 0 0 3 0 0 0 4 0 0 0 0 5 0 0 0 0 Output 6 20000 0 0 0 20000 User inputs 20000 7 20000 10.00 0 0 8 20000 10.00 200000 0 9 20000 10.00 200000 -180000 10-13 20000 10.00 200000 -180000 -180000 Output Er. Pradip Kharbuja
  23. 23. Desk-Checking •Desk-checks help to find the errors in your logic. •When you have made an error, you can go back to the pseudocodeand correct it. •By desk-checking complex algorithms, we can be sure the problem is in our logic. •In this case, our tax calculation is incorrect. Tax should be 10%. Er. Pradip Kharbuja
  24. 24. Correction Before After 7 taxRate= 10.00 8 myTax= income * taxRate 9 myNetPay= income -myTax 7 taxRate= 10.00 8 myTax= (income / 100) * taxRate 9 myNetPay= income -myTax Er. Pradip Kharbuja •Mistakes are going to happen –that’s unavoidable. •Pseudocodelets us ensure that we fix it at the earliest and easiest point -before we have written a single line of code.
  25. 25. Again, Desk-Checking PseudocodeExample –3 Line Num. income taxRate myTax myNetPay Input Output Remarks 1 0 2 0 0 3 0 0 0 4 0 0 0 0 5 0 0 0 0 Output 6 20000 0 0 0 20000 User inputs 20000 7 20000 10.00 0 0 8 20000 10.00 2000 0 9 20000 10.00 2000 18000 10-13 20000 10.00 2000 18000 18000 Output Er. Pradip Kharbuja
  26. 26. Desk-Checking With a desk-check we can see where data starts going wrong Sometimes, errors won’t be uncovered in a single desk- check When picking user input, be awkward. What happens if you enter a negative number in our previous examples? Er. Pradip Kharbuja
  27. 27. Desk-Checking •The code (or pseudocode) that we write defines the flow of executionthrough a program. This is the order in which code statements are executed when the program is running. •So far, we have looked only at sequentialflow of execution. Each line of code is executed after the last. •In later weeks, we will look at ways of representing loops and choices. These make desk-checking more challenging. Er. Pradip Kharbuja
  28. 28. Commenting •All programs should contain comments. These are human readable notes in the program that are ignored when it is compiled. •They make programs much more readable. •The two main commenting styles in most languages are 1.line-by-line //this is a comment 2.block comments. /* This is block comment */ Er. Pradip Kharbuja
  29. 29. Commenting -2 •Add comments when: •You are doing something unusual •You are doing something that requires some assumptions. •Comments should detail your intention, not simply describe what the code does. Er. Pradip Kharbuja
  30. 30. Commenting -3 /* The following algorithm calculates the length of the hypotenuse of a right angled triangle. */ /* The following algorithmtakesone value and squares it and then takes another value and squares it. It then gives the square root of the sum of those squares. */ Good Comment Bad Comment Er. Pradip Kharbuja •A comment should explain to people whatyou were doing, not howyou were doing it.
  31. 31. Terminologies •Qualities of Good Algorithm •Syntax •Arithmetic Operators •Desk-check •Flow of execution •Commenting Er. Pradip Kharbuja
  32. 32. Pseudocode Er. Pradip Kharbuja
  33. 33. Desk-Check with Null Values Line num1 num2 sum usertext Output Remarks 1 0 2 0 0 3 0 0 0 4 0 0 0 Null 5 10 0 0 Null 6 10 20 0 Null 7 10 20 30 Null 8 10 20 30 “The answeris” 9 10 20 30 “The answer is” “The answeris” Output 10 10 20 30 “The answer is” 30 Output
  34. 34. Desk Checking 1.Take 3 user inputs and find the sum. 2.Take length and breadth of the rectangle and find the area. Er. Pradip Kharbuja
  35. 35. Any Questions End of Topic -02 Er. Pradip Kharbuja

×