Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
226 views

Structured Programming Using FlowChart

This document discusses structured programming using flowcharts. It defines structured programming as a method to design and code programs in a systematic, organized manner using flowcharts. Flowcharts use special symbols to visually depict the logic and flow of a program or module. The basic flowcharting symbols and their functions are described. The three basic structures of programming logic are also explained: sequence, decision, and loop structures. Modular programming and procedure-based programming are introduced as ways to break problems into smaller pieces. Finally, hands-on activities are provided to create flowcharts demonstrating sequence and decision structures.

Uploaded by

John Lacea
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
226 views

Structured Programming Using FlowChart

This document discusses structured programming using flowcharts. It defines structured programming as a method to design and code programs in a systematic, organized manner using flowcharts. Flowcharts use special symbols to visually depict the logic and flow of a program or module. The basic flowcharting symbols and their functions are described. The three basic structures of programming logic are also explained: sequence, decision, and loop structures. Modular programming and procedure-based programming are introduced as ways to break problems into smaller pieces. Finally, hands-on activities are provided to create flowcharts demonstrating sequence and decision structures.

Uploaded by

John Lacea
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

Structured Programming using Flowchart

By

 It is a method used to design and code programs in a systematic and organized manner.

 It is a diagram that uses special symbols to display pictorially the flow of execution within a
program or a program module.
 It is a formalized graphic representation of a program’s logic sequence, a work or
manufacturing process, or any similar structure.

BASIC FLOWCHARTING SYMBOLS


Symbol Name Description
Represents the Start or End of
Terminator a program or module.

Represents any kind of


Process/Assignment processing function; for
example, a computation.

Represents an input or output


Input/Output operation.

Represents a program branch


Decision point.

Invokes a defined procedure.


Procedure Call

Show the flow of control.


Arrows

1
THREE (3) BASIC STRUCTURES
Structure
 It is a basic unit of programming logic.

1. SEQUENCE STRUCTURE
 It performs actions or tasks in order, one after the other.

SEQUENCE STRUCTURE

2. DECISION or SELECTION STRUCTURE


 One of two (2) courses of action is taken based on the answer to a question.
 A flowchart that describes a selection structure begins with a decision symbol
(diamond), and the branches of the decision must join at the bottom of the structure.
 Some people call the selection structure an if-then-else because it fits the following
statement.

DECISION STRUCTURE – DUAL ALTERNATIVE SELECTION

DECISION STRUCTURE – SINGLE ALTERNATIVE SELECTION


2
3. LOOP STRUCTURE
 A loop continues to repeat actions while a condition remains true. The action or actions
that occur within the loop are the loop body.
 In the most common type of loop, a condition is evaluated; if the answer is true, you
execute the loop body and evaluate the condition again. If the condition is still true, you
execute the loop body again and then reevaluate the condition. This continues until the
condition becomes false, and then you exit the loop structure.

LOOP STRUCTURE

MODULAR PROGRAMMING
The key to building complex programs is to modularize. That is, you must break the program
into parts, with each part performing a single task.

Divide-and-Conquer
 It divides a problem into one or more instances of the same problem of smaller size and they
conquer the problem by using the solutions of the smaller problems to find a solution of the
original problem, perhaps with some additional work. You can divide up your code into separate
procedures.
Procedure
 It is a group of instructions that together perform a task.

THE PROBLEM IS DIVIDED INTO THREE (3) PROCEDURES


3
LABORATORY HANDS-ON ACTIVITY NO.1
SEQUENCE STRUCTURE
1. Run Raptor.
2. On the Menu bar, click File and select New or press the keyboard short-cut Ctrl + N.
3. On the Menu bar, click Window and select Tile Vertical.

4. On the Menu bar, click File and select Save or press the keyboard short-cut Ctrl + S. Browse the
folder c:\ Raptor 2020 and type the filename: Sequence Structure.rap.
5. On the Symbols panel, drag the Input symbol and drop to the arrow.

Before After

4
6. On the Workspace, right-click the newly inserted Input symbol and select Edit.

7. Fill-up the following parameters:


Enter Prompt Here: “Please enter an integer number>”
Enter Variable Here: Num1

8. Click Done button, when you are done.


9. On the Symbols panel, drag another Input symbol and drop to the second arrow below the first
Input symbol.
10. On the Workspace, right-click the newly inserted Input symbol and select Edit.
5
11. Fill-up the following parameters:
Enter Prompt Here: “Please enter a second integer number>”
Enter Variable Here: Num2
12. Click Done button, when you are done.

13. On the Symbols panel, drag the Assignment or Process symbol and drop to the third arrow.

6
14. On the Workspace, right-click the newly inserted Process symbol and select Edit.

15. Fill-up the following parameters:


Set: Sum
to: Num1 + Num2
16. Click Done button, when you are done.
17. On the Symbols panel, drag the Assignment or Process symbol and drop to the fourth arrow.
18. On the Workspace, right-click the newly inserted Process symbol and select Edit.
19. Fill-up the following parameters:
Set: Difference
to: Num1 – Num2
20. Click Done button, when you are done.
21. On the Symbols panel, drag the Assignment or Process symbol and drop to the fifth arrow.
22. On the Workspace, right-click the newly inserted Process symbol and select Edit.
23. Fill-up the following parameters:
Set: Product
to: Num1 * Num2
24. Click Done button, when you are done.
25. On the Symbols panel, drag the Assignment or Process symbol and drop to the sixth arrow.
26. On the Workspace, right-click the newly inserted Process symbol and select Edit.
27. Fill-up the following parameters:
Set: Quotient
to: Num1 / Num2
7
28. Click Done button, when you are done.

29. On the Symbols panel, drag the Output symbol and drop to the seventh arrow.

8
30. On the Workspace, right-click the newly inserted Output symbol and select Edit.
31. Fill-up the following parameters:
Enter Output Here: "The Sum of " + Num1 + " and " + Num2 + " is " + Sum
Check the End current line
32. Click Done button, when you are done.

33. On the Symbols panel, drag the Output symbol and drop to the eighth arrow.
34. On the Workspace, right-click the newly inserted Output symbol and select Edit.
35. Fill-up the following parameters:
Enter Output Here: "The Difference of " + Num1 + " and " + Num2 + " is " + Difference

9
Check the End current line
36. Click Done button, when you are done.
37. On the Symbols panel, drag the Output symbol and drop to the ninth arrow.
38. On the Workspace, right-click the newly inserted Output symbol and select Edit.
39. Fill-up the following parameters:
Enter Output Here: "The Product of " + Num1 + " and " + Num2 + " is " + Product
Check the End current line
40. Click Done button, when you are done.
41. On the Symbols panel, drag the Output symbol and drop to the tenth arrow.
42. On the Workspace, right-click the newly inserted Output symbol and select Edit.
43. Fill-up the following parameters:
Enter Output Here: "The Quotient of " + Num1 + " and " + Num2 + " is " + Quotient
Check the End current line
44. Click Done button, when you are done.
45. On the Symbols panel, drag the Output symbol and drop to the eleventh arrow.
46. On the Workspace, right-click the newly inserted Output symbol and select Edit.
47. Fill-up the following parameters:
Enter Output Here: Num1 + " raised to " + Num2 + " is " + Power
Check the End current line
48. Click Done button, when you are done.
49. Press Ctrl + S to save.
50. To run the flowchart, press the keyboard short-cut F5.
51. Enter the sample inputs:
Please enter an integer number> 2
Please enter a second integer number> 3
52. The outputs are displayed on the Master Console window situated on the right.
53. To trace the flowchart, press the keyboard short-cut F10. Manually press F10 again and again
until you reach the End symbol. While you are manually tracing, please understand that this is a
sequence structure, which is the computer runs each symbol in sequence fashion.

54. If you want to stop, simply click the stop button on the toolbar.

10
LABORATORY HANDS-ON ACTIVITY NO.2
DECISION or SELECTION STRUCTURE

Body Mass Index (BMI)


Body mass index (BMI) is a measure of health based on weight. It can be calculated by
taking your weight in kilograms and dividing it by the square of your height in meters. The
interpretation of BMI for people 16 years and older is as follows:
BMI Interpretation
Below 18.5 Underweight
18.5 – 24.9 Normal
25.0 – 29.9 Overweight
Above 30.0 Obese
Body Mass Index (BMI)
Write a program that prompts the user to enter a weight in pounds and height in inches and
then displays the BMI. Note that one pound is 0.45359237 kilograms and one inch is 0.0254
meters.

1. Run Raptor.
2. On the Menu bar, click File and select New or press the keyboard short-cut Ctrl + N.
3. On the Menu bar, click Window and select Tile Vertical.
4. On the Menu bar, click File and select Save or press the keyboard short-cut Ctrl + S. Browse the
folder c:\ Raptor 2020 and type the filename: Decision Structure.rap.
5. On the Symbols panel, drag the Call or Procedure Call symbol and drop to the arrow.

11
6. On the Workspace, right-click the newly inserted Call symbol and select Edit.

7. Fill-up the following parameters:


Enter a procedure call: Clear_Console

Clear_Console
 It is a built-in procedure library that clears the Master Console window.

8. Click Done button, when you are done.


9. On the Symbols panel, drag the Assignment or Process symbol and drop to the second
arrow.
10. On the Workspace, right-click the newly inserted Process symbol and select Edit.
11. Fill-up the following parameters:
Set: KILOGRAMS_PER_POUND
to: 0.45359237
12. Click Done button, when you are done.
13. On the Symbols panel, drag the Assignment or Process symbol and drop to the third arrow.
14. On the Workspace, right-click the newly inserted Process symbol and select Edit.
15. Fill-up the following parameters:
Set: METERS_PER_INCH
to: 0.0254
16. Click Done button, when you are done.

12
55. On the Symbols panel, drag another Input symbol and drop to the fourth arrow.
56. On the Workspace, right-click the newly inserted Input symbol and select Edit.
57. Fill-up the following parameters:
Enter Prompt Here: "Please enter your weight in pounds>"
Enter Variable Here: Weight
58. Click Done button, when you are done.
59. On the Symbols panel, drag another Input symbol and drop to the fifth arrow.
60. On the Workspace, right-click the newly inserted Input symbol and select Edit.
61. Fill-up the following parameters:
Enter Prompt Here: "Please enter your height in inches>"
Enter Variable Here: Height
62. Click Done button, when you are done.
63. On the Symbols panel, drag the Assignment or Process symbol and drop to the sixth arrow.
64. On the Workspace, right-click the newly inserted Process symbol and select Edit.
65. Fill-up the following parameters:
Set: WeightKilograms
to: Weight * KILOGRAMS_PER_POUND
66. Click Done button, when you are done.
67. On the Symbols panel, drag the Assignment or Process symbol and drop to the seventh
arrow.
68. On the Workspace, right-click the newly inserted Process symbol and select Edit.
69. Fill-up the following parameters:
Set: HeightMeters
to: Height * METERS_PER_INCH
70. Click Done button, when you are done.
71. On the Symbols panel, drag the Assignment or Process symbol and drop to the eighth arrow.
72. On the Workspace, right-click the newly inserted Process symbol and select Edit.
73. Fill-up the following parameters:
Set: BMI
to: WeightKilograms / (HeightMeters ^ 2)
13
74. Click Done button, when you are done.
75. On the Symbols panel, drag the Output symbol and drop to the ninth arrow.
76. On the Workspace, right-click the newly inserted Output symbol and select Edit.
77. Fill-up the following parameters:
Enter Output Here: "Your BMI is “ + BMI
Check the End current line
78. Click Done button, when you are done.

14
79. On the Symbols panel, drag the Decision or Selection symbol and drop to the tenth arrow.

80. On the Workspace, right-click the newly inserted Selection symbol and select Edit.

81. Fill-up the following parameters:


Enter selection condition: BMI < 18.5
82. Click Done button, when you are done.

15
83. On the Symbols panel, drag the Output symbol and drop to the Yes arrow.

84. On the Workspace, right-click the newly inserted Output symbol and select Edit.
85. Fill-up the following parameters:
Enter Output Here: "Your weight is underweight."
Check the End current line
86. Click Done button, when you are done.
87. On the Symbols panel, drag the Decision or Selection symbol and drop to the No arrow.

88. On the Workspace, right-click the newly inserted Selection symbol and select Edit.
89. Fill-up the following parameters:
Enter selection condition: BMI >= 18.5 and BMI <= 24.9
90. Click Done button, when you are done.
91. On the Symbols panel, drag the Output symbol and drop to the Yes arrow.
92. On the Workspace, right-click the newly inserted Output symbol and select Edit.
93. Fill-up the following parameters:
Enter Output Here: "Your weight is normal."
Check the End current line
94. Click Done button, when you are done.
95. On the Symbols panel, drag the Decision or Selection symbol and drop to the No arrow.
96. On the Workspace, right-click the newly inserted Selection symbol and select Edit.
16
97. Fill-up the following parameters:
Enter selection condition: BMI >= 25.0 and BMI <= 29.9
98. Click Done button, when you are done.
99. On the Symbols panel, drag the Output symbol and drop to the Yes arrow.
100. On the Workspace, right-click the newly inserted Output symbol and select Edit.
101. Fill-up the following parameters:
Enter Output Here: "Your weight is overweight."
Check the End current line
102. Click Done button, when you are done.
103. On the Symbols panel, drag the Decision or Selection symbol and drop to the No arrow.
104. On the Workspace, right-click the newly inserted Selection symbol and select Edit.
105. Fill-up the following parameters:
Enter selection condition: BMI > 30.0
106. Click Done button, when you are done.
107. On the Symbols panel, drag the Output symbol and drop to the Yes arrow.
108. On the Workspace, right-click the newly inserted Output symbol and select Edit.
109. Fill-up the following parameters:
Enter Output Here: "Your weight is obese."
Check the End current line
110. Click Done button, when you are done.

111. Press Ctrl + S to save.


112. To run the flowchart, press the keyboard short-cut F5.
113. Enter the sample inputs:
Please enter your weight in pounds> 130
Please enter your height in inches> 66
114. The outputs are displayed on the Master Console window situated on the right.
115. To trace the flowchart, press the keyboard short-cut F10. Manually press F10 again and again
until you reach the End symbol. While you are manually tracing, please understand that this is a
decision structure, there is a branching of flow execution based on the condition.
116. If you want to stop, simply click the stop button on the toolbar.

17
LABORATORY HANDS-ON ACTIVITY NO.3
LOOP STRUCTURE
Write a program to sum the following series:

1. Run Raptor.
2. On the Menu bar, click File and select New or press the keyboard short-cut Ctrl + N.
3. On the Menu bar, click Window and select Tile Vertical.
4. On the Menu bar, click File and select Save or press the keyboard short-cut Ctrl + S. Browse the
folder c:\ Raptor 2020 and type the filename: Loop Structure.rap.
5. On the Symbols panel, drag the Call or Procedure Call symbol and drop to the arrow.
6. On the Workspace, right-click the newly inserted Call symbol and select Edit.
7. Fill-up the following parameters:
Enter a procedure call: Clear_Console
8. Click Done button, when you are done.
9. On the Symbols panel, drag the Assignment or Process symbol and drop to the second
arrow.
10. On the Workspace, right-click the newly inserted Process symbol and select Edit.
11. Fill-up the following parameters:
Set: Sum
to: 0
12. Click Done button, when you are done.
13. On the Symbols panel, drag the Assignment or Process symbol and drop to the third arrow.
14. On the Workspace, right-click the newly inserted Process symbol and select Edit.
15. Fill-up the following parameters:
Set: Numerator
to: 1
16. Click Done button, when you are done.
17. On the Symbols panel, drag the Assignment or Process symbol and drop to the fourth arrow.
18. On the Workspace, right-click the newly inserted Process symbol and select Edit.
19. Fill-up the following parameters:
Set: Denominator
to: 3
20. Click Done button, when you are done.
21. On the Symbols panel, drag the Loop symbol and drop to the fifth arrow.

18
22. On the Workspace, right-click the newly inserted Loop symbol and select Edit.

23. Fill-up the following parameters:


Enter loop exit condition: Numerator = 97
24. Click Done button, when you are done.
25. On the Symbols panel, drag the Assignment or Process symbol and drop to the No arrow.

26. On the Workspace, right-click the newly inserted Process symbol and select Edit.
27. Fill-up the following parameters:
Set: Sum
to: Sum + (Numerator / Denominator)
19
28. Click Done button, when you are done.
29. On the Symbols panel, drag the Assignment or Process symbol and drop below the inserted
Process arrow.
30. On the Workspace, right-click the newly inserted Process symbol and select Edit.
31. Fill-up the following parameters:
Set: Numerator
to: Numerator + 2
32. Click Done button, when you are done.
33. On the Symbols panel, drag the Assignment or Process symbol and drop below the inserted
Process arrow.
34. On the Workspace, right-click the newly inserted Process symbol and select Edit.
35. Fill-up the following parameters:
Set: Denominator
to: Denominator + 2
36. Click Done button, when you are done.

37. On the Symbols panel, drag the Output symbol and drop to the Yes arrow.
38. On the Workspace, right-click the newly inserted Output symbol and select Edit.
39. Fill-up the following parameters:
20
Enter Output Here: "The sum of the Series is " + Sum
Check the End current line
40. Click Done button, when you are done.
41. Press Ctrl + S to save.
42. To run the flowchart, press the keyboard short-cut F5.
43. To adjust the speed of flow execution, drag the tick mark located on the right side of the
toolbar.

LABORATORY HANDS-ON ACTIVITY NO.4


PROCEDURE

QUADRATIC EQUATION
The roots of the quadratic equation ax2 + bx + c = 0 where a ≠ 0 are

DISCRIMINANT

1. If D > 0, then the equation has two (2) distinct real solutions.

2. If D = 0, then the equation has exactly one real solution.


3. If D < 0, then the equation has no real solution but complex solution.

1. Run Raptor.
2. On the Menu bar, click File and select New or press the keyboard short-cut Ctrl + N.
3. On the Menu bar, click Window and select Tile Vertical.
4. On the Menu bar, click File and select Save or press the keyboard short-cut Ctrl + S. Browse the
folder c:\ Raptor 2020 and type the filename: Procedure.rap.
5. On the Symbols panel, drag the Call or Procedure Call symbol and drop to the arrow.
6. On the Workspace, right-click the newly inserted Call symbol and select Edit.
7. Fill-up the following parameters:
Enter a procedure call: Clear_Console
8. Click Done button, when you are done.
9. On the Symbols panel, drag the Assignment or Process symbol and drop to the second
arrow.

21
10. On the Workspace, right-click the newly inserted Process symbol and select Edit.
11. Fill-up the following parameters:
Set: a
to: 0
12. Click Done button, when you are done.
13. On the Symbols panel, drag the Assignment or Process symbol and drop to the second
arrow.
14. On the Workspace, right-click the newly inserted Process symbol and select Edit.
15. Fill-up the following parameters:
Set: b
to: 0
16. Click Done button, when you are done.
17. On the Symbols panel, drag the Assignment or Process symbol and drop to the second
arrow.
18. On the Workspace, right-click the newly inserted Process symbol and select Edit.
19. Fill-up the following parameters:
Set: c
to: 0
20. Click Done button, when you are done.
21. On the Symbols panel, drag the Assignment or Process symbol and drop to the second
arrow.
22. On the Workspace, right-click the newly inserted Process symbol and select Edit.
23. Fill-up the following parameters:
Set: x1
to: 0
24. Click Done button, when you are done.
25. On the Symbols panel, drag the Assignment or Process symbol and drop to the second
arrow.
26. On the Workspace, right-click the newly inserted Process symbol and select Edit.
27. Fill-up the following parameters:
Set: x2
to: 0
28. Click Done button, when you are done.
29. On the Workspace, right-click the main tab and select Add procedure.

22
30. Fill-up the following parameters:
Procedure Name: Get3Numbers
Parameter 1: a Check Output
Parameter 2: b Check Output
Parameter 3: c Check Output

31. Click Ok button, when you are done.


32. Under the Get3Numbers tab, on the Symbols panel, drag another Input symbol and drop to the
first arrow.
33. On the Workspace, right-click the newly inserted Input symbol and select Edit.
34. Fill-up the following parameters:
Enter Prompt Here: "Please enter the value of a>"
Enter Variable Here: a
35. Click Done button, when you are done.
36. On the Symbols panel, drag another Input symbol and drop to the second arrow.
37. On the Workspace, right-click the newly inserted Input symbol and select Edit.
38. Fill-up the following parameters:
Enter Prompt Here: "Please enter the value of b>"
Enter Variable Here: b
39. Click Done button, when you are done.
40. On the Symbols panel, drag another Input symbol and drop to the third arrow.
41. On the Workspace, right-click the newly inserted Input symbol and select Edit.
23
42. Fill-up the following parameters:
Enter Prompt Here: "Please enter the value of c>"
Enter Variable Here: c
43. Click Done button, when you are done.

44. Click the main tab, on the Symbols panel, drag the Call or Procedure Call symbol and drop to
the arrow.
45. On the Workspace, right-click the newly inserted Call symbol and select Edit.
46. Fill-up the following parameters:
Enter a procedure call: Get3Numbers(a, b, c)
47. Click Done button, when you are done.
48. On the Workspace, right-click the main tab and select Add procedure.
49. Fill-up the following parameters:
Procedure Name: Determinant
Parameter 1: a Check Input
Parameter 2: b Check Input
Parameter 3: c Check Input
Parameter 3: D Check Output
Input
 It means that the variable’s value is passed to the calling procedure.
Output
 It means that the variable will receive value inside the body of procedure.
50. Click Ok button, when you are done.
51. Under the Determinant tab, on the Symbols panel, drag another Assignment or Process
symbol and drop to the first arrow.
52. On the Workspace, right-click the newly inserted Process symbol and select Edit.
53. Fill-up the following parameters:
Set: D
to: (b * b) – (4 * a * c)
54. Click Done button, when you are done.
55. Read the diagram on the next page if you have made it correctly or not the procedure
Determinant.
24
56. On the Workspace, right-click the main tab and select Add procedure.
57. Fill-up the following parameters:
Procedure Name: QuadraticEquation1
Parameter 1: a Check Input
Parameter 2: b Check Input
Parameter 3: c Check Input
Parameter 3: x1 Check Output
58. Click Ok button, when you are done.
59. Under the QuadraticEquation1 tab, on the Symbols panel, drag Assignment or Process
symbol and drop to the first arrow.
60. On the Workspace, right-click the newly inserted Process symbol and select Edit.
61. Fill-up the following parameters:
Set: D
to: 0
62. Click Done button, when you are done.
63. On the Symbols panel, drag the Call or Procedure Call symbol and drop to the second arrow.
64. On the Workspace, right-click the newly inserted Call symbol and select Edit.
65. Fill-up the following parameters:
Enter a procedure call: Determinant(a, b, c, D)
66. Click Done button, when you are done.
67. On the Symbols panel, drag the Assignment or Process symbol and drop to the third arrow.
68. On the Workspace, right-click the newly inserted Process symbol and select Edit.
69. Fill-up the following parameters:
Set: x1
to: (– b + sqrt(D))/(2 * a)
70. Click Done button, when you are done.
71. Read the diagram on the next page if you have made it correctly or not the procedure
QuadraticEquation1.

25
72. On the Workspace, right-click the main tab and select Add procedure.
73. Fill-up the following parameters:
Procedure Name: QuadraticEquation2
Parameter 1: a Check Input
Parameter 2: b Check Input
Parameter 3: c Check Input
Parameter 3: x2 Check Output
74. Click Ok button, when you are done.
75. Under the QuadraticEquation2 tab, on the Symbols panel, drag Assignment or Process
symbol and drop to the first arrow.
76. On the Workspace, right-click the newly inserted Process symbol and select Edit.
77. Fill-up the following parameters:
Set: D
to: 0
78. Click Done button, when you are done.
79. On the Symbols panel, drag the Call or Procedure Call symbol and drop to the second arrow.
80. On the Workspace, right-click the newly inserted Call symbol and select Edit.
81. Fill-up the following parameters:
Enter a procedure call: Determinant(a, b, c, D)
82. Click Done button, when you are done.
83. On the Symbols panel, drag the Assignment or Process symbol and drop to the third arrow.
84. On the Workspace, right-click the newly inserted Process symbol and select Edit.
85. Fill-up the following parameters:
Set: x2
to: (– b – sqrt(D))/(2 * a)
86. Click Done button, when you are done.
87. Read the diagram on the next page if you have made it correctly or not the procedure
QuadraticEquation2.

26
88. On the Workspace, right-click the main tab and select Add procedure.
89. Fill-up the following parameters:
Procedure Name: Output
Parameter 1: a Check Input
Parameter 2: b Check Input
Parameter 3: c Check Input
90. Click Ok button, when you are done.
91. Under the Output tab, on the Symbols panel, drag Assignment or Process symbol and drop
to the first arrow.
92. On the Workspace, right-click the newly inserted Process symbol and select Edit.
93. Fill-up the following parameters:
Set: D
to: 0
94. Click Done button, when you are done.
95. On the Symbols panel, drag the Call or Procedure Call symbol and drop to the second arrow.
96. On the Workspace, right-click the newly inserted Call symbol and select Edit.
97. Fill-up the following parameters:
Enter a procedure call: Determinant(a, b, c, D)
98. Click Done button, when you are done.
99. On the Symbols panel, drag the Decision or Selection symbol and drop to the third arrow.
100. On the Workspace, right-click the newly inserted Selection symbol and select Edit.
101. Fill-up the following parameters:
Enter selection condition: D = 0
102. Click Done button, when you are done.
103. On the Symbols panel, drag the Call or Procedure Call symbol and drop to the Yes arrow.
104. On the Workspace, right-click the newly inserted Call symbol and select Edit.
105. Fill-up the following parameters:
Enter a procedure call: QuadraticEquation1(a, b, c, x1)
106. Click Done button, when you are done.

27
107. On the Symbols panel, drag the Output symbol and drop to the Yes arrow after the procedure
call QuadraticEquation1(a, b, c, x1).
108. On the Workspace, right-click the newly inserted Output symbol and select Edit.
109. Fill-up the following parameters:
Enter Output Here: "The quadratic root is " + x1
Check the End current line
110. Click Done button, when you are done.
111. On the Symbols panel, drag the Decision or Selection symbol and drop to the No arrow.
112. On the Workspace, right-click the newly inserted Selection symbol and select Edit.
113. Fill-up the following parameters:
Enter selection condition: D > 0
114. Click Done button, when you are done.
115. On the Symbols panel, drag the Call or Procedure Call symbol and drop to the Yes arrow.
116. On the Workspace, right-click the newly inserted Call symbol and select Edit.
117. Fill-up the following parameters:
Enter a procedure call: QuadraticEquation1(a, b, c, x1)
118. Click Done button, when you are done.
119. On the Symbols panel, drag the Output symbol and drop to the Yes arrow after the procedure
call QuadraticEquation1(a, b, c, x1).
120. On the Workspace, right-click the newly inserted Output symbol and select Edit.
121. Fill-up the following parameters:
Enter Output Here: "The quadratic root is " + x1
Check the End current line
122. Click Done button, when you are done.
123. On the Symbols panel, drag the Call or Procedure Call symbol and drop to the Yes arrow
after the Output symbol.
124. On the Workspace, right-click the newly inserted Call symbol and select Edit.
125. Fill-up the following parameters:
Enter a procedure call: QuadraticEquation2(a, b, c, x2)
126. Click Done button, when you are done.
127. On the Symbols panel, drag the Output symbol and drop to the Yes arrow after the procedure
call QuadraticEquation2(a, b, c, x1).
128. On the Workspace, right-click the newly inserted Output symbol and select Edit.
129. Fill-up the following parameters:
Enter Output Here: "The quadratic root is " + x2
Check the End current line
130. Click Done button, when you are done.
131. On the Symbols panel, drag the Decision or Selection symbol and drop to the No arrow.
132. On the Workspace, right-click the newly inserted Selection symbol and select Edit.
133. Fill-up the following parameters:
Enter selection condition: D < 0
134. Click Done button, when you are done.
135. On the Symbols panel, drag the Output symbol and drop to the Yes arrow.
136. On the Workspace, right-click the newly inserted Output symbol and select Edit.
137. Fill-up the following parameters:
Enter Output Here: "The quadratic equation has no real solution but complex solution!"
Check the End current line
138. Click Done button, when you are done.
139. Read the diagram on the next page if you have made it correctly or not the procedure Output.

28
140. Click the main tab, on the Symbols panel, drag the Call or Procedure Call symbol and drop
to the eighth arrow after the procedure call Get3Numbers(a, b, c).
141. On the Workspace, right-click the newly inserted Call symbol and select Edit.
142. Fill-up the following parameters:
Enter a procedure call: Output(a, b, c )
143. Click Done button, when you are done.
144. Read the diagram on the next page if you have made it correctly or not the main procedure.

29
145. Press Ctrl + S to save.
146. To run the flowchart, press the keyboard short-cut F5.
147. Test the following inputs:
a = 4, b = 12, c = 9 has one solution
a = 3, b = – 5, c = – 1 has two solutions
a = 1, b = 2, c = 2 has no solution but complex solution
148. To trace the flowchart, press the keyboard short-cut F10. Manually press F10 again and
again until you reach the End symbol. While you are manually tracing, please understand how
procedure is called and variables are being passed and the program body of the procedure is
executed by the computer.
30
Programming Exercises: Test your knowledge, understanding and know-how about
structured programming by solving the following problems using flowchart.

SEQUENCE STRUCTURE
1. Write a program that asks the user to input a radius of circle as integer or decimal. Calculate and
display the diameter, area and circumference of the circle. Use the following formula:
Diameter = 2r
Area = r2
Circumference = 2r

2. Write a program that asks the user to input the 3 sides of a triangle as integers or decimals.
Calculate the display the area of the triangle on the screen. Use the following formula:
S = 1 (a + b + c)
2

A= S(S – a) (S – b) (S – c)

Where:
a, b and c are the 3 lengths of 3 sides of the triangle

DECISION OR SELECTION STRUCTURE


1. Write a program that asks the user to input the gross income and deductions as decimal nos.
Compute the net income and tax amount, display the result.
To compute the net income the formula: Net Income = Gross Income – Deduction
To compute the tax amount:
3% of net income, if net income is below or equal to P70,000.00
5% of net income, if net income is P70,000.00 to P85,000.00
8% of net income, if net income is over P85,000.00

2. Richter Scale
The National Earthquake Information Center has asked you to write a program implementing
the following decision table to characterize an earthquake based on its Richter scale number.
The user must input the Richter Scale as decimal number and display the characterization.
Richter Scale Number (n) Characterization
n < 5.0 Little or no damage
5.0 ≤ n < 5.5 Some damage
5.5 ≤ n < 6.5 Serious damage: walls may crack or fall
6.5 ≤ n < 7.5 Disaster: houses and buildings may collapse

LOOP STRUCTURE
1. Write a program that produces this output:
0 1
1 2
2 4
3 8
4 16
5 32
6 64

31
2. The value of can be determined by the series equation

Write a program to approximate the value of using the formula given including terms up
through 1/99.
PROCEDURES
1. A savings account of $10,000 earns simple interest at 5% per annum. Calculate the simple
interest and value of the account (future value) after six years. Compute also the compound
interest.
Simple Interest

Where:
P0 = Principal Amount
i = interest rate
t = time in years
I = Simple Interest

Compound Interest

Where:
P0 = Principal Amount
i = interest rate
t = time in years
Pt = Compound Interest

( )

Write a program that prompts the user to enter the principal amount, interest rate as decimals and
time in years as integer. Compute the simple and compound interests and the future saving accounts.
Apply your own defined procedures in this problem. Here is a sample run:
Please enter your principal amount> 10000
Please enter the interest rate> 5
Please enter the time in years> 6
The simple interest is $3,000.00
The future saving account is $13,000.00
The compound interest is $13,400.96
The future saving account is $13,400.96
32
2. Home Loan Amortization
Home Loan Amortization

[ ]
[ ]

Example:
Interest Rate = 3%
Loan Amount = $350,000
No. of Years = 30
Solution:

[ ]
[ ]

Write a program that prompts the user to enter the loan amount, interest rate as decimals and
no. of years as integer. Compute the monthly mortgage payment. Apply your own defined
procedures in this problem.
Here is a sample run:
Please enter loan amount> 350000
Please enter interest rate> 3
Please enter number of years> 30
The monthly mortgage payment is $1,475.61

33
“An investment in knowledge pays the best interest.”
Benjamin Franklin
“Try to learn something about everything and everything about
something.”
Thomas Henry Huxley
“I do not know anything, but I do know that everything is
interesting if you go into it deeply enough.”
Richard Feynman
“Example is the school of mankind, and they will learn at no
other.”
Edmund Burke
“Share your knowledge. It’s a way to achieve immortality.”
Dalai Lama
“It does not make much difference what a person studies. All
knowledge is related, and the man who studies anything, if he
keeps at it, will become learned.”
Hypatia
“Mathematics possesses not only the truth, but some supreme
beauty – a beauty cold and austere, like that of a sculpture.”
Bertrand Russell
“Imagination is much more important than knowledge because
knowledge describes what we know. Imagination describes
everything that we can potentially know in the future.”
Albert Einstein

34

You might also like