1 / 23

Pseudocode

Resource:. Pseudocode. Agenda. Intro to Pseudocode Pseudocode vs Flowchart Technique – Write pseudocode Examples. What’s Pseudocode ?. Artificial and Informal language Helps programmers to plan an algorithm Similar to everyday English Not an actual programming language.

hinto
Download Presentation

Pseudocode

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Resource: Pseudocode

  2. Agenda • Intro to Pseudocode • Pseudocode vs Flowchart • Technique – Write pseudocode • Examples

  3. What’s Pseudocode ? • Artificial and Informal language • Helps programmers to plan an algorithm • Similar to everyday English • Not an actual programming language

  4. E.g : Pseudocode Read A, B Calculate C = A*B Display C Stop

  5. Technique • Do not write Start in every pseudocode • Parallelogram – Read / Get OR Display / Print • Rectangle – Specify the actions • E.g: • Calculate A = B + C OR A equals to B plus C • Average = total / count • Final price equals price of item plus sales tax • Diamond – [Next »]

  6. Technique (..Cont.) • Diamond • Selection – IF , IF / ELSE and IF / ELSE IF IF A is less than B BIG = B SMALL = A ELSE BIG = A SMALL = B • Repetition – WHILE / DO/WHILE / FOR [Next example]

  7. Comparative Between Flowchart vsPseudocode • Flowchart • A graphical way of writing pseudocode • Rounded rectangle – terminal • Parallelogram – input / output • Rectangle – actions • Diamonds – decision / conditional • Circles – connector

  8. Start Terminal. Program start here Stop Terminal Program end here Input. Enter values for A and B Process Output E.g : Flowchart

  9. Comparative Between Flowchart vsPseudocode (..Cont.) • Pseudocode • No syntax rule – Independent from any programming language • Write in an ordinary language • Uses a structure resembling computer structure • No connector between pages

  10. E.g : Pseudocode Read A, B Calculate C = A*B Display C Stop

  11. E.g : Pseudocode Read A, B – Input Calculate C = A*B - Action Display C - Output Stop - Terminal

  12. Example 2 (Selection) Read A, B IF A is less than B BIG = B SMALL = A ELSE BIG = A SMALL = B Write / Display BIG, SMALL Stop

  13. Example 2 (Selection) Read A, B - Input IF A is less than B - Selection BIG = B - Action SMALL = A - Action ELSE - Selection BIG = A - Action SMALL = B - Action Write / Display BIG, SMALL - Output Stop - Terminal

  14. Example 3 (Repetition) Set count to zero Set total to zero Read number WHILE ( not end-of-data ) increment count by 1 total = total + number read number IF ( count > 0 ) then average = total / count Display average Stop

  15. Advantages • Converting a pseudocode to a programming language is much more easier than converting a flowchart. • As compared to flowchart, it is easier to modify a pseudocode of a program logic when program modifications are necessary.

  16. Limitations • In the cases of pseudocode, a graphic representation of program logic is not available. • There are no standard rules to follow for using a pseudocode. • Different programmers use their own style of writing pseudocode; and hence, • Communication problem occurs due to lack of standardization.

  17. Review - Pseudocode • An artificial and informal language that helps programmers develop algorithms • A "text-based" detail (algorithmic) design tool • “Write the steps before you write the code” (Matthew Morgenstern –Computer Scientist)

  18. Example – IF/ELSE Read student ‘s grade IF student's grade is greater than or equal to 60 Print "passed" ELSE Print "failed“ Stop

  19. Example - WHILE Set total to zero Set grade counter to one WHILE grade counter is less than or equal to ten Input the next grade Add the grade into the total Set the class average to the total divided by ten Print the class average Stop

  20. Example – WHILE & IF/ELSE Initialize total to zero Initialize counter to zero Input the first grade WHILE (0 <= grade <= 100) Add this grade into the total Add one to the grade counter Input the next grade (possibly the sentinel) IF the counter is not equal to zero Set the average to the total divided by the counter Print the average ELSE Print “no grades were entered” Stop

  21. Example – WHILE & IF/ELSE IF Initialize total to zero Initialize counter to zero Input the first grade WHILE (0 <= grade <= 100) Add this grade into the total Add one to the grade counter Input the next grade (possibly the sentinel) IF the counter is not equal to zero Set the average to the total divided by the counter Print the average ELSE Print “no grades were entered” IF (80 <= grade <= 100) Print “A” ELSE IF (60 <= grade <= 79) Print “B” ELSE IF (40 <= grade <= 59) Print “C” ELSE IF (0 <= grade <= 39) Print “Fail” Stop

  22. Example – WHILE & IF/ELSE IF Initialize total to zero Initialize counter to zero Input the first grade WHILE (0 <= grade <= 100) Add this grade into the total Add one to the grade counter Input the next grade (possibly the sentinel) IF the counter is not equal to zero Set the average to the total divided by the counter Print the average ELSE Print “no grades were entered” IF (80 <= grade <= 100) Print “A” ELSE IF (60 <= grade <= 79) Print “B” ELSE IF (40 <= grade <= 59) Print “C” ELSE IF (0 <= grade <= 39) Print “Fail” Stop

  23. EXAMPLE – WHILE & IF/ELSE Initialize passes to zero Initialize failures to zero Initialize student to one WHILE student counter is less than or equal to ten Input the next exam result IF the student passed Add one to passes ELSE Add one to failures Add one to student counter Print the number of passes Print the number of failures IF eight or more students passed Print "raise tuition“ Stop

More Related