SlideShare a Scribd company logo
MCS 1
Tariq Ali
What is pseudocode?
 List of steps written in English
 Like the instructions for a recipe
 Must be in the right sequence
   Imagine saying “bake the cake” and then “mix it up”
Sample Pseudocode
 Task: add two numbers
 Pseudocode:
    Start
    Get two numbers
       Get first number
       Get second number
   Add them
   Print the answer
   End
Pseudocode
  English language constructs modeled to look like
   statements available in most programming
   languages


  Steps presented in a structured manner
   (numbered, indented, and so on)


  No fixed syntax for most operations is required
Invitation to Computer
Science, Java Version, Third
Edition                        4
Pseudocode (continued)
  Less ambiguous and more readable than natural
   language

  Emphasis is on process, not notation

  Well-understood forms allow logical reasoning
   about algorithm behavior

  Can be easily translated into a programming
   language
Invitation to Computer Science,
Java Version, Third Edition     5
Sample Pseudocode
 Task: add two numbers
 Pseudocode:
    Start
    Get two numbers
       Get first number
       Get second number
   Add them
   Print the answer
   End
What does a flowchart look like?
  The pseudocode from the previous slide would look
  like this as a flowchart:


           Start
                                 Print answer
        Get 2 numbers
                                  End
          Add them
What are those funny symbols?

 START/END

 INPUT/OUTPUT

 PROCESS

 DECISION
What are those funny symbols?
  START/END
  Used at the beginning
  and end of each
  flowchart.
What are those funny symbols?



 INPUT/OUTPUT
 Shows when
 information/data comes
 into a program or is
 printed out.
What are those funny symbols?
What are those funny symbols?
  PROCESS
  Used to show
  calculations, storing of
  data in variables, and
  other “processes” that
  take place within a
  program.
What are those funny symbols?
What are those funny symbols?
  DECISION
  Used to show that the
  program must decide             Y
  whether something        X>7?
  (usually a comparison
                           N
  between numbers) is
  true or false. YES and
  NO (or T/F) branches
  are usually shown.
Another Sample:
Calculating Age
 Pseudocode:
    Start
    Get year DOB
    Calculate age = (sysdate-DOB)
    Print age
    If age > 50 print OLD
    End
Another Sample:
                                       Start
 Calculating Age
                                      Get yr


                                     Calc age

 Flowchart
    Start                           Print age

    Get year born
    Calculate age           OLD   Y Age>50?
    Print age
                                               N
    If age > 50 print OLD             End
    End
Self-Check
 Look at the flowchart section below. If the variable X is
  5, what will print (K or 1st)?



  Print “K”      N                 Y    Print “1st”
                         X > 5?
Self-Check
 Look at the flowchart section below. If the variable X is
  5, what will print (K or 1st)?



   Print “K”     N                   Y    Print “1st”
                         X > 5?



K will be printed. The answer to the question “Is X greater than 5
is NO, since X is equal to (not greater than) 5.
Self-Check
  Choose the correct
  flowchart symbol for each
  of these statements.
  AGE>65?
  Calc. Tax
  START
  Print NAME
Self-Check
  Choose the correct
  flowchart symbol for each
  of these statements.
  AGE>65?
  Calc. Tax
  START
  Print NAME
Challenge
 Try to write pseudocode and create a flowchart for a
  program that calculates the average of three grades
  and prints the average.
 The word GOOD should be printed only if the average
  is more than 80.
Challenge
 Possible pseudocode
    Start
    Get three grades
    Average them (add all of them / number of grads taken)
    Print Average
    Average>80?
       If Yes, print GOOD
   End
START

Challenge                                Get 3 grades
  Possible flowchart
    Start                               Calc avg
    Get three grades
    Average them
                                         Print avg
    Print Average
    Average>80?
                                     Y
        If Yes, print GOOD   GOOD       Avg>80?
    End
                                              N

                                           END
Challenge
 Try to write pseudocode and create a flowchart for a
  program that calculates the average of three grades
  and prints the average.
 The word GOOD should be printed only if the average
  is more than 80.
Challenge
 Possible pseudocode
    Start
    Get three grades
    Average them
    Print Average
    Average>80?
       If Yes, print GOOD
   End
START

Challenge                                Get 3 grades
  Possible flowchart
    Start                               Calc avg
    Get three grades
    Average them
                                         Print avg
    Print Average
    Average>80?
                                     Y
        If Yes, print GOOD   GOOD       Avg>80?
    End
                                              N

                                           END
 Algorithm for Computing Average Miles per
  Gallon
 Write a program to do the task: Print a list of the numbers
  from 4 to 9, next to each number, print the square of the
  number.
Programming fundamentals lecture 3
Programming fundamentals lecture 3

More Related Content

What's hot

Pseudocode By ZAK
Pseudocode By ZAKPseudocode By ZAK
Pseudocode By ZAK
Tabsheer Hasan
 
Writing algorithms
Writing algorithmsWriting algorithms
Writing algorithms
Krishna Chaytaniah
 
Algorithmsandflowcharts1
Algorithmsandflowcharts1Algorithmsandflowcharts1
Algorithmsandflowcharts1
Emmanuel Alimpolos
 
Algorithmsandflowcharts1
Algorithmsandflowcharts1Algorithmsandflowcharts1
Algorithmsandflowcharts1
ወዲ ህዝቢ
 
Algorithmsandflowcharts1
Algorithmsandflowcharts1Algorithmsandflowcharts1
Algorithmsandflowcharts1
rajnidhiman
 
Flowchart and algorithm
Flowchart and algorithmFlowchart and algorithm
Flowchart and algorithm
Sayali Shivarkar
 
Algorithm itabq
Algorithm itabqAlgorithm itabq
Algorithm itabq
mckennadglyn
 
Algorithms and flowcharts
Algorithms and flowchartsAlgorithms and flowcharts
Algorithms and flowcharts
khair20
 
Unit 3 Foc
Unit  3 FocUnit  3 Foc
Unit 3 Foc
JAYA
 
pseudocode and Flowchart
pseudocode and Flowchartpseudocode and Flowchart
pseudocode and Flowchart
ALI RAZA
 
Algorithm and psuedocode
Algorithm and psuedocodeAlgorithm and psuedocode
Algorithm and psuedocode
Mustafa Qureshi
 
algo
algoalgo
algo
Rao Khan
 
Problem solving and design
Problem solving and designProblem solving and design
Problem solving and design
Renée Howard-Johnson
 
Introduction to basic programming repetition
Introduction to basic programming repetitionIntroduction to basic programming repetition
Introduction to basic programming repetition
Jordan Delacruz
 
Grade 10 flowcharting
Grade 10  flowchartingGrade 10  flowcharting
Grade 10 flowcharting
Rafael Balderosa
 
Algorithms
AlgorithmsAlgorithms
Algorithms
nicky_walters
 
Flowchart
FlowchartFlowchart
Flowchart
Gautam Roy
 
4 coding from algorithms
4 coding from algorithms4 coding from algorithms
4 coding from algorithms
hccit
 
Penyelesaian masalah
Penyelesaian masalahPenyelesaian masalah
Penyelesaian masalah
Unit Kediaman Luar Kampus
 
Algorithm and pseudo codes
Algorithm and pseudo codesAlgorithm and pseudo codes
Algorithm and pseudo codes
hermiraguilar
 

What's hot (20)

Pseudocode By ZAK
Pseudocode By ZAKPseudocode By ZAK
Pseudocode By ZAK
 
Writing algorithms
Writing algorithmsWriting algorithms
Writing algorithms
 
Algorithmsandflowcharts1
Algorithmsandflowcharts1Algorithmsandflowcharts1
Algorithmsandflowcharts1
 
Algorithmsandflowcharts1
Algorithmsandflowcharts1Algorithmsandflowcharts1
Algorithmsandflowcharts1
 
Algorithmsandflowcharts1
Algorithmsandflowcharts1Algorithmsandflowcharts1
Algorithmsandflowcharts1
 
Flowchart and algorithm
Flowchart and algorithmFlowchart and algorithm
Flowchart and algorithm
 
Algorithm itabq
Algorithm itabqAlgorithm itabq
Algorithm itabq
 
Algorithms and flowcharts
Algorithms and flowchartsAlgorithms and flowcharts
Algorithms and flowcharts
 
Unit 3 Foc
Unit  3 FocUnit  3 Foc
Unit 3 Foc
 
pseudocode and Flowchart
pseudocode and Flowchartpseudocode and Flowchart
pseudocode and Flowchart
 
Algorithm and psuedocode
Algorithm and psuedocodeAlgorithm and psuedocode
Algorithm and psuedocode
 
algo
algoalgo
algo
 
Problem solving and design
Problem solving and designProblem solving and design
Problem solving and design
 
Introduction to basic programming repetition
Introduction to basic programming repetitionIntroduction to basic programming repetition
Introduction to basic programming repetition
 
Grade 10 flowcharting
Grade 10  flowchartingGrade 10  flowcharting
Grade 10 flowcharting
 
Algorithms
AlgorithmsAlgorithms
Algorithms
 
Flowchart
FlowchartFlowchart
Flowchart
 
4 coding from algorithms
4 coding from algorithms4 coding from algorithms
4 coding from algorithms
 
Penyelesaian masalah
Penyelesaian masalahPenyelesaian masalah
Penyelesaian masalah
 
Algorithm and pseudo codes
Algorithm and pseudo codesAlgorithm and pseudo codes
Algorithm and pseudo codes
 

Viewers also liked

Pf Day4
Pf Day4Pf Day4
Pf Day4
guest2abee9
 
pseudo code basics
pseudo code basicspseudo code basics
pseudo code basics
Sabik T S
 
Introduction to Pseudocode
Introduction to PseudocodeIntroduction to Pseudocode
Introduction to Pseudocode
Damian T. Gordon
 
Pseudocode haggis
Pseudocode   haggisPseudocode   haggis
Pseudocode haggis
missstevenson01
 
Program design techniques
Program design techniquesProgram design techniques
Program design techniques
fika sweety
 
Programming fundamentals lecture 1 0f c
Programming fundamentals lecture 1 0f cProgramming fundamentals lecture 1 0f c
Programming fundamentals lecture 1 0f c
Raja Hamid
 
03 pseudocode
03 pseudocode03 pseudocode
03 pseudocode
Indra Abdam Muwakhid
 
Programming fundamentals lecture 1&2
Programming fundamentals lecture 1&2Programming fundamentals lecture 1&2
Programming fundamentals lecture 1&2
Raja Hamid
 
Fundamental Programming Lect 1
Fundamental Programming Lect 1Fundamental Programming Lect 1
Fundamental Programming Lect 1
Namrah Erum
 
Programming Fundamentals
Programming FundamentalsProgramming Fundamentals
Programming Fundamentals
Trivuz ত্রিভুজ
 
Flowchart pseudocode-examples
Flowchart pseudocode-examplesFlowchart pseudocode-examples
Flowchart pseudocode-examples
Gautam Roy
 
Pseudocode flowcharts
Pseudocode flowchartsPseudocode flowcharts
Pseudocode flowcharts
nicky_walters
 
Algorithmsandflowcharts1
Algorithmsandflowcharts1Algorithmsandflowcharts1
Algorithmsandflowcharts1
luhkahreth
 
Algorithms and Flowcharts
Algorithms and FlowchartsAlgorithms and Flowcharts
Algorithms and Flowcharts
Deva Singh
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
Elizabeth de Leon Aler
 

Viewers also liked (15)

Pf Day4
Pf Day4Pf Day4
Pf Day4
 
pseudo code basics
pseudo code basicspseudo code basics
pseudo code basics
 
Introduction to Pseudocode
Introduction to PseudocodeIntroduction to Pseudocode
Introduction to Pseudocode
 
Pseudocode haggis
Pseudocode   haggisPseudocode   haggis
Pseudocode haggis
 
Program design techniques
Program design techniquesProgram design techniques
Program design techniques
 
Programming fundamentals lecture 1 0f c
Programming fundamentals lecture 1 0f cProgramming fundamentals lecture 1 0f c
Programming fundamentals lecture 1 0f c
 
03 pseudocode
03 pseudocode03 pseudocode
03 pseudocode
 
Programming fundamentals lecture 1&2
Programming fundamentals lecture 1&2Programming fundamentals lecture 1&2
Programming fundamentals lecture 1&2
 
Fundamental Programming Lect 1
Fundamental Programming Lect 1Fundamental Programming Lect 1
Fundamental Programming Lect 1
 
Programming Fundamentals
Programming FundamentalsProgramming Fundamentals
Programming Fundamentals
 
Flowchart pseudocode-examples
Flowchart pseudocode-examplesFlowchart pseudocode-examples
Flowchart pseudocode-examples
 
Pseudocode flowcharts
Pseudocode flowchartsPseudocode flowcharts
Pseudocode flowcharts
 
Algorithmsandflowcharts1
Algorithmsandflowcharts1Algorithmsandflowcharts1
Algorithmsandflowcharts1
 
Algorithms and Flowcharts
Algorithms and FlowchartsAlgorithms and Flowcharts
Algorithms and Flowcharts
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
 

Similar to Programming fundamentals lecture 3

Spss lecture notes
Spss lecture notesSpss lecture notes
Spss lecture notes
David mbwiga
 
programming.ppt
programming.pptprogramming.ppt
programming.ppt
AdrianVANTOPINA
 
ICT_Seminar_flow_charts_for_2013_Nov.pptx
ICT_Seminar_flow_charts_for_2013_Nov.pptxICT_Seminar_flow_charts_for_2013_Nov.pptx
ICT_Seminar_flow_charts_for_2013_Nov.pptx
ssuser2f67c91
 
Algorithms&flowcharts
Algorithms&flowchartsAlgorithms&flowcharts
Programming algorithms and flowchart.ppt
Programming algorithms and flowchart.pptProgramming algorithms and flowchart.ppt
Programming algorithms and flowchart.ppt
VictorMorcillo1
 
Introduction To SPSS
Introduction To SPSSIntroduction To SPSS
Introduction To SPSS
ThankGod Damion Okpe
 
Please help. C++ The program is an interactive program th.pdf
Please help. C++ The program is an interactive program th.pdfPlease help. C++ The program is an interactive program th.pdf
Please help. C++ The program is an interactive program th.pdf
fsenterprises
 
Learn Programming with Livecoding.tv http://goo.gl/tIgO1I
Learn Programming with Livecoding.tv http://goo.gl/tIgO1ILearn Programming with Livecoding.tv http://goo.gl/tIgO1I
Learn Programming with Livecoding.tv http://goo.gl/tIgO1I
livecoding.tv
 
Programming
ProgrammingProgramming
Programming
Leo Simon Anfone
 
Baabtra.com little coder chapter - 5
Baabtra.com little coder   chapter - 5Baabtra.com little coder   chapter - 5
Baabtra.com little coder chapter - 5
baabtra.com - No. 1 supplier of quality freshers
 
ALGORITHM PPT GUIDE.pdf
ALGORITHM PPT GUIDE.pdfALGORITHM PPT GUIDE.pdf
ALGORITHM PPT GUIDE.pdf
meychu1
 
Algorithms&flowcharts
Algorithms&flowchartsAlgorithms&flowcharts
Basic computer-programming-2
Basic computer-programming-2Basic computer-programming-2
Basic computer-programming-2
lemonmichelangelo
 
SPS intro
SPS introSPS intro
Introduction to Python - Training for Kids
Introduction to Python - Training for KidsIntroduction to Python - Training for Kids
Introduction to Python - Training for Kids
Aimee Maree Forsstrom
 
spss intro.ppt
spss intro.pptspss intro.ppt
spss intro.ppt
KENNEDY GITHAIGA
 
Introduction to Programming and QBasic Tutorial
Introduction to Programming and QBasic TutorialIntroduction to Programming and QBasic Tutorial
Introduction to Programming and QBasic Tutorial
nhomz
 
Mathematics for 6th Grade: Numbers and Number Sense
Mathematics for 6th Grade: Numbers and Number SenseMathematics for 6th Grade: Numbers and Number Sense
Mathematics for 6th Grade: Numbers and Number Sense
Bridgette Mackey
 
Q basic ch
Q basic chQ basic ch
Q basic ch
ssuser39dff5
 
Algorithms and flowcharts
Algorithms and flowchartsAlgorithms and flowcharts
Algorithms and flowcharts
Samuel Igbanogu
 

Similar to Programming fundamentals lecture 3 (20)

Spss lecture notes
Spss lecture notesSpss lecture notes
Spss lecture notes
 
programming.ppt
programming.pptprogramming.ppt
programming.ppt
 
ICT_Seminar_flow_charts_for_2013_Nov.pptx
ICT_Seminar_flow_charts_for_2013_Nov.pptxICT_Seminar_flow_charts_for_2013_Nov.pptx
ICT_Seminar_flow_charts_for_2013_Nov.pptx
 
Algorithms&flowcharts
Algorithms&flowchartsAlgorithms&flowcharts
Algorithms&flowcharts
 
Programming algorithms and flowchart.ppt
Programming algorithms and flowchart.pptProgramming algorithms and flowchart.ppt
Programming algorithms and flowchart.ppt
 
Introduction To SPSS
Introduction To SPSSIntroduction To SPSS
Introduction To SPSS
 
Please help. C++ The program is an interactive program th.pdf
Please help. C++ The program is an interactive program th.pdfPlease help. C++ The program is an interactive program th.pdf
Please help. C++ The program is an interactive program th.pdf
 
Learn Programming with Livecoding.tv http://goo.gl/tIgO1I
Learn Programming with Livecoding.tv http://goo.gl/tIgO1ILearn Programming with Livecoding.tv http://goo.gl/tIgO1I
Learn Programming with Livecoding.tv http://goo.gl/tIgO1I
 
Programming
ProgrammingProgramming
Programming
 
Baabtra.com little coder chapter - 5
Baabtra.com little coder   chapter - 5Baabtra.com little coder   chapter - 5
Baabtra.com little coder chapter - 5
 
ALGORITHM PPT GUIDE.pdf
ALGORITHM PPT GUIDE.pdfALGORITHM PPT GUIDE.pdf
ALGORITHM PPT GUIDE.pdf
 
Algorithms&flowcharts
Algorithms&flowchartsAlgorithms&flowcharts
Algorithms&flowcharts
 
Basic computer-programming-2
Basic computer-programming-2Basic computer-programming-2
Basic computer-programming-2
 
SPS intro
SPS introSPS intro
SPS intro
 
Introduction to Python - Training for Kids
Introduction to Python - Training for KidsIntroduction to Python - Training for Kids
Introduction to Python - Training for Kids
 
spss intro.ppt
spss intro.pptspss intro.ppt
spss intro.ppt
 
Introduction to Programming and QBasic Tutorial
Introduction to Programming and QBasic TutorialIntroduction to Programming and QBasic Tutorial
Introduction to Programming and QBasic Tutorial
 
Mathematics for 6th Grade: Numbers and Number Sense
Mathematics for 6th Grade: Numbers and Number SenseMathematics for 6th Grade: Numbers and Number Sense
Mathematics for 6th Grade: Numbers and Number Sense
 
Q basic ch
Q basic chQ basic ch
Q basic ch
 
Algorithms and flowcharts
Algorithms and flowchartsAlgorithms and flowcharts
Algorithms and flowcharts
 

Programming fundamentals lecture 3

  • 2. What is pseudocode?  List of steps written in English  Like the instructions for a recipe  Must be in the right sequence  Imagine saying “bake the cake” and then “mix it up”
  • 3. Sample Pseudocode  Task: add two numbers  Pseudocode:  Start  Get two numbers  Get first number  Get second number  Add them  Print the answer  End
  • 4. Pseudocode  English language constructs modeled to look like statements available in most programming languages  Steps presented in a structured manner (numbered, indented, and so on)  No fixed syntax for most operations is required Invitation to Computer Science, Java Version, Third Edition 4
  • 5. Pseudocode (continued)  Less ambiguous and more readable than natural language  Emphasis is on process, not notation  Well-understood forms allow logical reasoning about algorithm behavior  Can be easily translated into a programming language Invitation to Computer Science, Java Version, Third Edition 5
  • 6. Sample Pseudocode  Task: add two numbers  Pseudocode:  Start  Get two numbers  Get first number  Get second number  Add them  Print the answer  End
  • 7. What does a flowchart look like?  The pseudocode from the previous slide would look like this as a flowchart: Start Print answer Get 2 numbers End Add them
  • 8. What are those funny symbols?  START/END  INPUT/OUTPUT  PROCESS  DECISION
  • 9. What are those funny symbols?  START/END  Used at the beginning and end of each flowchart.
  • 10. What are those funny symbols?  INPUT/OUTPUT  Shows when information/data comes into a program or is printed out.
  • 11. What are those funny symbols? What are those funny symbols?  PROCESS  Used to show calculations, storing of data in variables, and other “processes” that take place within a program.
  • 12. What are those funny symbols? What are those funny symbols?  DECISION  Used to show that the program must decide Y whether something X>7? (usually a comparison N between numbers) is true or false. YES and NO (or T/F) branches are usually shown.
  • 13. Another Sample: Calculating Age  Pseudocode:  Start  Get year DOB  Calculate age = (sysdate-DOB)  Print age  If age > 50 print OLD  End
  • 14. Another Sample: Start Calculating Age Get yr Calc age  Flowchart  Start Print age  Get year born  Calculate age OLD Y Age>50?  Print age N  If age > 50 print OLD End  End
  • 15. Self-Check  Look at the flowchart section below. If the variable X is 5, what will print (K or 1st)? Print “K” N Y Print “1st” X > 5?
  • 16. Self-Check  Look at the flowchart section below. If the variable X is 5, what will print (K or 1st)? Print “K” N Y Print “1st” X > 5? K will be printed. The answer to the question “Is X greater than 5 is NO, since X is equal to (not greater than) 5.
  • 17. Self-Check  Choose the correct flowchart symbol for each of these statements.  AGE>65?  Calc. Tax  START  Print NAME
  • 18. Self-Check  Choose the correct flowchart symbol for each of these statements.  AGE>65?  Calc. Tax  START  Print NAME
  • 19. Challenge  Try to write pseudocode and create a flowchart for a program that calculates the average of three grades and prints the average.  The word GOOD should be printed only if the average is more than 80.
  • 20. Challenge  Possible pseudocode  Start  Get three grades  Average them (add all of them / number of grads taken)  Print Average  Average>80?  If Yes, print GOOD  End
  • 21. START Challenge Get 3 grades  Possible flowchart  Start Calc avg  Get three grades  Average them Print avg  Print Average  Average>80? Y  If Yes, print GOOD GOOD Avg>80?  End N END
  • 22. Challenge  Try to write pseudocode and create a flowchart for a program that calculates the average of three grades and prints the average.  The word GOOD should be printed only if the average is more than 80.
  • 23. Challenge  Possible pseudocode  Start  Get three grades  Average them  Print Average  Average>80?  If Yes, print GOOD  End
  • 24. START Challenge Get 3 grades  Possible flowchart  Start Calc avg  Get three grades  Average them Print avg  Print Average  Average>80? Y  If Yes, print GOOD GOOD Avg>80?  End N END
  • 25.
  • 26.  Algorithm for Computing Average Miles per Gallon
  • 27.
  • 28.  Write a program to do the task: Print a list of the numbers from 4 to 9, next to each number, print the square of the number.