0% found this document useful (1 vote)
601 views

Flowcharting

This laboratory manual introduces students to problem solving techniques like algorithms, flowcharts, and pseudocode. It defines algorithms as step-by-step procedures for solving problems unambiguously in a finite number of steps. Flowcharts are graphical representations of algorithms that depict the flow or sequence of steps. Pseudocode describes algorithms using a structured English format without syntax. The document provides examples and exercises to help students practice applying these techniques, including using conditional statements and switch case statements to alter program flow based on different conditions.

Uploaded by

Bien Medina
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
601 views

Flowcharting

This laboratory manual introduces students to problem solving techniques like algorithms, flowcharts, and pseudocode. It defines algorithms as step-by-step procedures for solving problems unambiguously in a finite number of steps. Flowcharts are graphical representations of algorithms that depict the flow or sequence of steps. Pseudocode describes algorithms using a structured English format without syntax. The document provides examples and exercises to help students practice applying these techniques, including using conditional statements and switch case statements to alter program flow based on different conditions.

Uploaded by

Bien Medina
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

COE103 – Laboratory Manual PAMANTASAN NG CABUYAO – College of Engineering

Laboratory 1
(INTRODUCTION TO PROGRAMMING)

OBJECTIVES:
1. Familiarity in pseudo code, algorithms and flowchart
2. Apply solving different techniques that will be the basis for solution.
3. Recognize various structures like sequence, selection and repetition

BASIC CONCEPTS

Problem Solving Techniques:

The process of working through details of a problem to reach a solution. There are three
approaches to problem solving: Algorithm, Flowchart, Pseudo Code.

Algorithm: The algorithm is a step-by-step procedure to be followed in solving a problem. It


provides a scheme to solve a particular problem in finite number of unambiguous steps. It helps in
implementing the solution of a problem using any of the programming languages.

In order to qualify as an algorithm, a sequence of instructions must possess the following


characteristics:

Definiteness: Instructions must be precise and unambiguous i.e. each and every instruction should
be clear and should have only one meaning.

Finiteness: Not even a single instruction must be repeated infinitely. i.e., each instruction should be
performed in finite time.

Termination: After the algorithm gets executed, the user should get the desired result.

Key features of an algorithm:

Any algorithm has a finite number of steps and some steps may involve decision making, repetition.
Broadly speaking, an algorithm exhibits three key features that can be given as:

Sequence: Sequence means that each step of the algorithm is executed in the
specified order.

Decision: Decision statements are used when the outcome of the process depends on some
condition.

Repetition: Repetition which involves executing one or more steps for a number of times can be
implemented using constructs like the while, do-while and for loops. These loops executed one or
more steps until some condition is true.

P rob le m So lv in g T e c hniqu e s 1
COE103 – Laboratory Manual PAMANTASAN NG CABUYAO – College of Engineering

Example: To compute the Area of Rectangle

ALGORITHM: AREA_of_RECTANGLE [This algorithm takes length and breadth, the sides of the
rectangle as input and computes the area of rectangle using the formula area=length * breadth.
Finally it prints the area of rectangle]

STEPS:
Step 1:[Initialize]
Start
Step 2: [Input the sides of Rectangle]
Read length, breadth
Step 3:[Compute the area of rectangle]
Area=length*breadth
Step 4:[Display the Area]
Print Area
Step 5: [Finished]
Stop

Flowcharts: A flowchart is a graphical or symbolic representation of an algorithm. They are


basically used to design and develop complex programs to help the users to visualize the logic of
the program so that they can gain a better understanding of the program and find flaws,
bottlenecks, and other less-obvious features within it.

Basically, a flowchart depicts the “flow” of a program. The following table shows the symbols used
in flowchart along with its descriptions.

SYMBOL NAME DESCRIPTION


START / STOP
THIS REPRESENT THE TERMINAL POINT
BEGIN / END

REPRESENTS THE PROCESS STEPS DEFINED IN


PROCESS
ALGORITHM
INDICATE THE READING OPERATION USED FOR
I/O INPUT/OUTPUT OR DATA OR INFORMATION
FROM/TO ANY DEVICE
SHOWS THE FLOWCHART DIRECTION AND
ARROWS
CONNECTS THE VARIOUS FLOW CHART SYMBOLS
INDICATES THE DECISIONS (QUESTIONS) AND
CONSEQUENTLY THE BRANCH POINTS OR THE
DIAMOND
PATHS TO BE FOLLOWED BASED ON THE RESULT
OF THE QUESTION
SHOWS THE CONTINUATION FROM ONE POINT IN
SMALL CIRCLE
THE PROCESS FLOW TO ANOTHER
OFF PAGE CONNECTOR CONNECTS ONE DRAWING TO ANOTHER PAGE

P rob le m So lv in g T e c hniqu e s 2
COE103 – Laboratory Manual PAMANTASAN NG CABUYAO – College of Engineering

Advantages of Flowcharts:

A flowchart is a diagrammatic representation that illustrates the sequence of steps that must be
performed to solve a problem. They are usually drawn in the early stages of formulating computer
solutions to facilitate communication between programmers and business people.

Flowcharts help programmers to understand the logic of complicated and lengthy problems. They
help to analyze the problem in a more effective manner Flowchart can be used to debug programs
that have error(s).

Limitations of using Flowcharts:

Drawing flowcharts is a laborious and a time consuming activity.

Flowchart of a complex program becomes, complex and clumsy. At times, a little bit of alteration in
the solution may require complete re-drawing of the flowchart

Essentials of what is done may get lost in the technical details of how it is done. There are no well-
defined standards that limit the details that must be incorporated in a flowchart.

E.g.: To compute the Area of Rectangle

Pseudocode:

It is a form of structured English that describes algorithms. It facilitates the designers to focus on the
logic of the algorithm without getting bogged down by the details of language syntax.

Pseudo code is a compact and informal high-level description of an algorithm that uses the
structural conventions of a programming language. It is meant for human reading rather than
machine reading, so it omits the details that are not essential for humans.
P rob le m So lv in g T e c hniqu e s 3
COE103 – Laboratory Manual PAMANTASAN NG CABUYAO – College of Engineering

Such details include keywords, variable declarations, system-specific code and subroutines. There
are no standards defined for writing a pseudo code because it is not an executable program.
Flowcharts can be considered as a graphical alternative to pseudo code, but are more spacious on
paper.

TRY ME: ( Homework)

A. Sweta, who scores 60 marks in Science, 70 marks in mathematics and 75 marks in English.
Use the adjacent flowchart and provide the execution steps in calculating the average marks
of Sweta.

B. The following empty flowchart gives the steps to be followed while seeking admission to new
school. The phrases to be filled in the boxes are also given. Complete the flowchart by filling
in the number of the corresponding phrase, inside each box. For example: the number
corresponding to the first box in the flowchart is 7.

P rob le m So lv in g T e c hniqu e s 4
COE103 – Laboratory Manual PAMANTASAN NG CABUYAO – College of Engineering

Conditional statements

Within a method, we can alter the flow of control (the order in which statements are executed)
using either conditionals or loops. Each choice or decision is based on the value of a boolean
expression (also called the condition) .

The if Flowchart

• If boolean_expression evaluates to true, then statement1 is executed.


• If boolean_expression evaluates to false, then statement2 is executed.

Thus the diamond symbol in flowchart has 1 input and 2 possible output.

EXERCISE :

A. Lengths of three sides of a triangle a, b, c are given as input. The following flowchart finds if
the triangle is isosceles, equilateral, or scalene.

Hint: In an equilateral triangle three sides are equal.


In an isosceles triangle two sides are equal.
In a scalene triangle three sides are not equal.

B. There are four types of fruits Apples, Oranges, Bananas and Grapes. Each student can pick
up two fruits. There are some conditions which have to be used to pick up the fruits. Draw a
flow chart which can take the name of first fruit as an input and print the names of second
fruit or fruits that can be picked up. The conditions are:

 If you pick an apple you can pick banana.


 If you pick orange you can pick grapes.
 If you pick grapes you can pick banana.

P rob le m So lv in g T e c hniqu e s 5
COE103 – Laboratory Manual PAMANTASAN NG CABUYAO – College of Engineering

Switch case statement:

This typically is used on selection cases. Or having some input which can be test on different
conditions. Typically used if there are choices / selections…

Switch Case Flowchart

Example :

Create a flowchart that would take a numeric input , and display the equivalent value:
1 – PNC
2 – BOTICAB START
3 – PeTOTMAN
4 – Exit
Read Choice : CH

Case 1 Case 2 Case 3 Case 4

Output Output Output


PNC BOTICAB PeTOTMAN
END

P rob le m So lv in g T e c hniqu e s 6
COE103 – Laboratory Manual PAMANTASAN NG CABUYAO – College of Engineering

Loops (Repetition)

This structure allows you to repeat a task over and over. The red chart above on the left does the
task and repeats doing the task until the condition is false. It always does the task at least once.
The green chart on the right checks the condition first and continues doing the task while the
condition is true. In the green chart the task may not be done at all. You can also have the
conditions reversed and your loop is still a structured design loop.

For LOOP

The above chart is a "For Loop." In this example the task is performed 10 times as X counts from 0
to 10. Depending on the condition, the task may not be performed at all.

P rob le m So lv in g T e c hniqu e s 7
COE103 – Laboratory Manual PAMANTASAN NG CABUYAO – College of Engineering

Examples

#1 Find the sum of 5 numbers

Algorithm
1. Initialize sum = 0 and count = 0 (PROCESS)
2. Enter n (I/O)
3. Find sum + n and assign it to sum and then increment count by 1 (PROCESS)
4. Is count < 5 (DECISION)
5. if YES go to step 2
else
Print sum (I/O)

Flowchart

#2 Print Hello World 10 times

Algorithm
1. Initialize count = 0 (PROCESS)
2. Print Hello World (I/O)
3. Increment count by 1 (PROCESS)
4. Is count < 10 (DECISION)
5. if YES go to step 2
else Stop

FLOWCHART

P rob le m So lv in g T e c hniqu e s 8
COE103 – Laboratory Manual PAMANTASAN NG CABUYAO – College of Engineering

EXERCISES FORMAT

1. PROVIDE AN ALGORITHM FOR THE PROBLEM


2. PROVIDE A CLEAR FLOWCHART FOLLOWING YOUR ALGORITHM

SAMPLE : Draw a flowchart to log in to facebook account

Algorithm

1. Enter www.facebook.com in your browser. (I/O)


2. Facebook Home page loads (PROCESS)
3. Enter your Email ID and Password (I/O)
4. Is Email ID and Password Valid (DECISION)
if NO then
Log in error (PROCESS)
go to step 3
else
Display Facebook Account (I/O)
Stop

Flowchart

MATRIX OF GRADING (FLOWCHARTING)

Algorithm
Correct analysis of the problem 20 pts
Correct arrangement of logic / solutions has been supplied 15 pts
Correct command of English has been supplied 15 pts
Clear flow has been given 15 pts

Flowchart
Correct symbols has been used 20 pts
Neat and organized presentation 15 pts

Note: Correct algorithm , wrong flowchart : grade = 40


Wrong algorithm , correct flowchart : grade = 30
Incorrect analysis of the problem : grade = 10 consideration

P rob le m So lv in g T e c hniqu e s 9
COE103 – Laboratory Manual PAMANTASAN NG CABUYAO – College of Engineering

EXERCISE ( TO BE SUBMITTED ON LAB FORM)

1. Create an algorithm and flowchart that will convert temperature from F to C.

2. Create an algorithm that will compute the average age of the students in a class, the flow will only
stop if “ 0 “ zero has been supplied as input. Display the Average.

3. Draw a flowchart to match the following pseudo code.


o Give variable num1 a starting value of 5
o Give variable num2 a starting value of 10
o Add 7 to num2
o Store the value num1 times num2 in variable num3
o Store the value num2 minus num1 in num2
o Output num1, num2 and num3

4. Obtain the length and width of a rectangle from the user. Calculate and output the area. If the length
and width are equal, output a message indicating that the figure is a square. Make a list of variables,
draw the flowchart, and perform a desk check using the following: 4, 8, 5, 5.

5. Obtain three test scores from a student. Calculate their average test score and output this value. If
their average score is 75% or more output a message indicating that they may proceed to the next
class. Make a list of variables, draw the flowchart, and perform a desk check using the following: 45,
55, 75, 80, 75, 88.

6. Obtain a name and age from the user. If the user is 16 or older, output a message indicating they are
old enough to drive. For people under 16, output a message indicating how many years they must
wait before they can drive legally.

7. Obtain a temperature in degrees Fahrenheit from the user. If the temperature is 80 degrees or more
display the message "Go play golf" otherwise, if the temperature is 70 - 79 degrees display the
message "Put on a jacket", otherwise display the message "It is way too cold." Make a variable list,
flowchart, and perform a desk check using the following values: 95, 72, 50

8. Draw a flowchart for a program that will compute the average of 10 exam scores entered by the user.
List the variables needed for this program. Perform a desk check using the following values: 75, 25,
51, 49, 88, 12, 22, 23, 52, and 78.

9. Modify problem #1 to allow the user to input the total number of exam scores. List the necessary
variables and draw the flowchart. Perform a desk check with the following values: 5, 23, 77, 75, and
50.

P rob le m So lv in g T e c hniqu e s 10

You might also like