Flowcharting and Algorithms

36
Flowcharting and Algorithms

description

Algorithms and Flowcharting

Transcript of Flowcharting and Algorithms

Flowcharting and Algorithms

A two-dimensional representation of an algorithm; the predefined graphic symbols of a flowchart are used to indicate the various operations and the flow of control.

A diagram representing the logical sequence in which a combination of steps or preparations is to be performed. It is a blueprint of the program.AlgorithmAlgorithm is a finite set of instructions that specify a sequence of operations to be carried out in order to solve a specific problem or class of problems.Basic Symbols Used in FlowchartingSymbols What it representsTerminal Used to signify the beginning and end of flowchartPreparation / Initialization Signifies the preparation of data

Used to select initial conditions

Used to represent instruction or group of instructions that will alter or modify a programs course of execution.Symbols What it representsInput / Output Shows input and output. Data are to be read into the computer memory from an input device or data are to be passed from the memory to an output deviceProcessing Performs any calculations that are to be doneDecision Signifies any decision that are to be done

Two alternative execution paths are possible. The path to be followed is selected during the execution by testing whether or not the condition specified within the outlined is fulfilled

Symbols What it representsOn-Page Connector Shows the entry or exit point of the flowchart

A non-processing symbol used to connect one part of a flowchart to another without drawing flowlines

Conserves space by keeping related blocks near one another, reduces, the number of flowlines in complex programs, and eliminates cross lines from taking placeOff-Page Connector Designates entry to or exit from one page when a flowchart requires more than one pageSymbols What it representsFlowlinesSignifies the process that is to be executedBasic Control StructuresSEQUENCE process is executed from one to another in a straightforward manner.Design a flowchart that will accept and display a number. Write its equivalent algorithms.Algorithm:

Step 1. Read in the value of N.Step 2. Print the value of N.StartRead NPrint NEndEXAMPLE!!!!Operators Commonly Used in FlowchartingArithmetic OperatorsOperatorsMeaning+Addition-Subtraction*Multiplication/DivisionRelational OperatorsOperatorsMeaning=Equal>Greater thanBStartInput A,BPrint B, HigherPrint A, HigherEndTFEXAMPLE!!!!Draw a chart that will input a grade of a student and determine whether the grade is passed or failed. Print the name , grade and remark of the student. Write its equivalent algorithmStartName= Remarks= Read Name, GradeGrade 60Remarks = FailedRemarks = PassedPrint Name, Grade, RemarksEndTFAlgorithm:Step 1. Initialize name and remarks into blanks.Step 2. Read in values for Grade and Name.Step 3. Test if Grade is greater than or equal to 60.Step 4. If Grade is greater than or equal to 60, remark is Passed. However, if Grade is below 60, remark is Failed.Step 5. Print the name, grade, and remarks.DEI Manufacturing Company plans to give a year-end bonus to each of its employee. Draw a flowchart which will compute the bonus of an employee. Consider the following conditions: If the employees monthly salary is less than 2,000.00, the bonus is 50% of the salary; for employees with the salaries greater than 2,000.00, the bonus is 1,500.00. Print the name and the corresponding bonus for each employee. Write each equivalent algorithms.ANSWERStartBonus = 0Read Name, SalarySalary < 2,000Bonus = 0.5*SalaryBonus = 1,500Print Name, BonusEndTFAlgorithm:Step 1. Initialize bonus to 0.Step 2. Read in employee's name and salary.Step 3. Test if employees salary is less than 2,000.Step 4. If salary < 2,000 then Bonus= salary * 50%else Bonus = 1,500.Step 5. Print the employees name and bonus.Using On-page connectorStartBonus = 0Read Name, SalarySalary < 2,000Bonus = 0.5*SalaryBonus = 1,500Print Name, BonusEndABFTABAssignmentConstruct a flowchart that will accept the evaluation score of a faculty and determine its equivalent remarks. Print the name of the faculty and the remarks obtained. Remarks (Rem) are based on the following criteria: Write its equivalent algorithms.

4.50 5.00 Outstanding4.00 4.49 Very Satisfactory3.50 3.99 Satisfactory3.00 3.49 Needs Improvement2.99 below Poor

Answer QuizRepetition (Looping)Do while this structure provides for the repetitive execution of an operation or routine while the condition is true. The condition is evaluated before executing any process statement. As long as the condition is true, the process is executed, otherwise, control flows out of the structure.CAFTConstruct a flowchart that will count from 1 to 10 and print each number counted using the do-while-repetition structure. Write its equivalent algorithm.StartC = 0C < 10C = C + 1Print CEndAlgorithm:Step 1. Initialize the value of C to 0.Step 2. Test if the C is less than 10,.Step 3. If C is less than 10, add 1 to the value of C, print the value then go back to Step 2. However, if C is greater than 10, stop processing.The initial value of the radius (R) of a circle is equal to 1 unit and each succeeding radius is 1 unit greater than the value before it. Draw a flowchart to compute the Area of a circle starting with R = 1 to R = 5, then print each radius and the corresponding area of a circle.StartPi = 3.14R = 1Area = Pi * R * RPrint R, AreaR= R + 1R 5EndFTAlgorithm:Step 1. Initialize the value of R to 1 and the value of Pi to 3.14Step 2. Compute the area by multiplying Pi to the square of R.Step 3. Print the value of R and the computed Area.Step 4. Increment the value of R by 1.Step 5. Test R if less than or equal to 5.Step6. If R is less than or equal to 5, loop back and repeat steps 2. to 5. However, if R is greater than 5, stop processing.AssignmentDraw a flowchart that will read and print the names and individual score of 50 students for a particular examination. Also, determine the average score and print it.Design a flowchart that will generate the sum and product of 20 input numbers.Construct a flowchart that will compute the evaluation rating of a teacher given by 32 students. Print the average.

Algorithm:Step1. Initialize Rem into space or blanks.Step2. Read in the values of Name and Score.Step3. Test the score if it is greater than or equal to 4.50.Step4. If the score is greater than or equal to 4.50, Rem is Outstanding. However, if the score is less than 4.50, do step 5.Step5. Test the score if it is greater than or equal to 4.00.Step6. If the score is greater than or equal to 4.00, Rem is Very Satisfactory. However, if the score is less than 4.00, do step 7.Step7. Test the score if it is greater than or equal to 3.50.Step8. If the score is greater than or equal to 3.50, Rem is Satisfactory. However, if the score is less than 3.50, do step 9.Step9. Test the score if its is greater than or equal to 3.00.Step10. If the score is greater than or equal to 3.00, Rem is Needs Improvement. However, if the score is less than 3.00, Rem is Poor.Step11. Print the name and Rem.SELECTIONGiven two numbers x and y, draw a flowchart to determine the difference between x and y. If x - y is negative, compute r = x + y; if x y is zero, compute r = 2x + 2y; and if x y is positive, compute r = x * y. Print the values of x, y, and r.Construct a flowchart that asks for the amount purchased by the customer. If the customer purchases more than 2,000 then a 5% discount is given. Display the net amount to be paid by the costumer.