Sei sulla pagina 1di 83

Module 1

Flowcharting & Flowgorithm


Objectives
• Define flowchart and state the purpose of flowchart;
• Identify, describe, and draw the standard symbols
used in flowchart;
• State some advantages and disadvantages of using
flowchart; and
• Solve engineering machine problems using flowchart;
• Use flowgorithm tool to apply flowchart.
Flowcharting
• Flowcharting
– Visual representation of sequence of steps needed to
perform a process.
– Used in designing and documenting simple processes
or computer programs.
– Widely used to document, study, plan, improve and
communicate complex processes in clear, easy-to-
understand diagrams
Advantage of using Flowchart
• Communication
– Better way of communicating the logic of a system to all
concerned.

• Effective analysis
– Problem can be analyzed in more effective way.

• Proper documentation
– Serves as good program documentation which is needed
for various purposes.
Advantage of using Flowchart
• Efficient Coding
– Acts as guide or blueprint during systems analysis and
program development phase.

• Proper Debugging
– Helps in debugging process.

• Efficient Program Maintenance


– Helps programmer to put efforts more efficiently on the
easy maintenance of the program.
Limitation of using Flowchart
• Complex logic
– Program logic is quite complicated, thus, using flowchart
becomes complex and clumsy.
• Alterations and Modifications
– If changes are required, it may require re-drawing
completely.
• Reproduction
– As the flowchart symbols cannot be typed, reproduction of
flowchart becomes a problem.

• The essentials of what is done can easily be lost in


the technical details of how it is done.
Sample Structure of Flowchart
• Draw a flowchart to log in to facebook account
Common Symbols
• Terminal Terminal • Flow Lines
• Declare • On-page connector
Declare
A

• Off-page connector
• Process Process
Off-Page

• Input/Output Input /
Output • Predefined process /Call
function Predefined
Process
• Decision / If Decision
Common Symbols
• Looping / Repetition • Document
Document
While

• Data File
For
Database

Do
Machine Problem #1
• Create a simple flowchart that displays “Hello
World” on the screen.
Main

Output “Hello World”

End
Machine Problem #2
• Create a flowchart that inputs two integer numbers.
Compute and display the sum of the two numbers on
the screen. A B
Main
Output Sum = N1 + N2
“Enter first number”
Integer N1
Output
Input N1
Sum
Integer N2
Output
End
“Enter second number”
Integer Sum
Input N2

A
B
Machine Problem #3
• Create a flowchart that allows user to input the radius
of the circle. Compute and display the area of the
circle.
Main x

Integer R Input R

Real Area Area = 3.1416 * R^2

Output Output
“Input radius” “Area:” & Area

x End
Some guidelines in flowcharting:
• In drawing a flowchart, all necessary requirements
should be listed out in logical order.
• Flowchart should be clear, neat and easy to follow.
No room for ambiguity in understanding it.
• Usual direction of the flow of a procedure or system
is from left to right or top to bottom.
• Test validity of the flowchart by passing through it
with a simple test data.
Available Flowchart Tools
Drawing Programs Visual Programming
• Dia languages
• Flowgorithm
• yEd
• Raptor

• Inkscape • LARP

• Visual Logic
• Microsoft Visio
• VisiRule
• Free programming language that is based on simple
graphical flowcharts.

• Double click the flowgorithm icon


Do MP#1 using Flowgorithm

Save as MP1.fprg
Do MP#2 using
Flowgorithm

Save as MP2.fprg
Do MP#3 using
Flowgorithm

Save as MP3.fprg
Exercises
• Create a flowchart that:
1. Reads the length and the width of the rectangle.
Compute and display the Area and Perimeter of
the rectangle. Save as MP4.fprg

2. Reads the radius of the circle. Compute and


display the diameter and circumference of the
circle. Save as MP5.fprg

3. Inputs the base and the height of the right


triangle. Calculate and display the hypotenuse
and the Area of the right triangle.
Save as MP6.fprg
1 2 3
Exercises
• Create a flowchart that:
4. Reads the locations of the 2 points <say P1 with
(X1, Y1) and P2 with (X2,Y2)> in the Cartesian
coordinate system. Compute and display the
distance between the 2 points. Also, compute the
midpoints of the points.
Formula to use:
dist = (2 − 1) + (
2 −
1)
mid x = ⁄ (1 + 2) mid y = ⁄ (
1 +
2)

Save as MP7.fprg
Flowgorithm Data Types
Flowgorithm Operator Precedence
Flowgorithm Operators
Built-in Functions
Built-in Constants
Exercises: Your turn..
5. Create a flowchart that inputs the base and the
height of the right triangle. Calculate and display the
angle that makes it with the horizontal.

6. One end of a foot ruler is placed against a vertical


wall, the other end of the ruler reaches a point on
the floor 9 inches from the base of the wall. Find the
sine, cosine, and tangent of the angle that the ruler
makes with the floor.
Exercises
7. The total resistance of a Series Circuit is the sum of
all individual resistance values. Draw a flowchart
allowing the user to input for 2 resistor values.
Compute and display the total resistance of a
circuit.
Exercises
8. Draw a flowchart that inputs the values for the 3
resistors and the voltage source of the series circuit
as shown below. Compute and display the total
current in the circuit. The relationship for the total
current is: IT = VS / ( R1 + R2 + R3 )
Exercises
9. Revise Problem #8 to include computations for
voltage drop for each resistor.
Note: VR1 = IT * R1
VR2 = IT * R2
VR3 = IT * R3
Solution to #9 x

x
Seatwork #1
Given the circuit shown below, develop a flowchart that
allows the user to input values for resistor (R1),
inductor (L1), frequency (f) and the voltage source (VS).
Thereafter, compute and display the voltage drop
across the resistor (VR) and the inductor (VL).

XL = 2fL1
Z = R12 + XL2
VL = VS (XL / Z)
VR = VS (R / Z)
Seatwork #2
• The area of an ellipse is given by the formula: Area =
ab. The circumference of an ellipse is given by the
formula C =   4 (a+b)2

Develop a flowchart to calculate and display the area


and the circumference of an ellipse by allowing the user
to input for the minor (a) and major (b) axes.
Assignment
1. Develop a flowchart that computes and displays the
total resistance and total current of a parallel circuit
consisting of 3 resistors and voltage source as
shown below:


The relationship for the total resistance is:
  
 
       

The relationship for the total current is:



 

Assignment
2. A wire is stretched from the top of a vertical pole
standing on level ground. The wire reaches to a
point on the ground with X feet from the foot of the
pole, and makes an angle of Y with the horizontal.
Draw a flowchart that allows user to input for the X
and Y. Thereafter, compute for the height of the pole
and the length of the wire.
3. From the top cliff X feet high the angle of
depression of a boat is Y degrees. Draw a flowchart
allowing the user to input for the values for X and Y.
Compute and display the distance between the boat
and the foot of the cliff.
Assignment
4. Algebraic solution of two equations system.
Allow the user to input for the numerical
coefficients of x and y and the constant values for the
two equations. Determine and display the values for x
and y.
Format: ax + by = e
cx + dy = f

Use the formula:


x = (de – bf) / (ad – bc)
y = (af – ce) / (ad – bc)
Assignment
5. Draw a flowchart that will obtain from the user the
length and width of the rectangle and the radius of a
circle. Calculate and output the area and perimeter
of the rectangle and the area and circumference of
the circle.
Assignment
6. Draw a flowchart that obtains from the user, annual
interest rate, the term of the loan (in years), and the
amount borrowed. Your algorithm should use the
following formula:
(1 + )

  
 !" #!
(1 + ) −1
Compute and display monthly payment.

Note: You need to convert the interest rate to monthly rate, and
the term into months. Test check: 120,000 for the loan amount,
30 years for the term, and annual interest rate of 7%.
Branching Statement
• Used to cause certain actions within a program if a
certain condition is met.
• Symbol:

– An If Statement checks the condition and executes a


true or false branch based on the result of the
condition.
Machine Problem #4
• Create a flowchart that inputs your age. If the entered
age is below 19, display “You are Teenager”,
otherwise “You are an ADULT”.
Machine Problem #5
• Create a flowchart that
inputs the salary of an
employee. If the salary is
less than 10,000.00, then
compute the bonus which is
25% of the salary, otherwise
bonus is fixed at P4,000.
Machine Problem #6
• Create a flowchart that
allows user to input for
an integer. Display “Its
an EVEN number” if the
integer is an even
number, otherwise
display “Its an ODD
number”.
Machine Problem #7
• Design a flowchart that
selects the larger of two
inputted values. Assume
that the two numbers
are not equal.
Machine Problem #8
• In temperature countries like Japan, there are 4
seasons. January to March (1 - 3) is Winter, April to
June (4 - 6) is Spring, July to September (6 – 9) is
Summer, and October to December (10 - 12) is
Autumn. Draw a flowchart that allows the user to
input month (in integer format). Display the season
associated with that month.
Solution
to MP #8
Machine Problem #9
• Input from the user an hourly pay rate and the
number of hours worked for the week. Calculate and
output his/her gross pay according to the following:
– Regular pay is the pay up to 40 hours.
– Overtime pay is pay for the hours over 40. Overtime is
paid at a rate of 1.5 times the hourly rate.
– Gross pay is the sum of the regular pay and the
overtime pay.
Solution to MP #9
Problems: Your turn…
1. Input length and width of a rectangle from the user.
Calculate and output the area. If the length and
width are equal, output a message indicating that
the “figure is a square”.

2. Input three test scores of the students. Calculate


and display their average test score. If their average
score is 75% or more, display a message indicating
that they “Passed”.
Problems: Your turn…
3. Input a temperature in degrees Fahrenheit from the
user. If the temperature is 80 degrees or more
display the message “Go play golf” otherwise, if the
temperature is 70 - 79 degrees display the message
“Put on a jacket”, otherwise display the message “It
is way too cold.”
4. Draw a flowchart that allows the user to input for the
username and password. Display “Successful login”
if the username is “s218” and Password is
“computer”, otherwise display the message “Alert:
intruder”.
Problems: Your turn…
5. You’ve been hired as a programmer by SFT (Sending
Failed Telecoms) – a mobile telecommunications
company. You are to draw a flowchart that will ask the
user to input the number of text messages incurred by
the subscriber. Text messaging charge is computed
based on the number of text messages. Charge is zero
for the first 100 messages. Text messages beyond that
are charged by 50 centavos per message. Compute and
display the charge incurred.
Built-in Functions

• Examples:
X = Random(100) => returns 0 to 99
Bingo = Random(76) => returns 0 to 75
Machine Problem #10
10. You were hired by PAGCOR as part of a programming
team in-charge of automating its BINGO game. Your
task is to draw a flowchart that will randomize a number
from 1 to 75. Your algorithm should determine and
display the letter corresponding to that number.
Numbers from 1 to 15, display ‘B’, 16 to 30  ‘I’, 31 to
45  ‘N’, 46 to 60 ‘G’ and 61 to 75, display ‘O’.
Answer to Seatwork #10
Exercise: Your Turn…
• Draw a flowchart that inputs the user’s age. Display
the name of his/her favorite snack according to the ff.
age group:
Seatwork
Looping
• Used for operations that are repeated for some
number of times.
• Loop repeats until some specified condition at the
beginning or end of the loop is met.
• Looping blocks:
– For block
– While block For While Do

– Do block
For Block Structure

ctr

1 10

Example:
ctr = 1 to 10
While Block Structure

ctr <=10

Example:
ctr <= 10
Do Block Structure

ctr <=10

Example:

ctr <= 10
Repetition Problem #1
• Make a flowchart that displays numbers from 1 to 10
using FOR block.
Repetition Problem #2
• Make a flowchart that displays numbers from 1 to 10
using WHILE block.
Repetition Problem #3
• Make a flowchart that displays numbers from 1 to 10
using DO block.
Repetition Problem #4
• Draw a flowchart that will
compute and display the sum
of numbers from 1 to 10.
Repetition Problem #5
• Draw a flowchart that will
compute and display the
average of 5 exam scores
entered by the user.
Repetition Problem #6
• Modify problem #4 to allow the
user to input the total number of
exam scores. Draw the flowchart
to compute and display the
average exam score.
Repetition Problem #7
• Draw a flowchart that will input 5
exam scores from the user and
determine whether the score is
passing (a score of 75 or above)
or failing. Your flowchart should
count the number of passing and
failing scores. Display the
average of the score, the number
of failing scores, and the number
of passing scores.
x

z
x
z
Repetition Problem #8
• Draw a flowchart that computes the squares and
cubes of the integers from 1 to 10 with the following
output.
Number Square Cube
1 1 1
2 4 8
3 9 27
4 16 64
5 25 125
6 36 216
7 49 343
8 64 512
9 81 729
10 100 1000
Answer
Your Turn #1:
• Draw a flowchart that prints the degrees Celsius from
5 to 45 (step 5) with their equivalent degrees
Fahrenheit as follows: Use the Formula:
9
$  ' + 32
5
Your Turn #2:
• The bank charges 12% simple interest on the amount
per annum. Draw a flowchart that allows the user to
input for the amount loan and the number of years to
pay. Compute and display the lump sum amount for
each year.

Formula: Amt = P (1 + r t)
where: Amt – lump sum amount
P – Amount loan
r – interest rate (12%)
t – # of years
Your Turn #3:
• A bank offers a car loan at the rate of 15% compounded
monthly. Draw a flowchart allowing the user to input for
the loan amount of the car and the period of years to pay.
Compute and display the monthly payments to amortize
the loan and determine the total amount at the end of the
period.
compounded interest
Formula: i
12
n = years x (12 months)

PA
1  i   1
n

i 1  i 
n
Your Turn #4:
• Draw a flowchart that prints the angles in degrees
from 0 to 80 (step 10) and its equivalent Sine() and
Tan() in radians as follows:
Your Turn #5:
• Make a flowchart that computes and displays the
distance a body falls in feet per second, for the first 5
seconds of free fall as given by the equation:
S = ½ at2 where: S = the distance in feet
a = acceleration due to gravity (32 ft/sec2)
t = time in seconds
• Output:

Time(in sec) Distance(in ft)


1 16
2 64
3 144
4 256
5 400
Built-in Functions

• ToFixed(150.12345, 2) => returns 150.12


• ToInteger(“1458”) => returns 1458
• ToReal(“78.56789”) => returns 78.56789
• ToString(9.81) => returns “9.81”
Repetition Problem #9
The x and y coordinates, as function of time t of a projectile
fired with an initial velocity v at an angle  with respect to
the ground is given by:
x = v t cos() y = v t sin() – ½ gt2

Using these formulas, draw a flowchart that allows the user


to input for the initial velocity (say 350 m/sec ) at an angle
(say 25 degrees). Display a table of x (distance travelled)
and y (height) values for a projectile fired at time interval 0
to the total time of flight (that is: t = 2 v sin() / g ) seconds
with increments of ½ second.

Note: g = 9.81 m/sec2 = 32.2 ft/sec2


: Need to convert degrees to radian (π/180)
Sample Output:
Solution
x

x
z
Cont.
Assignment #1
• Draw a flowchart for each item that produces table of
x and y values for the ff:
1. y  3x , − 2x  + x for x between 5 to 10 step 0.5

-. -/
2. y  1 + x + + for x between 1 to 5 step 0.25
 0

3. y  πx  for x between 5 to 25
Assignment #2
• Draw a flowchart that display the sum of the
following:

1. ∑ 44
-5 i = 1 + 2 + 3 +… + 99 + 100

2. ∑<4
-5 i divisible by 2 = 2 + 4 + … + 48 + 50

3. ∑ 4
-5 i 
= 1 + 2 + … + 9 + 10
End of Module 1

Potrebbero piacerti anche