Presentation on theme: "Chapter 1 Pseudocode & Flowcharts"— Presentation transcript:
1 Chapter 1 Pseudocode & Flowcharts 1st Semester H
2 Levels of Program Development Define the problem. Human thoughtPlan the problem solution. writing the algorithm [pseudo-natural language (English, Arabic) or drawing the flowchart diagram).Code the program. High Level Programming Language (C, C++, Java, …)Compile the program. Machine CodeRun the program.Test and debug the program.
3 From Lec1 we learned that When planning for a problem solution, algorithms are used to outline the solution steps usingEnglish like statements, called pseudocode.orA flowchart , which is a graphical representation of an algorithm.
4 PseudocodePseudocode is a detailed description of what a computer program must do, expressed in an English like language rather than in a programming language.
5 Pseudocode ExampleWrite a Program to Print the Sum of two integer NumbersStart the programRead the first number and save in the variable ( N1 )Read the second number and save in the variable ( N2 )Sum the both numbers and save the result in the variable ( Sum ) Sum = N1 + N2Print the variable ( Sum )End the program
6 FlowchartA 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.
7 Flowcharts Symbols Start/End Start End Read/Print Print n1 Read n1 Arithmetic OperationsN2 = n1+3N2 = 5Decision , can be used with loopsn1 > 3
8 Example1 start Draw a flowchart for a program that calculates and print the area and the perimeter ofa rectangle.InputLengthwidthProcessingArea = length*widthPerimeter = 2*( length + width)OutputAreaPerimeterRead L, Warea = L * Wperimeter = 2 (L+W)Print areaPrint perimeterEnd
9 Total_Sal = Salary +Overtime Example 2Draw the flow chart for a program that calculates the total salary for an employee using this equation:Total_Sal = Salary +Overtime
11 Example 3Draw a flowchart for a program that determine if the temperature degree is above or below freezing.InputTemp.ProcessingCheck if Temp is below the 32 below freezing.Check if Temp is above the 32 above freezing.OutputPrint “below freezing” or “above freezing”
13 Example 4Draw a flowchart for a program that calculates the Zakat, where the user enter the amount of money then the program show the zakat.Zakat =(2.5/100) * amount.Zakat is not calculated if the amount is less than S.R
14 Solution Input amount. Processing Check if amount is below 1000 Zakat =0.Check if amount is above 1000 Zakat =(2.5/100) * amountOutputZakat
16 Solution no Start Read amount yes Amount > 1000 Zakat =(2.5/100)*amountPrint there is no ZakatPrint ZakatEnd
17 More ExamplesDraw a flowchart to read a student’s three grades, calculate the average of the grades, then display the average grade.Draw a flowchart for a program that reads the height, length, and width of a rectangular box, calculates and displays the volume Note: volume = height * length * width
18 More Examples Draw a flowchart to find the largest of three numbers. Draw a flowchart to reads the salary of an employee and prints:"Manager" if the salary is above 20000,"Supervisor" if the salary is above 15000,"Technician" if the salary is above 8000.
19 More ExamplesDraw a flowchart for a program that asks the user to enter two numbers. Then the user should be prompted to enter a 1 to add these numbers or a 2 to multiply these numbers. If the user does not enter 1 or 2 an error message should appear.