0% found this document useful (0 votes)
250 views

Disclaimer: College of Information and Communications Technology

The document provides an overview of program design tools used to develop computer programs, including algorithms described as step-by-step instructions to solve problems, pseudocode which expresses algorithms using plain English notation, and flowcharts which visually represent algorithms using standard symbols. It discusses key characteristics and advantages of algorithms, pseudocode, and flowcharts, and how to write algorithms and pseudocode. The learning outcomes cover interpreting flowcharts, designing complete programs using the tools, and explaining how program solutions are transformed into code.

Uploaded by

Faith Reyna Tan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
250 views

Disclaimer: College of Information and Communications Technology

The document provides an overview of program design tools used to develop computer programs, including algorithms described as step-by-step instructions to solve problems, pseudocode which expresses algorithms using plain English notation, and flowcharts which visually represent algorithms using standard symbols. It discusses key characteristics and advantages of algorithms, pseudocode, and flowcharts, and how to write algorithms and pseudocode. The learning outcomes cover interpreting flowcharts, designing complete programs using the tools, and explaining how program solutions are transformed into code.

Uploaded by

Faith Reyna Tan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

Chapter 2: Introduction to Computer Programming

Disclaimer

This learning material is used in compliance with the flexible teaching-learning approach
espoused by CHED in response to the pandemic that has globally affected educational institutions.
Authors and publishers of the contents are well acknowledged. As such, the college and its faculty
do not claim ownership of all sourced information. This learning material will solely be used for
instructional purposes not for commercialization.

College of Information and Communications Technology


Chapter 2: Introduction to Computer Programming
MODULE 2: PROGRAM DESIGN TOOLS

Chapter 2
Program
Design
Tools
Chapter 2: Program Design Tools

Module Overview

Program Design tools are the tools used to develop a program. A program is the
expression of an algorithm in a programming language.

This module will provide the different program design tools. It will cover the following
lessons:

Lesson 1: Algorithm

An algorithm is a sequence of instructions or step by step instruction to find the


solution of a problem.

Lesson 2: Pseudocode

A pseudocode is an artificial and informal language that helps programmers


develop algorithms.

Lesson 3: Flowchart

A flowchart is a pictorial representation of an algorithm.

Learning Outcomes

At the end of the module, the students shall be able to:

1. Draw flowchart and write pseudocode to design a complete program


2. Interpret different flowchart symbols.
3. Explain how a program solution using the different program design tools is transformed
into a program code.
Chapter 2: Program Design Tools

Module Map

Draw flowchart
and write
pseudocode to Design, implement, test, an
design a ebug a program, based on
complete iven specification, that use
each of the following
fundamental programming
omponents: (1) primitive da
ypes, (2} basic computatio
Program 3) simple I/0, (4) conditiona
Interpret different Design Tools and iterative structures, (5
flowchart symbols definition of functions and
parameter passing, and (6 CC102
recursion

Explain how a
program solution Analyze and simulate resul
using the differen of algorithms that may be
rogram design too mplemented as a solution t
s transformed into a given problem.
program code

Definition of Key Terms / Unlocking of Difficulties

Algorithm - a sequence of steps to solve a problem or it is an ordered set of definite steps


that produces a result and terminates in a finite time.

Pseudocode - simply an implementation of an algorithm in the form of annotations and


informative text written in plain English.

Flowchart - described as the blueprint of program during the Program Development Process.

Introduction

In your daily life, you may face problems through various activities. A problem means an
objective or an output that we must achieve, for example preparing a meal is considered a
problem, and we must follow consecutive steps sequentially to attain the required objective and
get the meal
Chapter 2: Program Design Tools

LESSON 1: Algorithm

1.1. What is an algorithm?

An algorithm is a sequence of steps to solve a problem or it is an ordered set


of definite steps that produces a result and terminates in a finite time.

1.2. Characteristics of algorithm

 Input: An algorithm may or may not require input


 Output: Each algorithm is expected to produce at least one result
 Definiteness: Each instruction must be clear and unambiguous
 Finiteness: If the instructions of an algorithm are executed, the algorithm
should terminate after finite number of steps.

1.3. Advantages of algorithm

 It is a stepwise representation of a solution to a given problem, which makes it


easy to understand.
 An algorithm uses a definite procedure.
 It is not dependent on any programming language, so it is easy to understand
for anyone without programming knowledge.
 Every step in an algorithm has its own local sequence so it is easy to debug.

1.4. How to write algorithms

 Step 1. Define your algorithms input: Many algorithms take in data to be


processed, e.g. to calculate the area of rectangle, input the rectangle height
and width.
 Step 2. Define the variables: Algorithm’s variables allow you to use it form
more than place. We can define two variables for rectangle Height and Width
(or H and W).
 Step 3. Outline the algorithm’s operations: Use input variable for
computation purpose, e.g. to find area of rectangle, multiply the Height and
Width variable and store the value in new variable Area.
Chapter 2: Program Design Tools

 Step 4. Output the results of your algorithm’s operations: In case the


output will be the value stored in variable Area, and if the input variables
described a rectangle with a Height and Width e.g. 2 and 3, the algorithm
would output the value of 6.
Example 1. Write an algorithm to calculate the area of a rectangle.

Step 1: Start
Step 2: Input H and W (H = height, W=width)
Step 3. Compute the Area by multiplying H and W
Step 4: Print Area
Step 5: End

Example 2: Write an algorithm that calculates the sum of two numbers entered by
the user and display the result.

Step 1: Start
Step 2: Enter the number num1 and num2
Step 3. Perform the sum of the two numbers using the equation
sum = num1 + num2, the output is the sum
Step 4: Print sum
Step 5: End

Example 3. Write an algorithm to compute and display the average and product of
three (3) numbers.

Step 1: Start
Step 2: Read the values of num1, num2 and num3
Step 3. Perform the average and product of the three numbers
using the equations:
Average = (num1 + num2 + num3) / 3
Product = num1 * num2 * num3
Step 4: Print Average, Product
Step 5: End

You will find more examples on Lesson 3.

Supplementary Learning Resources


1. David, D. J. (2013, May 20). What's an algorithm? - David J. Malan.
YouTubehttps://www.youtube.com/watch?v=6hfOvs8pY1k

2. ITS InfoTechSkills. (2020, April 9). Introduction to Algorithm for Beginners |


Algorithm Tutorial for Beginners.
YouTube:https://www.youtube.com/watch?v=tm5oUTciK8g

3. ITS InfoTechSkills. (2020, April 26). Flowchart and Algorithm Sample Problems
Tagalog | Beginners Guide 2020.
YouTube. https://www.youtube.com/watch?v=BQP2doXjVlQ
Chapter 2: Program Design Tools

NAME:
PROGRAM / YR / BLK:
COURSE CODE / TITLE: AEC9 – Business Logic
TIME / DAY:
CHAPTER
2

Test Yourself 2-1-1

1. Write a sequence of steps that will solve for the payable amount of Samsung 6
Edge; the price is: P38,390.00; plus 3% interest rate. The customer is given a two
mode of payments, in six [6] or twelve [12] month terms.

Ans: 1.
Chapter 2: Program Design Tools

LESSON 2: Pseudocode

2.1 What is a pseudocode?

Pseudocode is simply an implementation of an algorithm in the form of


annotations and informative text written in plain English. It has no syntax like any of
the programming language and thus can’t be compiled or interpreted by the
computer.

2.2 Advantages of pseudocode

 Improves the readability of any approach. It’s one of the best approaches to start
implementation of an algorithm.
 Acts as a bridge between the program and the algorithm or flowchart. Also works
as a rough documentation, so the program of one developer can be understood
easily when a pseudocode is written out.
 The main goal of a pseudocode is to explain what exactly each line of a program
should do, hence making the code construction phase easier for the
programmer.

2.3 How to write pseudocode

 Arrange the sequence of tasks and write the pseudocode accordingly.


 Start with the statement of a pseudo code which establishes the main goal or the
aim.
 The way the if-else, for, while loops are indented in a program, indent the
statements likewise, as it helps to comprehend the decision control and
execution mechanism. They also improve the readability to a great extent.
 Use appropriate naming conventions. The human tendency follows the approach
to follow what we see. If a programmer goes through a pseudocode, his
approach will be the same as per it, so the naming must be simple and distinct.
 Use appropriate sentence casings, such as CamelCase for methods, upper case
for constants and lower case for variables.
 Elaborate everything which is going to happen in the actual code. Don’t make the
pseudocode abstract.
 Use standard programming structures such as ‘if-then’, ‘for’, ‘while’, ‘cases’ the
way we use it in programming.
 Check whether all the sections of a pseudocode is complete, finite and clear to
understand and comprehend.
 Don’t write the pseudocode in a complete programmatic manner. It is necessary
to be simple to understand even for a layman or client, hence don’t incorporate
too many technical terms.
Chapter 2: Program Design Tools

The program design process describes the algorithm for the solution of the problem.
Algorithm specify what actions and operations a program will take. A programmer has
several program design tools to choose from, flowcharts, decision, tables or
pseudocodes – in formulating an algorithm.

Steps in Program Design:

1. Determine the program logic using a top-down approach and modularization

2. Design details using pseudocode and/or flowcharts

Pseudocode – is an algorithm written in normal human-language statements to


describe the logic and processing flow. It can also contain such terms as If, THEN,
or ELSE

Example of an Algorithm:
Get the employee name, hourly rate, hours worked, deductions
Calculate gross pay and net pay
Write name, gross pay and net pay.

The pseudocode would look like this:

Read name, hourly rate, hours worked, deductions


Calculate: Gross pay = hourly rate time hours worked
Calculate: Net pay = Gross pay minus deductions
WRITE name, Gross pay, Net pay

Example 1. Write a pseudocode to calculate the area of a rectangle.

 Input the height (h) and width (w) of a rectangle


 Calculate the Area by multiplying height and width
 Output the Area

Example 2: Write a pseudocode that calculates the sum of two numbers entered by
the user and display the result.

 Input the 1st and 2nd numbers


 Calculate the Sum of the two numbers by adding the 1st and
2nd numbers
 Output the Sum

Example 3. Write a pseudocode to compute and display the average and product of
three (3) numbers.

 Input the 3 numbers


 Calculate their average by summing and dividing by 3
Calculate the product by multiplying the 3 numbers
 Output the average and product

You will find more examples on Lesson 3.


Chapter 2: Program Design Tools

Supplementary Learning Resources


1. Yusuf, S. (2013, August 27). Algorithm using Flowchart and Pseudo code Level 1
Flowchart. YouTube. https://www.youtube.com/watch?v=vOEN65nm4YU

2. SkillHave. (2017, April 9). 03 - Pseudocode and Flowchart - Programming for


beginners series | SkillHive. YouTube. https://www.youtube.com/watch?v=AlEBMhxreo0

3. Codeacademy. (2019, May 9). What is Pseudocode And How Do You Use It?
YouTube. https://www.youtube.com/watch?v=PwGA4Lm8zuE
Chapter 2: Program Design Tools

NAME:
PROGRAM / YR / BLK:
COURSE CODE / TITLE: AEC9 – Business Logic
TIME / DAY:
CHAPTER
2

Test Yourself 2-2-1


Instruction: Write an algorithm / pseudocode of the following;

1. Write a sequence of steps that will accept and display a number.

2. Write a sequence of steps that will determine a student’s final grade.

3. Write a sequence of steps that will compute and display the sum and product of two
numbers.
Chapter 2: Program Design Tools

4. Write an algorithm / pseudocode that will input values for A & B. Compare two
values inputted and print which of the values is higher including the mark “Higher”.
Chapter 2: Program Design Tools

LESSON 3: Flowchart

3.1 What is a flowchart?

Flowchart is described as the blueprint of program during the Program Development


Process. It uses graphical symbol that illustrates the sequence of steps for solving a problem.

3.2 Standard Symbols Used in Constructing Flowchart

Flowcharts are drawn using standard symbols that connotes specific meanings.
These are the 8 standard symbols used in constructing a flowchart:

Symbol Name Description


Terminal It signifies the start and end of
flowchart.

Preparation/  It signifies the preparation of


Initialization data
 It is used to select initial
conditions
 It represents instructions that
alters or modifies a program’s
course of execution
Input/output It 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 device
Process It performs any calculations.

Decision  It signifies any decisions to be


done;
 There are two possible
alternative paths

On-page It shows the entry or exit of the


connector flowchart.
Chapter 2: Program Design Tools

Off-page It designates entry or exit from


connector one page when a flowchart
requires more than one page.

Flowlines It signifies the process that is to


be executed next.

3.3 Advantages of Flowchart

• Communication: Flowcharts are a good way of communicating the logic of a system to


all concerned.

• Effective analysis: With the help of flowchart, problem can be analyzed in more
effective way.

• Proper documentation: Program flowcharts serve as a good program documentation.

• Efficient coding: The flowcharts act as a guide during the system’s analysis and
program development phase.

• Proper debugging: The flowchart helps in debugging process.

• Efficient program maintenance: The maintenance of a program becomes easy with


the help of flowchart.

3.4 Limitations of Using a Flowchart

• Complex logic: Sometimes, the program logic is quite complicated. In this case,
flowchart becomes complex and clumsy.

• Alterations and modifications: If alterations are required the flowchart may require re-
drawing completely.

• The essentials of what is done can easily be lost in the technical details of how it is
done

3.5 Rules for Flowchart

a. Every flowchart has a START symbol and a STOP symbol.


b. The flow of sequence is generally from the top of the page to the bottom of the page.
This can vary with loops which need to flow back to an entry point.
c. Use arrowheads on connectors where flow direction may not be obvious.
d. There is only one flow chart per page
e. A page should have a page number and a title.
Chapter 2: Program Design Tools

f. A flow chart on one page should not break and jump to another page
g. A flow chart should have no more than around 15 symbols (not including START and
STOP).

3.6 General Rules for flowcharting

a. All boxes of the flowchart relate to Arrows. (Not lines)


b. Flowchart symbols have an entry point on the top of the symbol with no other entry
points. The exit point for all flowchart symbols is on the bottom except for the Decision
symbol.
c. The Decision symbol has two exit points; these can be on the sides or the bottom and
one side.
d. Generally, a flowchart will flow from top to bottom. However, an upward flow can be
shown if it does not exceed 3 symbols.
e. Connectors are used to connect breaks in the flowchart. Examples are:
i. From one page to another page
ii. From the bottom of the page to the top of the same page
iii. An upward flow of more than 3 symbols
f. Subroutines and Interrupt programs have their own and independent flowcharts.
g. All flow charts start with a Terminal or Predefined Process (for interrupt programs or
subroutines) symbol.
h. All flowcharts end with a terminal or a contentious loop.

3.7 Basic Control Structures

3.7.1 Sequence

It shows a set of instructions that are performed sequentially without


branching.

Problem No. 1. Compute the Sum of Two (2) numbers

Draw a flowchart for a program that calculates the sum of two numbers
entered by the user and display the result.

Solution:

 Define the Problem

Output: The sum of two numbers.

Input: The first number is num1 and the second number is num2

Solution
sum = num1 + num2 where the result is sum.
:
Chapter 2: Program Design Tools

 Algorithm and Flowchart to add two numbers

Step Algorithm Flowchart

1 Start START

Enter the number num1 and Enter


2 the num2 num1, num2

Perform the sum of the two sum = num1 + num2


numbers using the equation
3 sum = num1 + num2, the
output is sum
Print
sum
4 Print sum

End
5 End

Consider the following when constructing a flowchart

1. The flowchart should start with the Start symbol and end with End symbol.
2. num1, num2 and sum are variable names. A variable is a storage of data or a
memory storage that holds a value.
3. The equation: sum = num1 + num2 indicates the sum of the value of num1, to
the value of num2, and stores the result in sum.
4. Entering the values in num1 and num2 is done by using the term “Enter”
inside the parallelogram or input symbol. The term “Read” or “Input” can also
be used.
5. The sum of the equation is written inside the rectangle or process symbol as it
represents an arithmetic equation.
6. The output is expressed with a parallelogram or output symbol using the term
“Print”. The term “Output” can also be used.
7. Lines with arrows or flowlines are from top to bottom and show the order of
the algorithm.
Chapter 2: Program Design Tools

Problem No. 2. Compute and display the average and product of


three (3) numbers.

Draw a flowchart for a program that will compute and display the
average and product of three (3) numbers.

Solution:

 Define the Problem

Output: The average and product of three numbers

Input: The first number is num1; second number is num2;


third number is num3.
Solution average = (num1 + num2 + num3) / 3 and,
: product = num1 * num2 * num3

 Algorithm and Flowchart to compute and display the average


and product of three numbers

Step Algorithm Flowchart

1 Start START

Read the values of num1, num2, Read


2 num3 num1, num2, num3

Perform the average and product


of the three numbers using the Average = (num1 + num2 +
equations: num3) / 3
3 average = (num1 + num2 + num3) / product=num1 * num2 *
3 num3
product = num1 * num2 * num3

Print
average,
4 Print the average and the product product

5 End End
Chapter 2: Program Design Tools

3.7.1.1 Selection

A choice is provided between two (2) alternatives. There are problems


that includes a decision where there are two (2) possible answers: “Yes” or “No”.
It is also called a decision structure or an if-then-else.

Problem No. 3:

Draw a flowchart for a program that will input two numbers, num1 and
num2. Compare the two inputted values and print which of the values is higher
including the remark “higher”.

Solution:
 Define the Problem

Output: Print the word “higher”

Input: The first number is num1; second number is num2


If num1 is greater than num2, num1 is higher.
Solution: However, if num1 is less than num2, num2 is higher.
Print the number and the remark “higher”

 Algorithm and Flowchart to display the higher number and the


remark “higher”

Step Algorithm Flowchart

1 Start START

Read in the values of Input


2 num1 and num2 num1, num2

Test if num1 is num1 > num2


3 N Y
greater than num2.

If num1 is greater
than num2, num1 is
Print Print
higher. However, if
4 num1 is less than
num2, “higher” num1, “higher”
num2, num2 is
higher
Print the number and
5 the remark “higher”
6 End
Chapter 2: Program Design Tools

End

Problem No. 4:

Draw a flowchart for a program that determines a student’s final


grade and indicate whether it is passing or failing. The final grade is
calculated as the average of four marks.

Solution:

 Define the Problem

Output: Print “Passed” or “Failed”


Input: Four marks: m1, m2, m3, m4
Solution: Calculate the average by adding the four marks and
divide by 4. If the average is below 75, print “Failed”,
else print “Passed”

 Algorithm and Flowchart

Step Algorithm Flowchart

1 Start START

Input a set of four (4)


2 marks: m1, m2, m3, Input
m4 m1,m2,m3,m4

Calculate the
3 average grade Grade =
(m1+m2+m3+m4)/4

Grade <
75
If Grade is less than
4 75, print “Failed” else
print “Passed” Print Print
“Passed “ “Failed”

5 End
End
Chapter 2: Program Design Tools

3.7.1.2 Loop

It repeats a set of actions until a condition is satisfied. This is


also called repetition or iteration.

Basics of Looping

a. Iteration. It simply means repetition of a loop. If a problem requires


the printing of numbers from 1 to 5, it means that printing of
instructions repeatedly 5 times is needed. The number of repetitions
the loop has taken to perform to satisfy the problem is the number of
iterations.

b. Accumulator. It is a temporary storage that holds mathematical data


during processing. The problem requires the printing of sum from 1 to
5. To illustrate this, look at the following:

Numbers: 1 2 3 4
5
Sum of the numbers: 1+2+3+4+5
The sum is: 15

The numbers 1 to 5 is to be added 5 times which means that


there are 5 iterations. As the number increases, get the number, add
them and store them in a temporary variable to hold the current sum
until the 5 iterations are completed.

The variable that holds the temporary value for the sum is
called the accumulator. The accumulator can also be used for
multiplications and other mathematical applications.

c. Counter. It counts the number of iterations or processing in a


program and the value is stored in a temporary storage location
called counter. The counter also identifies the number and
implements the accumulator.

Problem No. 5:

Draw a flowchart that prints the first 500 counting numbers.

Solution:

 Define the Problem

Output: Print the first 500 numbers


Chapter 2: Program Design Tools

Input: Counter is set to 0.


Solution: If counter is less than or equal to 500, print the
counter

 Algorithm and Flowchart

Step Algorithm Flowchart

START
1 Start

Initialize the value of ctr = 0


2 counter to 0.

Increment the value ctr = ctr + 1


3 of counter by 1

Test if the counter is ctr <=


6 less than or equal to 500? Y
500.

If counter is less than Print


or equal to 500, loop N ctr
back and repeat
7 steps 3 to 6. End
However, if radius is
greater than 500,
stop processing.

8 Stop

Problem No. 6:
Draw a flowchart to compute the area of the circle starting with
radius 1 up to 5, then print each radius and the corresponding area of the
circle.
Solution:

 Define the Problem

Output: Print the radius and each area where the radius is from
1 to 5.
Chapter 2: Program Design Tools

Input: radius=1; pi=3.1416


Solution: Compute the area of a circle from radius 1 to 5

 Algorithm and Flowchart

Step Algorithm Flowchart

START
1 Start

Initialize the value of adius=1 pi=3.141


2 radius to 1 and pi to
3.1416
A
Calculate the area by
using the equation area=pi * radius * radius
3 area=pi * radius *
radius

Print
4 Print radius and area radius,area

Increment the value


5 of radius by 1
radius = radius + 1

Test if radius is less


6 than or equal to 5. radius
If radius is less than Y <=5?
or equal to 5, loop A
back and repeat
7 steps 3 to 6.
However, if radius is N
greater than 5, stop
processing.
End
8 Stop

Types of Loop

a. Infinite Loop – A loop that runs without an end it is due to wrong logical
operation or expression used, or wrong variables used to control the
Chapter 2: Program Design Tools

termination of the loop. Others call this logical error. Often this type of error
is the hardest type of error to debug. This kind of loop should be avoided.
Chapter 2: Program Design Tools

Problem No. 7:

Draw a flowchart to print the first 100 counting numbers.

Solution Leading to Infinite Loop:

 Define the Problem

Output: Print the first 100 numbers


Input: ctr = 0; num = 0
Solution: If num is greater than counter, print the counter.

 Algorithm and Flowchart

Step Algorithm Flowchart

START
1 Start

Initialize counter to 0 ctr=0


2 and num to 0 num=0
A

Increment the value ctr = ctr + 1


3 of the counter to 1

Test if number is
greater than the num >
value of the counter. N ctr? Y
If the number is
greater than the
counter, stop
4 processing. Print End
However, if the ctr
number is less than
the counter, loop
back and repeat
steps 3 to 4.

5 Stop A

What is wrong with the solution above?


1. In step number 2, the variable num was initialized to 0 instead of 1.
Chapter 2: Program Design Tools

2. In step number 6, the comparison used inside the decision symbol


shows an incorrect logical operator to terminate (stop) the loop. It used
greater than (>) instead of less than (>) symbol. Incorrect choice of the
logical operator shall lead to infinite loop.

b. Index Loop. A loop that executes when the number of iterations is explicit
in the problem. The printing of numbers 1 to 10 is an example of this type
of loop.

Problem No. 8:

Draw a flowchart to print the first five even numbers.

Solution:

 Define the Problem

Output: Print the first five even numbers


Input: ctr = 0
Solution: If counter is less than or equal to 10

 Algorithm and Flowchart

Step Algorithm Flowchart

1 Start START

2 Initialize counter to 0
ctr=0

Increment the value


3 of the counter to 2
ctr = ctr + 2
Test if the counter is
less than or equal to
10. If yes, print ctr <=
counter and loop N 10? Y
4 back and repeat
steps 3 to 4.
However, if not, stop
processing. Print
ctr
End
5 Stop
Chapter 2: Program Design Tools

c. Conditional Loop. A loop that executes only in a given satisfied condition.


The number of iterations in this type of loop is not explicit in the problem
and the iteration is dependent on the conditions given.
 While Loop. This loop checks first if the given condition in the decision
symbol is true. If it is true, the program performs the instruction. The rule
of the thumb for this approach in programming is:
“While the condition is true, Do *statement/s”

Problem No. 9:
Draw a flowchart that asks for a number and print the integers of
the inputted number.
Solution:

 Define the Problem

Output: Print the integers of the number inputted


Input: The user shall input any desired number.
Solution: If the user inputted a number 10, the integers of the
number are: 1,2,3,4,5,6,7,8,9, and 10.
 Algorithm and Flowchart

Step Algorithm Flowchart

1 Start START

Initialize the counter ctr=0


2 to 0 and num to 0 num=0

Enter the desired


3 number Input
num
Increment the value
4 of counter by 1
ctr = ctr + 1
Test if the counter is
less than or equal to
the number. If yes, ctr <= x?
5 print the counter and Y
N
loop back and repeat
steps 4 to 5. If no,
stop processing
6 Stop End Print
ctr
Chapter 2: Program Design Tools

 Do-while loop. It performs the instruction before checking the condition


given in the decision symbol. The rule of thumb in programming under
this approach is:
“Always executes its loop at least once.”
“Do statement and iterate while the condition is true”

Problem No. 10:


(like Problem No. 9, but this time use a do-while loop)
Draw a flowchart that asks for a number and print the integers of
the inputted number.
Solution:

 Define the Problem

Output: Print the integers of the number inputted


Input: The user shall input any desired number.
Solution: If the user inputted a number 10, the integers of the
number are: 1,2,3,4,5,6,7,8,9, and 10.

 Algorithm and Flowchart

Step Algorithm Flowchart

START
1 Start

ctr=0
Initialize the counter num=0
2 to 0 and num to 0

Input
Enter the desired
3 num
number

Increment the value ctr = ctr + 1


4 of counter by 1

Print
ctr
Print the value of the
5 counter

6 Test if the counter is ctr <= x?


Y
N

Stop
Chapter 2: Program Design Tools

less than or equal to


the number. If yes,
loop back and repeat
steps 4 to 6. If no,
stop processing
7 Stop

Supplementary Learning Resources

1. ITS InfoTechSkills. (2020). HOW TO CREATE FLOWCHART | LOGIC


FORMULATION |TAGALOG| Beginners Guide 2020 [YouTube Video]. In YouTube.
https://www.youtube.com/watch?v=YwE6yqi-37Y
2. the Gangwar. (2020). FlowChart Tutorial for Beginners in Programming Part 1
[YouTube Video]. In YouTube. https://www.youtube.com/watch?v=tgyfGBauk-g
3. the Gangwar. (2020b). FlowChart Tutorial for Beginners in Programming Part 2
[YouTube Video]. In YouTube. https://www.youtube.com/watch?v=xSxIo-W3mp8

NAME:
Chapter 2: Program Design Tools

PROGRAM / YR / BLK:
COURSE CODE / TITLE: AEC9 – Business Logic
TIME / DAY:
CHAPTER
2

Learning Activity 2-1

I. Problem Analysis. Identify the input, process and output of the following problem
statements.
1. Read two (2) records in a computer. The first record will contain unit price and the
second number will contain quantity. Draw a flowchart that will compute and
display the amount by multiplying unit price and quantity.
Input Processing Output

Flowchart:
Chapter 2: Program Design Tools

2. Draw a flowchart that will compute and display the area of a rectangle using the
formula: Area = Length * Width
Input Processing Output

Flowchart:

Synthesis

Algorithms and flowcharts are two different tools used for creating new programs,
especially in computer programming. An algorithm is a step-by-step analysis of the process, while
a flowchart explains the steps of a program in a graphical way.
Chapter 2: Program Design Tools

NAME:
PROGRAM / YR / BLK:
COURSE CODE / TITLE: AEC9 – Business Logic
TIME / DAY:
CHAPTER
2

Assignment

For each of the following problem statements, write the algorithm, draw the
flowchart and write the pseudocode:

A. Problems (Sequence)

1. Draw a flowchart that will accept the length of the base and height of a triangle and print
the area. Use the formula: Area = (base * height) / 2
2. Draw a flowchart that accepts dollar value and print the equivalent peso value. The
flowchart will convert dollar to peso having an exchange rate of 1 is to 53.25.
3. Draw a flowchart that will convert Fahrenheit to Celsius using the formula:
Celsius = (5/9) * (Fahrenheit – 32) where Fahrenheit is 20.
4. Draw a flowchart that reads in three numbers num1, num2, num3 and determine which is
the largest.
5. Draw a flowchart that read unit price and quantity. Compute and display the amount by
multiplying unit price and quantity.

B.
Chapter 2: Program Design Tools

C. Problems (Selection)

1. Display “IT’S COLD!” if the temperature is less than 20, “IT’S HOT!” is the temperature is
greater than 30, “COOL CLIMATE” otherwise.
2. Output “Congratulations you PASSED!” if the student’s grade is greater than or equal to
75. Otherwise, output “Sorry, you failed”
3. Accept two integers for variables int1 and int2 respectively and print the integers in
lowest to highest.
4. Identify whether the inputted number is a positive or negative. Consider 0 as positive.
5. Identify whether the inputted number is even or odd.
6. Accept three (3) numbers and determine the highest number, if there are equal numbers
print the equal numbers otherwise do not print anything.
7. Accept three (3) integers and determine if they are equal numbers. If there are equal
numbers, print the product of the equal numbers, otherwise print the average of the
numbers.
8. CounterVille Company plans to give a year-end bonus to each of its employee. It will
compute the bonus of an employee. Consider the following conditions: If the employee’s
monthly salary is less than 2,000 pesos, the bonus is 50% of the salary; for employees
with salaries greater than 2,000 pesos, the bonus is 1,500 pesos. Print the name and the
corresponding bonus for each employee.
9. Accept the evaluation score of a faculty and determine its equivalent remarks. Print the
name of the faculty and the remarks obtained. Remarks are based on the following
criteria:
4.50 – 5.00 - Outstanding
4.00 – 4.49 - Very Satisfactory
3.50 – 3.99 - Satisfactory
3.00 – 3.99 - Needs Improvement
2.99 below - Poor
D. Problems (Looping)

1. Output your name 15 times.


2. Output all even numbers from 1 to 50.
3. Get the average of all integers from 1 to 30 using do-while loop.
4. Generate the sum and product of 15 input numbers
5. Calculate and print the sum of the even integers from 2 and 100.
6. Calculate and print the product of the odd integers from 1 to 25.
7. Get the factorial of an input number.
8. Read and print the names and score of 20 students for an examination and determine
the average score and print it.

33
Catanduanes State University College of Information and Communications Technology

You might also like