Introduction to Flowcharting 1 Writing a program Defining

  • Slides: 25
Download presentation
Introduction to Flowcharting 1

Introduction to Flowcharting 1

Writing a program • Defining the problem – Write down what the program will

Writing a program • Defining the problem – Write down what the program will do • Planning – Write down the steps, draw a flowchart • Programming – Coding, including errors correction, testing • Documenting – Adding comments • Implementing – Improvement, making the program better 2

Objective • A program can be divided into 3 parts: – Input data –

Objective • A program can be divided into 3 parts: – Input data – Processing data – Calculation, etc. – Output information/results Input Processing Output 3

Arrows • From Top to Bottom & from Left to Right • Make turn

Arrows • From Top to Bottom & from Left to Right • Make turn • Join together 4

What is a Flowchart? • A flowchart is a diagram that depicts the “flow”

What is a Flowchart? • A flowchart is a diagram that depicts the “flow” of a program. • A diagram made up of symbols of various shapes connected by arrows. • Those symbols indicate either actions to be taken or decisions to be made. • It helps us planning & programming. • The figure shown here is a flowchart for a pay-calculating program. 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 5

Basic Flowchart Symbols START Display message “How many hours did you work? ” •

Basic Flowchart Symbols START Display message “How many hours did you work? ” • Notice there are three types of symbols in this flowchart: – rounded rectangles – parallelograms – a rectangle • Each symbol represents a different type of operation. Rounded Rectangle Read Hours Display message “How much do you get paid per hour? ” Parallelogram Read Pay. Rate Rectangle Rounded Rectangle Multiply Hours by Pay. Rate. Store result in Gross. Pay. Display Gross. Pay END 6

Basic Flowchart Symbols START Terminal Display message “How many hours did you work? ”

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 7

Basic Flowchart Symbols • Input/Output Operations – represented by parallelograms – indicate an input

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 8

Basic Flowchart Symbols START Display message “How many hours did you work? ” •

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 9

Stepping Through the Flowchart In the next seven slides we will step through each

Stepping Through the Flowchart In the next seven slides we will step through each symbol in the flowchart. We will show the program output and the contents of the variables. Variable Contents: Hours: ? Pay. Rate: ? Gross. Pay: ? 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 10

Stepping Through the Flowchart How many hours did you work? Screen Output START Display

Stepping Through the Flowchart How many hours did you work? Screen Output START Display message “How many hours did you work? ” Step 1: An Output Operation Read Hours Display message “How much do you get paid per hour? ” Read Pay. Rate Variable Contents: Hours: ? Pay. Rate: ? Gross. Pay: ? Multiply Hours by Pay. Rate. Store result in Gross. Pay. Display Gross. Pay END 11

Stepping Through the Flowchart How many hours did you work? 40 Step 2: An

Stepping Through the Flowchart How many hours did you work? 40 Step 2: An Input Operation (User types 40) START Display message “How many hours did you work? ” Read Hours Display message “How much do you get paid per hour? ” Read Pay. Rate Variable Contents: Hours: 40 Pay. Rate: ? Gross. Pay: ? Multiply Hours by Pay. Rate. Store result in Gross. Pay. The value 40 is stored in Hours. Display Gross. Pay END 12

Stepping Through the Flowchart How much do you get paid per hour? Screen Output

Stepping Through the Flowchart How much do you get paid per hour? Screen Output Step 3: An Output Operation START Display message “How many hours did you work? ” Read Hours Display message “How much do you get paid per hour? ” Read Pay. Rate Variable Contents: Hours: 40 Pay. Rate: ? Gross. Pay: ? Multiply Hours by Pay. Rate. Store result in Gross. Pay. Display Gross. Pay END 13

Stepping Through the Flowchart Display message “How many hours did you work? ” Read

Stepping Through the Flowchart Display message “How many hours did you work? ” Read Hours How much do you get paid per hour? 20 Display message “How much do you get paid per hour? ” Step 4: Input Operation (User types 20) Variable Contents: Hours: 40 Pay. Rate: 20 Gross. Pay: ? START The value 20 is stored in Pay. Rate. Read Pay. Rate Multiply Hours by Pay. Rate. Store result in Gross. Pay. Display Gross. Pay END 14

Stepping Through the Flowchart START Display message “How many hours did you work? ”

Stepping Through the Flowchart START Display message “How many hours did you work? ” Read Hours How much do you get paid per hour? 20 Step 5: The product of Hours times Pay. Rate is stored in Gross. Pay Display message “How much do you get paid per hour? ” Read Pay. Rate Variable Contents: Hours: 40 Pay. Rate: 20 Gross. Pay: 800 Multiply Hours by Pay. Rate. Store result in Gross. Pay. The value 800 is stored in Gross. Pay. Display Gross. Pay END 15

Stepping Through the Flowchart Your gross pay is 800 Screen Output START Display message

Stepping Through the Flowchart Your gross pay is 800 Screen Output START Display message “How many hours did you work? ” Read Hours Display message “How much do you get paid per hour? ” Read Pay. Rate Variable Contents: Hours: 40 Pay. Rate: 20 Gross. Pay: 800 Multiply Hours by Pay. Rate. Store result in Gross. Pay. Step 6: An Output Operation Display Gross. Pay END 16

Four Flowchart Structures • • Sequence (TODAY) Decision Repetition Case 17

Four Flowchart Structures • • Sequence (TODAY) Decision Repetition Case 17

Sequence Structure • A series of actions are performed in sequence • The pay-calculating

Sequence Structure • A series of actions are performed in sequence • The pay-calculating example was a sequence flowchart. 18

Connectors • Sometimes a flowchart will not fit on one page. • A connector

Connectors • Sometimes a flowchart will not fit on one page. • A connector (represented by a small circle) allows you to connect two flowchart segments. A 19

Connectors • The “A” connector indicates that the second flowchart segment begins where the

Connectors • The “A” connector indicates that the second flowchart segment begins where the first segment ends. START A END A 20

Review • What do each of the following symbols represent? (Answer on next slide)

Review • What do each of the following symbols represent? (Answer on next slide) 21

Answer • What do each of the following symbols represent? Terminal Input/Output Operation Process

Answer • What do each of the following symbols represent? Terminal Input/Output Operation Process 22

Review • Name the four flowchart structures. (Answer on next slide) 23

Review • Name the four flowchart structures. (Answer on next slide) 23

Answer • • Sequence Decision Repetition Case 24

Answer • • Sequence Decision Repetition Case 24

Flowcharting Problems Write out the steps to solve the problem, then draw the diagram

Flowcharting Problems Write out the steps to solve the problem, then draw the diagram 1. Flowchart a program to input the radius of a circle, and then calculate and print the area. The formula is Area = Pi * Radius 2 2. Flowchart a program that will input four marks and calculate the average. 3. Flowchart a program that will take a temperature in Fahrenheit (F) convert it to Centigrade (C) The formulas are below. • C = ( F - 32) / 1. 8 – Output the results with a message that states: “ ___ degrees C is equal to ___ degrees F” 25