Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 15

DYBITITP113:

Introduction to Programming

HERLIZA F. ESTRADA
Instructor, College of Computer Studies

Declaration:
This learning module is an exclusive property of Dr. Yanga’s Colleges, Inc., as an essential part of the
REIMAGINED Learning Program for the Academic Year 2020-2021, and shall only be used by and for
DYCIans. No part of this learning module shall be reproduced, distributed, transmitted, and/or sold, without
the consent of DYCI.
Week No. 4
PROGRAM DESIGN - SELECTION FLOWCHART

This module will help you achieve greater grasps in the understanding of pictorial or
diagrammatic representation of an algorithm using selection and repetition structure.

At the end of this module, you are expected to:


1. Differentiate binary selection and multi-way selection.
2. Construct s flowchart to solve a problem using selection structure.

Selection Structure

Selection structure is used in a computer program or algorithm to determine which


particular step or set of steps is to be executed. This is also referred to as a ‘decision’. A
selection statement can be used to choose a specific path dependent on a condition.
There are two types of selection: binary selection (two possible pathways) and multi-
way selection (many possible pathways).

Binary Selection

In binary selection, if the condition is met then one path is taken, otherwise the second
possible path is followed. In each of the examples below, the first case described
requires a process to be completed only if the condition is true. The process is ignored if
the condition is false. In the second case, there is an alternative process if the condition
is false.

Multi-way selection

Multi-way selection allows for any number of possible choices, or cases. The path taken
is determined by the evaluation of the expression. Multi-way selection is often referred
to as a case structure.

1
Problem:

Design the flowchart and pseudocode that determine if the number given by
the user is an odd or an even number.

Pseudocode Flowchart

Step 1: START START

Step 2: DECLARE num

Step 3: INPUT num DECLARE num

Step 4: IF num % 2 == 0 THEN


PRINT num “is Even number”
ELSE INPUT num
PRINT num “is Odd number”

Step 5: STOP

F
num % 2 == 0?

PRINT num is
Even number

PRINT num is
Odd number

STOP

2
Example 1: Design a pseudocode and a flowchart that will determine whether to
age can vote or not.

Solution: Binary selection.


Pseudocode Flowchart
Step 1: START
Step 2: DECLARE age START
Step 3: READ age
Step 3: IF age >= 18 DECLARE age READ age
PRINT “You can
Vote”
Step 4: STOP Yes
PRINT age >= 18
“You can
Vote”

STOP

Multi -way selection.


Pseudocode Flowchart
Step 1: START
Step 2: DECLARE age START
Step 3: READ age
Step 3: IF age >= 18 DECLARE age READ age
PRINT “You can Vote”
ELSE
PRINT Yes
PRINT “You can’t “You can age >= 18
Vote” Vote”
Step 4: STOP
No PRINT “You
STOP can’t Vote”
3
Example 2: Give the pseudocode and draw a flowchart to input two numbers from
user and display the largest of two numbers

Solution:

Pseudocode Flowchart
Step 1: START
Step 2: DECLARE and START
INITIALIZE num1 = 0,
num2 = 0
Step 3: INPUT num1, num2 num1 = 0,
num2 = 0
Step 3: IF num1 > num2
PRINT num1 is the
largest
INPUT
ELSE
num1, num2
PRINT num2 is the
largest
Step 4: STOP
num1 > num2
F PRINT
num2 is the largest

T
PRINT num1
is the largest
A
A

STOP

4
Example 3: Design the flowchart and pseudocode that determine if the number
given by the user is positive or negative number.

Solution:

Pseudocode Flowchart
Step 1: START
Step 2: DECLARE and INITIALIZE START
num to 0
Step 3: INPUT num
num = 0
Step 4: IF num >= 0 THEN
DISPLAY num is Positive
number
ELSE INPUT num

DISPLAY num is negative


number
Step 5: STOP
num >= 0

F T

num is num is
Negative Positive
number number

STOP

5
Example 3: Design the pseudocode and flowchart that allows the user to enter a
value for age and determine whether the given age is for minor adult or children.
If the age is less than or equal to 12, Display “age is still a child”. If the age is
greater than or equal to 13 but not greater than 18, Display “age is a minor”. If
the age is greater than or equal to 18, Display “age is an adult”. If the age value is
less than zer0, Display “invalid entry”.

Solution:

Pseudocode Pseudocode

Step 1: START START DECLARE age


Step 2: DECLARE age
Step 3: GET age
GET age
Step 4: IF age >=0 && age <= 12
THEN
DISPLAY “age is still a
child” age >=
Step 5: IF age >=13 && age <=17 13 && F age >= 0
age <= && age
THEN
17 <= 12?
DISPLAY “age is a minor”
Step 6: IF age>= 18 THEN
F
T T
DISPLAY “age is an adult”
STEP 7: IF age < 0 THEN age is a age is still
minor a child
DISPLAY “invalid entry”
Step 8: STOP

age>= T age is an
18 adult

F STOP
6
Name: Rating:
Year and Section: Professor / Instructor:
Due of Submission:

Week No. 4
PROGRAM DESIGN - FLOWCHART

Instructions: Write the Pseudocode and draw the flowchart of the following problem:

1. ABC corporation plans to give a yearly bonus to each of its employees. Compute
the bonus of an employee. Consider the following criteria: Salary < 6000, bonus is
50% of salary; Salary > = 6000but less than 10000, bonus is 40%; Salary 10000
and up bonus is 35%. Print the corresponding salary and bonus

Pseudocode Flowchart

7
Name: Rating:
Year and Section: Professor / Instructor:
Due of Submission:

Week No. 4
PROGRAM DESIGN - FLOWCHART

2. If the wholesale cost of an item is under P500, the markup is 20%. If the wholesale
cost is at least P500, the markup is 30%. Determine the retail price for an item whose
wholesale cost is given by the user.

Pseudocode Flowchart

8
Name: Rating:
Year and Section: Professor / Instructor:
Due of Submission:

Week No. 4
PROGRAM DESIGN - FLOWCHART

3. The ABS Credit Cooperative approves a loan application. If the applicant’s income
is t least P30000 or the value of his/her assets is at least P150000; in addition, his/her
total liabilities must be less than P75000. Create a flowchart and pseudocode that
accepts three numbers representing income, assets and liabilities. Display a message
whether the application is approved or not.

Pseudocode Flowchart

9
Name: Rating:
Year and Section: Professor / Instructor:
Due of Submission:

Week No. 4
PROGRAM DESIGN - FLOWCHART

4. The humiture H, which is defined as H = T + h where T is the current temperature in


degrees Fahrenheit and h is the number of humit. A humit h is defined as h = e – 10,
where e is the vapor pressure in millibars of mercury. The discomfort zones of
humiture are: 85 ( mild), 100 (uncomfortable) and 115 (all activity is stopped).

Pseudocode Flowchart

10
Name: Rating:
Year and Section: Professor / Instructor:
Due of Submission:

Week No. 4
PROGRAM DESIGN - FLOWCHART

5. An employee’s weekly working hours is 40. If an employee exceeds 40 hours, it is


considered overtime (OT). Accept the number id hours worked of the employee and
the hourly rate and print the gross pay and overtime pay rendered. If there’s no OT
pay to print, print only the gross pay. To compute for the gross pay, multiply the
number of hours worked OT the value of rate plus the value for OT pay. The OT pay
is 15% of the hourly rate.

Algorithm Flowchart

11
Codesansar. (2020, June 24). Computer Basics. Retrieved from
https://www.codesansar.com/computer-basics/.
Farell, J. (2015). Programming Logic and Design 8th edition. Stanford: Cengage
Learning.
freecodecamp.org. (2017, October 12). A Gentler Introduction to Programming. Retrieved
from https://www.freecodecamp.org/news/a-gentler-introduction-to-programming-
1f57383a1b2c/.
geeksforgeeks.org. (2020, June 15). Difference between Algorithm, Pseudocode and
Program. Retrieved from https://www.geeksforgeeks.org/difference-between-
algorithm-pseudocode-and- program/#:~:text=An%20algorithm%20is%20defined
%20as,used%20to%20repres ent%20an%20algorithm.
geeksforgeeks.org. (2020, June 15). Java Programming Language. Retrieved from
https://www.geeksforgeeks.org/java/.
Goel, A. (2020, April 28). What is Programming. Retrieved from
https://hackr.io/blog/what-is-programming.
P2PU. (2020, June 24). Planning and designing software solutions. Retrieved
from https://courses.p2pu.org/en/courses/2544/hsc-sdd-planning-and-
designing- software-solutions/.
tutorialspoint.com. (2020, June 03). Computer Programming - Overview. Retrieved from
https://www.tutorialspoint.com/computer_programming/computer_programming_o
verview.htm.
tutorialspoint.com. (2020, June 15). Programming Methodologies. Retrieved from
https://www.tutorialspoint.com/programming_methodologies/index.htm.

12

You might also like