Uploaded by Adachi Itsuki

CC102-Chapter-2-Flowcharts-and-Algorithms

advertisement
CC – 102: Fundamentals of
Programming
Chapter 2: Flowcharts and
Algorithms
Presented by: Christian A. Fajardo, MACE
What is a Flowchart?
• Use of symbols and phrases to designate the
logic of how a problem is solved.
• A common method for defining the logical ste
ps of flow within a program by using a series
of symbols to identify the basic Input,
Process and Output (IPO’s) function within a
program.
• A diagram representing the logical sequence
in which a combination of steps or operations
is to be performed. It is a blueprint of the
program.
Flowchart Example
Calculating the average of three numbers
What is an Algorithm?
• It is a finite set of instructions that specify a
sequence of operations to be carried out in
order to solve a specific problem or class of
problems.
• Can be also defined as a step-by-step
sequence of instructions that must terminate
and describes how to perform an operation to
produce a desired output
• When English phrases are used to describe
an algorithm, the description is called a
pseudocode.
Algorithm Example:
Calculating the average of three numbers:
 Input the three numbers into the computer.
 Calculate the average by adding the
numbers and dividing the sum by three
 Display the average
Pseudocode Example:
Calculating the average of three numbers:
start
input Number1
input Number2
input Number3
set average = (Number1 + Number2 + Number3) / 3
output average
stop
Symbols Used in Flowcharting
Symbols
What it represents
•
Used to signify the beginning
and end of flowchart.
•
Signifies the preparation of data
•
Used to select initial conditions
•
Used to represent instructions or
group of instructions that will
alter or modify a program’s
course of execution.
•
Shows input and output. Data
are read into the computer
memory from an input device or
data are to be passed from the
memory to an output device.
Terminal / Terminator
Preparation / Initialization
Input / Output
Symbols
What it represents
•
Performs any calculations that
are to be done
•
Signifies any decisions that are
to be done
•
Shows the entry or exit point of
the flowchart
•
Signifies the process that is to
be executed
Processing
Decision
Connector
Flowlines
Basic Flowchart Control
Structures
• Sequence – process is executed from one to
another in a straight – forward manner.
• Selection – a choice is provided between
two alternatives.
• Repetition – provides for the repetitive
execution of an operation or routine while the
condition is true.
Flowcharting Problems
1. Create a flowchart for a program that can convert an
inputted value in pounds (lbs) to
its weight
counterpart in kilograms (kgs).
2. Design a flowchart for a program that can determine if
a specific grade entered is “PASSED” or “FAILED”.
Assume that the passing grade should be exactly 75
and above.
3. Modify the design in flowcharting problem #2 in such
a way that grade values allowed are from 50 to 100
only. Otherwise, the program should be terminated.
4. Build the corresponding flowchart for a program that
can display the first ten multiples of 3. Implement the
repetition structure for this problem.
CC – 102: Fundamentals of
Programming
END OF CHAPTER 2
Presented by: Christian A. Fajardo, MACE
Download