100 likes | 130 Views
Lesson 5 Program Flowchart. Design tool commonly used in designing input, output and process flow of a program A graphical representation of the program logic using standard symbols (NCC Symbols) Using three primary program constructs; sequence, selection and iteration/repetition.
E N D
Lesson 5Program Flowchart • Design tool commonly used in designing input, output and process flow of a program • A graphical representation of the program logic using standard symbols (NCC Symbols) • Using three primary program constructs; sequence, selection and iteration/repetition
Three Program Constructs in Flowchart • Sequence • A sequential execution of process. Each instruction is executed in a serial manner, one after another • Selection • Provide a decision point that allows one of two choices to be chosen • Iteration • Repeat a set of instructions a number of times based on condition stated. This loop will end when condition has been fulfilled
Symbols Used in Program Flow Chart • Processing • Program flow • Decision • Terminal • Connector • Input/Output
Start Get number1 Get number2 answer = number1 / number2 Display answer Stop Sequence Example:
Start Get number1 Get number2 number2= 0? yes Display "Division by zero error" answer = number1 / number2 Display answer Stop Selection Example 1
Start Display main menu Get choice choice =1? yes Display "choice 1 selected" no choice =2? yes Display "choice 2 selected" no choice =3? yes Display "choice 3 selected" no choice =4? yes Display "choice 4 selected" no Stop Selection Example 2
Start total = 0 Get number number < 1000? no Display total Stop yes total = total + number2 Iteration Example 1
Start i = 1 i <= 12? no Stop yes result = i * 9 Display (i, "*9=",result) i = i + 1 Iteration Example 2
Connector Example • A program to accept input of a series of numbers and total up value entered until ‘0’ is entered. Then display number of data entered and total
Exercises • Draw a flowchart for a program that accepts an amount entered through the keyboard. Then, determine the discount rate allowed; 20% would be given to any purchase of more than $1000, 10% to purchase of more than $500 (inclusive). Display the discount given and also the amount after the deduction of the discount. • Draw a flowchart for a program which prompt the user to enter his/her name & age and determine whether he/she is an adult or not. If he/she is below 20 years old the user would be a teenager else he/she would be an adult. The user will be prompted after each person, if he/she wishes to enter anymore names. The program continues to run until the user enters ‘NO’ or ‘N’.