Introduction to Flowcharting Computer Science Principles 2013 2014
- Slides: 32
Introduction to Flowcharting Computer Science Principles 2013 -2014 ASFA 1
What is a Flowchart? • A flowchart is a diagram that depicts the “flow” of a program. • The figure shown here is a flowchart for the pay-calculating program shown in Program 1 -1. START Display message “How many hours did you work? ” Read Hours Display message “How much do you get paid per hour? ” Read Pay. Rate Multiply Hours by Pay. Rate. Store result in Gross. Pay. Display Gross. Pay END 2
Basic Flowchart Symbols START Terminal Display message “How many hours did you work? ” • Terminals Read Hours – represented by rounded rectangles – indicate a starting or ending point Display message “How much do you get paid per hour? ” Read Pay. Rate Multiply Hours by Pay. Rate. Store result in Gross. Pay. START Display Gross. Pay END Terminal END 3
Basic Flowchart Symbols • Input/Output Operations – represented by parallelograms – indicate an input or output operation Display message “How many hours did you work? ” START Display message “How many hours did you work? ” Read Hours Display message “How much do you get paid per hour? ” Input/Output Operation Read Pay. Rate Multiply Hours by Pay. Rate. Store result in Gross. Pay. Read Hours Display Gross. Pay END 4
Basic Flowchart Symbols START Display message “How many hours did you work? ” • Processes Read Hours – represented by rectangles – indicates a process such as a mathematical computation or variable assignment Multiply Hours by Pay. Rate. Store result in Gross. Pay. Display message “How much do you get paid per hour? ” Read Pay. Rate Process Multiply Hours by Pay. Rate. Store result in Gross. Pay. Display Gross. Pay END 5
Four Flowchart Structures • • Sequence Decision Repetition Case 6
Sequence Structure • A series of actions are performed in sequence • The pay-calculating example was a sequence flowchart. 7
Decision Structure • The flowchart segment below shows how a decision structure is expressed in C++ as an if/else statement. Flowchart NO C++ Code YES x < y? if (x < y) a = x * 2; else Calculate a as x plus y. Calculate a as x times 2. a = x + y; 8
Decision Structure • The flowchart segment below shows a decision structure with only one action to perform. It is expressed as an if statement in C++ code. Flowchart C++ Code NO YES x < y? if (x < y) a = x * 2; Calculate a as x times 2. 9
Repetition Structure • The flowchart segment below shows a repetition structure expressed in C++ as a while loop. Flowchart C++ Code while (x < y) x < y? x++; YES Add 1 to x 10
Controlling a Repetition Structure • The action performed by a repetition structure must eventually cause the loop to terminate. Otherwise, an infinite loop is created. • In this flowchart segment, x is never changed. Once the loop starts, it will never end. • QUESTION: How can this YES flowchart be modified so x < y? Display x it is no longer an infinite loop? 11
Controlling a Repetition Structure • ANSWER: By adding an action within the repetition that changes the value of x. YES x < y? Display x Add 1 to x 12
Case Structure If years_employed = 2, bonus is set to 200 If years_employed = 1, bonus is set to 100 1 bonus = 100 If years_employed = 3, bonus is set to 400 If years_employed is any other value, bonus is set to 800 CASE years_employed 2 3 bonus = 200 bonus = 400 Other bonus = 800 13
Connectors • The “A” connector indicates that the second flowchart segment begins where the first segment ends. START A END A 14
Modules • The position of the module symbol indicates the point the module is executed. • A separate flowchart can be constructed for the module. START Read Input. Call calc_pay function. Display results. END 15
Combining Structures • This flowchart segment shows two decision NO structures combined. Display “x is outside the limits. ” YES x > min? NO YES x < max? Display “x is outside the limits. ” Display “x is within limits. ” 16
Review • What do each of the following symbols represent? (Answer on next slide) 17
Answer • What do each of the following symbols represent? Terminal Input/Output Operation Process Decision Connector Module 18
Review • Name the four flowchart structures. (Answer on next slide) 19
Answer • • Sequence Decision Repetition Case 20
Review • What type of structure is this? (Answer on next slide) 21
Answer • Repetition 22
Review • What type of structure is this? (Answer on next slide) 23
Answer • Sequence 24
Review • What type of structure is this? (Answer on next slide) 25
Answer • Case 26
Review • What type of structure is this? (Answer on next slide) 27
Answer • Decision 28
29
30
31
Examples ? ? ? 32
- Control chart precision accuracy pmp
- Her favourite subject be english
- What is sequencing apcsp
- Science fusion introduction to science and technology
- Introduction to computer science midterm exam
- Introduction to computer science midterm exam test
- C++ code
- Python programming an introduction to computer science
- Coso 2013 internal control framework
- Computer concepts 2014
- Introduction to ms word 2013
- What is the third fundamental principle of fingerprints
- Applied principles of horticultural science
- Principles of science
- Principles of animal nutrition
- Natural vs social science
- Natural physical science
- Natural and physical science
- Applied science vs pure science
- Anthropology vs sociology
- Rule of 70 in population growth
- Julie lundquist
- Hard and soft science
- Computer security principles and practice
- Computer security principles and practice solutions
- Build a modern computer from first principles
- Principles of network applications in computer networks
- Principles of human computer interaction
- Principles of congestion control in computer networks
- Design objectives of computer clusters
- Computer security principles and practice 4th edition
- Design in output
- Principles of computer security