Download Pseudocode and Flowcharts: Creating Programs with Algorithms and more Lecture notes English in PDF only on Docsity! PSEUDOCODE & FLOWCHARTS 1 Levels of Program Development 2 1. Define the problem. Human thought 2. Plan the problem solution. writing the algorithm [pseudo-natural language (English, Arabic) or drawing the flowchart diagram). 3. Code the program. High Level Programming Language (C, C++, Java, …) 4. Compile the program. Machine Code 5. Run the program. 6. Test and debug the program. Pseudocode Example 5 Write a Program to Print the Sum of two integer Numbers 1. Start the program 2. Read the first number and save in the variable ( N1 ) 3. Read the second number and save in the variable ( N2 ) 4. Sum the both numbers and save the result in the variable ( Sum ) Sum = N1 + N2 5. Print the variable ( Sum ) 6. End the program Flowchart A flowchart is a type of diagram that represents an algorithm , showing the steps as boxes of various kinds [ex: rectangles, diamonds, ovals], and their order by connecting these with arrows. 6 Flowcharts Symbols 7 Start/End Read/Print Arithmetic Operations Decision , can be used with loops Start Read n1 N2 = 5 End Print n1 N2 = n1+3 n1 > 3 10 start Read Salary Print Total_Sal End Total_Sal = Salary +Overtime Solution Input Salary Overtime Processing Total_Sal = Salary +Overtime Output Total_Sal Read Overtime Example 3 11 Draw a flowchart for a program that calculates and prints the sum of the even integers from 2 to 30. Input No input. Processing Sum = 2+4+6+8+……+28+30. Output sum Solution 12 Pesudocode: Start the program Create a variable to hold a counter from 2 to 30. Initialize the counter to 2. Create a variable to hold the sum. Initialize the sum to zero. Loop While the counter is less-than-or-equal to 30 add the counter to the sum add two to the counter. repeat until the counter reach 30 Print the sum. End of program Solution
=
a a
“Below “A bowe
Freezing™ Freezing™
Example 5 Draw a flowchart for a program that accepts a person’s initial bank balance followed by a sequence of numbers representing transactions. A positive number represents a credit entry in the account and a negative number represents a debit entry. The input is terminated by a zero entry. The program should print the new balance. 16 Solution Input bank balance. transactions Processing balance = balance + transaction. Output balance 17 Solution Input amount. Processing Check if amount is below 1000 Zakat =0. Check if amount is above 1000 Zakat =(2.5/100) * amount Output Zakat 20 Solution 21 Start End Amount > 1000 Zakat =0. Print Zakat yes no Read amount Zakat =(2.5/100)*amount