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

CFP - Chapter 2

The document discusses tools for developing program logic, including pseudocode and flowcharts. It provides instructions on pseudocode, including how to write pseudocode statements and examples. It also discusses flowchart symbols and provides examples of writing pseudocode for various problems, such as calculating sums, averages, squares and cubes of numbers. The objectives are to learn about algorithms, pseudocode, flowcharts and how to construct algorithms, write pseudocode and develop programs using flowcharts, algorithms and pseudocode.

Uploaded by

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

CFP - Chapter 2

The document discusses tools for developing program logic, including pseudocode and flowcharts. It provides instructions on pseudocode, including how to write pseudocode statements and examples. It also discusses flowchart symbols and provides examples of writing pseudocode for various problems, such as calculating sums, averages, squares and cubes of numbers. The objectives are to learn about algorithms, pseudocode, flowcharts and how to construct algorithms, write pseudocode and develop programs using flowcharts, algorithms and pseudocode.

Uploaded by

Velante Irafrank
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Tools for Developing Program Logic

Flowchart and Pseudocode Instructions


2.0 OBJECTIVES
2.1 INTRODUCTION TO ALGORITHMS
CHAPTER 2.1.1 PSEUDOCODE
2.1.2 DATA DICTIONARIES
SAMPLE PROBLEMS

2
SCHOOL ACTIVITY 1: PSEUDOCODE (COMPUTATIONS)
TAKE HOME ACTIVITY 1: PSEUDOCODE (QUIZZES)
TAKE HOME ACTIVITY 2: PSEUDOCODE (GREATER AND
SMALLER NUMBER)
2.2 FLOWCHART AND FLOWCHARTING SYMBOLS
2.2.1 TYPES OF FLOWCHARTS
SAMPLE PROBLEMS
SCHOOL ACTIVITY 2: FLOWCHART (COMPUTATIONS)
TAKE HOME ACTIVITY 3: FLOWCHART (QUIZZES)
TAKE HOME ACTIVITY 4: FLOWCHART (THREE NUMBERS)
TAKE HOME ACTIVITY 5: FLOWCHART SYMBOLS

2.0 OBJECTIVES
Students, after studying this you will be able to explain
Program and Logic Formulation. The main features of this chapter
are as follows;
o Learn to familiarize flowchart symbols
o Learn to construct an algorithm
o Learn to write a pseudo-code
o Develop a program using flowchart, algorithms and pseudo-
codes

Programming Logic and Design


INTRODUCTION TO ALGORITHMS

Topics
• Algorithms
• Pseudocode
• Flowcharts

Introduction to Algorithms

1. A sequence of instructions.
2. A procedure or formula for solving a problem.
3. It was created mathematician, Mohammed ibn-Musa al-
Khwarizmi.
4. Often used for calculation, data processing and
programming.
5. Algorithms can be expressed in any language.

ALGORITHMS PROCEDURES

• Algorithms for making things will often be divided


into sections;
– the parts/components/ingredients or the inputs which is
required to accomplish the task.
– actions/steps/methods or processing of data to produce
the required outcome or output.

• For example, to build a personal computer, the parts or inputs


are needed plus instructions on how to assemble the computer or
its processes and the result is the new computer model as your
output.

Introduction to Algorithms
• Two forms of Algorithm:
– Pseudocode
– Flow chart

2.1.1 PSEUDOCODE
• Pseudocode is a counterfeit code, because it’s not really
programming code since it specifies only the steps required to
accomplish the required task.

• Pseudocode is a type of structured English that is used


to specify an algorithm.
• Pseudocode cannot be compiled nor executed, and there is no
real formatting or syntax rules. It is just a logical algorithm.

Programming Logic and Design


Advantages of a Pseudocode
• Reduced complexity of the desired system to develop.
• Increased flexibility of developing the system.
• Ease of understanding for faster coding.

Why is Pseudocode Necessary?


• The programming process is a complicated one and
most especially on your starting point.

• You must first understand the program specifications before


such proceedings on coding.

• Then you need to organize your thoughts or you need to


plan first and create the program as a good start.

• You must break the main tasks that must be accomplished into
smaller ones in order to be able to eventually write fully
developed code since it is easier to understand the concept.

• Writing Pseudocode will save you time later during the


construction and testing phase of a program's development sine
it is the logic of your program to develop.

How to Write Pseudocode Statements?


There are six basic computer operations such as;

1. A computer can receive information.



Read the information from a file.

Get the information from the keyboard.

2. A computer can put out information.



Write the information to a file.

Display the information to the screen.

3. A computer can perform arithmetic.


Use actual mathematical symbols or the words for the symbols.
Example:

Add number to total


Total = total + number

(Addition “+”), (Subtraction “- “), (Multiplication “*”,


and (Division “/”)

4. A computer can assign a value to a piece of data.


It has 3 cases;

Programming Logic and Design


4.1. to give data an initial value.
Initialize, Set

4.2. to assign a value as a result of some processing.


“=‟ it is an assignment operator (the equals sign).

Example: x=y+2, it means that the result will be


stored on variable x.

Let y-2; therefore, x=2+2, so after addition x=4.

4.3. to keep a piece of information for later use.


Save, Store

5. A computer can compare two pieces of information and select


one of two alternative actions.

IF (condition) THEN
some action
ELSE
alternative action to take
ENDIF

6. A computer can repeat a group of actions.

WHILE (condition) (is true)


some action
ENDWHILE
FOR a number of times
some action to take
ENDFOR

2.1.2 DATA DICTIONARIES

• The pseudo code by itself doesn't provide enough information


to be able to write a program code.

• Data Dictionaries are used to describe the data used in the


Pseudo Code to do a process.

• The standard data types used in Pseudo Code are Integer,


Double, String, Char and Boolean.

VARIABLE NAME DATA TYPE


Num1 Integer (int)

Programming Logic and Design


Num2 float (float)
sum double (double)
name Character (char)
Number1 long integer (long int)
Number2 long double (long double)
location string (string)
proceed boolean (bool)

Visibility of variables

•Variables are only visible after their declaration and in the


block they have been declared.

•Blocks can include other blocks. The variables of the outer


blocks are visible, a priori, in the inner blocks.

•A variable declared in an inner block masks the variables with


the same name declared in outer blocks.

DO’s of a variable declaration

• Do define a variable by writing the type, then the variable


name.
Example; float myScore = 100;

• Do use meaningful variable names.


Example; myScore, myAge, Number, result

• Do remember that C++ is case sensitive.


Example; Score and score is different.

• Do understand the number of bytes each variable type


consumes in memory and what values can be stored in
variables of that type.
Example; float pi = 3.1416 and double number=20.01259874;

DONT’s of a variable declaration

• Don’t use C++ keywords as variable names.


Example; float asm = 3.1416, int char = ‘A’;

• Don’t use unsigned variables for negative


numbers. Example; unsigned int myNumber = -1241;

Programming Logic and Design


• Don’t use a variable name starts with a letter.
Example; unsigned int 1myNumber = 0;

• Don’t use a variable name with spaces.


Example; unsigned int my Number = -1241;

PSEUDOCODE EXAMPLES

Example 1:
Program Specification:

Write a pseudocode that obtains two integer numbers from the


user. It will print out the sum of those numbers (see pseudocode
below).

PSEUDOCODE:

Start
Initialize all the needed variables.
Prompt the user to enter the first integer
Prompt the user to enter a second integer
Compute the sum of the two user inputs
Display an output prompt that explains the answer as the
sum Display the result
Stop

Example 2:
Write a pseudocode that will find the average of any three
numbers.

We might usually specify the procedure of solving this problem


as “add the three numbers and divide by three”. Here, read and
write are implied. However, in an algorithm, these steps have to
be made explicit. Thus, a possible algorithm is:

PSEUDOCODE:

Start
Initialize all the needed variables.
Read values of num1, num2, sum
Compute for sum of three numbers (Sum = num1 + num2 + num3)
Compute for average of three numbers (Average = sum / 3)
Write value of average
Stop

Example 3:

Programming Logic and Design


Write a pseudocode that will compute the square and cube.

PSEUDOCODE:

Start
Initialize all the needed variables.
Read value of a Number.
Compute for the value of Square (Square = Number * Number)
Compute for the value of a cube (Cube = Square * Number)
Write values of Square and Cube.
Stop
Example 4:
Write a pseudocode that will find the biggest of two numbers.

PSEUDOCODE:

Start
Initialize all needed variables.
Read num1 and num2.
If num1 > num2,
then BIG = num1
Else
BIG = num2.
Write BIG
Stop

Example 5:
Write a pseudocode that will calculate pay of a worker.

PSEUDOCODE:

Start
Initialize all needed variables.
Input numbers of hours obtained by a worker.
Input rate of a worker.
Compute for pay of a worker (Pay = hours * rate)
Print pay of a worker.
End

Name: Date:
Section/Schedule: Instructor:

Programming Logic and Design


2.2 FLOWCHART AND FLOWCHARTING SYMBOLS

Flowcharts use special shapes to represent different types of


actions or steps in a process of a system. The lines and arrows
show the sequence of the steps which tells the actions where to
go, and the relationships among them as each symbol is
interconnected. These are known as flowchart symbols.

The type of diagram dictates the flowchart symbols that are


being used. For example, a data flow diagram may contain an
Input and output Symbol (also known as an I/O Symbol), but you
wouldn't expect to see it in most process flow diagrams.
When should developers use Flowcharts?

At the beginning of your process improvement efforts, an


as-is Flowchart helps you and others involved in the process to
understand how the system will works. The developers may find it
helpful to compare this as-is Flowchart with a diagram of the
way the process is supposed to work for since it is the best way
to start. Later, the developer will develop a Flowchart of the
modified process—again in order to record how it actually
functions accurately.
At some argument, the developer may want to create an ideal
Flowchart to show how it would ultimately like the process to be
performed or to do such task to operate. Among the benefits of
using Flowcharts are the following;


Developers need to promote and implement understanding of a
process by explaining the steps pictorially. Developer may
have differing ideas about how a process works and a
Flowchart can help you gain arrangement about the sequence of
steps to be followed. Flowcharts promote understanding in a
way that written procedures cannot do. One good Flowchart can
replace pages of words normally.


Using flowchart, it provides a tool for training users
because of the way they visually lay out the sequence of
process steps. Flowcharts can be very helpful in training
users to perform the process according to standardized
procedures that needs to follow.


Flowchart can identify problem areas and opportunities for
process improvement. Once you break down the process steps
and draw a diagram, problem areas become more visible and you
can draw solutions easily. It is easy to spot opportunities
for simplifying and refining your process by analyzing

Programming Logic and Design


decision points according to data, redundant steps, and
rework loops to test again in order to see results.

Here is a more comprehensive library of flowchart symbols that


needs to understand in order to procced on the steps given.

NAME/FUNCTIONS FLOWCHART SYMBOL


START/END SYMBOL

The terminator symbol marks the


starting or ending point of the system.
It usually contains the word "Start" or
"End."

ACTION OR PROCESS SYMBOL


A box can represent a single step ("add
two cups of flour"), or an entire sub-
process ("make bread") within a larger
process.

DOCUMENT SYMBOL
A printed document or report.

DECISION SYMBOL
A decision or branching point. Lines
representing different decisions emerge
from different points of the diamond.

INPUT/OUTPUT SYMBOL

Represents material or information


entering or leaving the system, such as
customer order (input) or a product
(output).

PREPARATION SYMBOL
Represents a set-up to another step in
the process.

Programming Logic and Design


CONNECTOR SYMBOL
Indicates that the flow continues where
a matching symbol (containing the same
letter) has been placed.

SUBROUTINE SYMBOL
Indicates a sequence of actions that
perform a specific task embedded within
a larger process. This sequence of
actions could be described in more
detail on a separate flowchart.

Most of the flowchart symbols shown here are for use in


very specific applications, such as a data flow diagram used for
computer programming. Unless you have specialized knowledge and
your diagram is being developed for a peer group with similar
knowledge, it's best to follow to basic flowchart symbols. If
more than the most basic flowchart symbols appear in your
diagram, it is good practice to include a legend or symbol key
for better understanding of flowchart.
Most flowcharts should be built using only the Start/Stop
and Action or Process symbols and should follow a very basic set
of best practices as beginners. Following with these two primary
flowchart symbols is the best way to guarantee that your diagram
will be easy to understand the whole concept or process.
How do we get started?

Many methods for constructing Flowcharts have been described


and you can safely use any one of them, as long as you start out
by doing these things:


Identify the right people to develop the chart for fast access.

Determine what you expect to get from the Flowchart before start.

Identify who will use it and how it will used.

Define the level of detail you need for specific purposes.

Establish the boundaries of the process for rooms of improvement.

Programming Logic and Design


A word about boundaries, these are the starting and ending
points to a Flowchart. For example, process boundaries for a
repair shop overhauling a pump might be when the pump enters the
shop and when it passes final testing. The boundaries determine
the number of activities to be studied and the number of people
involved in the process, functionally and cross-functionally.

At first, many teams struggle with the Flowchart tool. Team


members may be unsure about process boundaries or disagree on
the level of detail needed. The first few drawings quickly
become a tangled mess of lines as steps are added, moved, and
reconnected. And most discouraging of all, workers may question
the value of the Flowchart and fail to use it in their daily
work.

What are the keys to successful flowcharting?

Many of these difficulties can be avoided or overcome by


applying the keys to successful outline. It is vital that you
start by depicting the process the way it really works, not the
way you think it should work. You need to chart the process as
it is. Later you can chart it as it is supposed to work (by
regulation), or as you would like it to work (your ideal picture
of the process). Here are the keys:


Start with the big picture. It is best to draw a macro-
level Flowchart first. After you’ve depicted this big
picture of the process, you can develop other diagrams with
increased levels of detail.


Observe the current process. A good way to start Flowcharting
a process is to walk through the current process, observing it
in actual operation.


Record the process steps you observed. Record the steps as
they actually occur in the process as it is. Write the
steps on index cards or post it notes. You can use a
different color to represent each individual or group TM
involved if that will help you to understand and depict the
flow more accurately.


Arrange the sequence of steps. Now arrange the cards or
post-it notes TM exactly as you observed the steps. Using
cards lets you rearrange the steps without erasing and
redrawing and prevents ideas from being discarded simply
because it’s too much work to redraw the diagram.

Programming Logic and Design



Draw the Flowchart. Depict the process exactly as you observed,
recorded, and arranged the sequence of steps.

Interpreting Your Flowchart


• Determine who is involved in the process.
• Form theories about root causes.
• Identify ways to simplify and refine the actions taken.
• Determine how to implement changes on the process taken.
• Locate cost-added-only steps for faster checking.
• Provide training for further knowledge.

Interpretation Steps
Step 1 - Examine each process step.
Bottlenecks? Weak links? Poorly defined steps? Cost-added-
only steps?

Step 2 - Examine each decision symbol.


Can this step be eliminated?

Step 3 - Examine each rework loop.


Can it be shortened or eliminated?

Step 4 - Examine each activity symbol.


Does the step add value for the end-user?

2.2.1 TYPES OF FLOWCHARTS

Besides the three levels of detail used to categorize


Flowcharts, there are three main types of Flowcharts—Linear,
Deployment, and Opportunity. The level of detail can be depicted
as macro, mini, or micro for each of these types.

The viewgraphs that accompany the explanation below show


how one process, Producing the Plan of the Day (POD), might be
depicted using each of the three Flowchart types.

Programming Logic and Design



Basic Flowchart.

Basic flowcharts identify the major steps in a process in a


simple and easy-to-understand
way. They are used to
familiarize a person or group
with the major steps of a
process by giving them a broad
overview. For example, a
production line process might
use a flowchart to show
employees the process of
receiving material. The first
step might be Receive
Material, and then an arrow
points to the next step, which
might be Inspect. The chart
might now go in a couple of
directions. The person or
group follows the Okay arrow
if the material passes
inspection, or he may follow
the Bad arrow if it is
damaged. Following the Okay
arrow, the person or group
would see Move to Production
and so on. Following the Bad
arrow, the process may end at
Dispose of Material or
whatever is done with damaged material in that company. No
explanations or people are defined within the chart, only basic
steps.

Programming Logic and Design



Deployment Flowchart.

Deployment flowcharts are like process flowcharts in terms of


detail, except that in addition to showing the flow of a
process, deployment flowcharts indicate the people involved in
each step as well. This type of flowchart is useful when a
certain process involves different departments or areas to be
involved rather than a single team because it shows where the
people or departments fit into the process chain and how they
are linked to one another throughout.

Programming Logic and Design



Opportunity Flowchart.

Opportunity flowcharts are as detailed as deployment flowcharts,


but they also highlight decision steps and check points
throughout. In opportunity flowcharts, it may not be a simple
moving from this step to the next or answering a single question
at each stage. For example, the left side of an opportunity
flowchart may show the steps taken when everything goes right,
and the right side has the steps taken for when things go wrong.
If no problems arise, only the steps on the left are followed.
Opportunity flowcharts enable a company or group to see where a
process might be improved and highlight where these improvements
might be made. They are also used to show how much work or cost
is added when things go wrong, which enables organizations to
adjust their processes to eliminate unnecessary work and cost.

Programming Logic and Design



Process Flowchart.
Relatively it is a basic overview, process flowcharts give a full
listing of the major steps as well as the sub-steps in a process.
Process flowcharts are helpful when identifying unnecessary steps
within a certain process and are also used in troubleshooting.
For example, a process flowchart for the troubleshooting of a
machine might ask questions for the person or group to answer
before going to the next stage. Is the machine plugged in? If
not, the next step is Plug Machine In. The question might ask if
the working light is on; if the answer is "no," it may go through
the steps to turn the light on.

Programming Logic and Design


FLOWCHART EXAMPLES USING PSEUDOCODE

Example 1:
Program Specification:

Draw a flowchart that obtains two integer numbers from the user.
It will print out the sum of those numbers (see pseudocode
below).

PSEUDOCODE:

Start
Initialize all the needed variables.
Prompt the user to enter the first integer
Prompt the user to enter a second integer
Compute the sum of the two user inputs
Display an output prompt that explains the answer as the
sum Display the result
Stop

FLOWCHART

Programming Logic and Design


Example 2:
Draw a flowchart that will find the average of any three
numbers.

We might usually specify the procedure of solving this problem


as “add the three numbers and divide by three”. Here, read and
write are implied. However, in an algorithm, these steps have to
be made explicit. Thus, a possible algorithm is:

PSEUDOCODE:

Start
Initialize all the needed variables.
Read values of num1, num2, sum
Compute for sum of three numbers (Sum = num1 + num2 + num3)
Compute for average of three numbers (Average = sum / 3)
Write value of average
Stop

FLOWCHART

Programming Logic and Design


Example 3:
Draw a flowchart that will compute the square and cube.

PSEUDOCODE:

Start
Initialize all the needed variables.
Read value of a Number.
Compute for the value of Square (Square = Number * Number)
Compute for the value of a cube (Cube = Square * Number)
Write values of Square and Cube. Stop

FLOWCHART

Programming Logic and Design


Example 4:
Draw a flowchart that will find the bigger of two numbers.

PSEUDOCODE:

Start
Initialize all needed variables.
Read num1 and num2.
If num1 > num2,
then BIG = num1
Else
BIG = num2.
Write BIG
Stop

FLOWCHART

Programming Logic and Design


Example 5:
Draw a flowchart that will calculate pay of a worker.

PSEUDOCODE:

Start
Initialize all needed variables.
Input numbers of hours obtained by a worker.
Input rate of a worker.
Compute for pay of a worker (Pay = hours * rate)
Print pay of a worker.
End

FLOWCHART

Programming Logic and Design

You might also like