0% found this document useful (0 votes)
25 views8 pages

IT 101 Module 2.0 2022

This module teaches the basics of algorithms and flowcharts. It explains what an algorithm is, what a flowchart is, and how they relate. It introduces flowchart symbols and how to embed variables and logical operators. It also covers different flowchart structures and how to distinguish between non-structured and structured flowcharts. Students will learn how to convert unstructured flowcharts called "spaghetti code" into structured flowcharts.

Uploaded by

lanilyn mongado
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views8 pages

IT 101 Module 2.0 2022

This module teaches the basics of algorithms and flowcharts. It explains what an algorithm is, what a flowchart is, and how they relate. It introduces flowchart symbols and how to embed variables and logical operators. It also covers different flowchart structures and how to distinguish between non-structured and structured flowcharts. Students will learn how to convert unstructured flowcharts called "spaghetti code" into structured flowcharts.

Uploaded by

lanilyn mongado
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

MODULE 2

IT 101 – Introduction to Programming

SUBJECT : IT 101

DESCRIPTION : Introduction to Computing

PREPARED BY : MR. ALEX B. GUIRIGAY

MODULE 2
TITLE: Algorithms and Flowcharts

OVERVIEW
This module teaches the basics of algorithms and flowcharts. It explains what is an algorithm and what is
flowchart and how are they relate with each other. It also introduces us on how to use the different flowcharting
symbols and embeds variables and logical operator in them. It also teaches us the different flowcharting
structures and distinguish non-structured flowcharting to structured flowcharting and converts unstructured
flowchart (like spaghetti code) to structured one.

OBJECTIVES
At the end of this module, the students are expected to:

• Know what is an algorithm and what is a flowchart;


• Familiarize the flowchart symbols
• Use the appropriate symbol depending on what the problem requires
• Distinguish non-structured to structured flowcharting
• Familiarize the flowcharting structures
• Knowledgeable on how to convert non-structured flowchart to structured flowchart
• Be aware of what is spaghetti code and how to solve it

DISCUSSION

Algorithms and Flowcharts


Algorithm ➔ is a list of instructions which should be taken step-by-step.
Flowchart ➔ is a graphical representation of a command or a program.

Example:
1. Considering you’re going to use a rice cooker and that the utensils are all clean, make an algorithm and a
flowchart that depicts on how to cook rice from the moment you prepare the ingredients until it is
cooked.
Solution:
Algorithm
1. Put some measured rice into the rice cooker
2. Put also some water into it
3. Cleanse the rice
4. Drain it
5. Put some measured water into it
6. Plug the wire
7. Push the button to cook
8. Wait until it is cooked
9. Unplug the wire

Flowchart
MODULE 2
IT 101 – Introduction to Programming

Flowcharting symbols:
Process ➔ is used to illustrate a process, action or operation.

Input/ Output ➔ shows the inputs and the outputs from a process.

Decision ➔ represents a question that is answerable by ‘yes’ or ‘no’ or ‘true’ or ‘false’.

Flow lines ➔ represents the flow of the program.

On-page connector ➔ is used to connect flow lines on the same page.

Off-page connector ➔ is used to connect flow lines on another page.

Terminal ➔ is used at the beginning and at the end of the flowchart.

Examples:
1. Considering that A=10 and B=5, make an algorithm and a flowchart that computes and display the sum,
difference, product, quotient and average out of those numbers.

Solution:
MODULE 2
IT 101 – Introduction to Programming

ALGORITHM
a. Initialize A=10, B=5, sum=0, diff=0, prod=0, quo=0 and ave = sum/2
b. Compute sum by adding A+B, diff by subtracting A from B, prod by multiplying A to B, quo by
dividing A to B and ave by dividing sum by two (2)
c. Display the sum, diff, prod, quo and ave.

FLOWCHART

2. Make an algorithm and a flowchart that displays the area of a circle.


Solution:
ALGORITHM
a. Initialize area=0, radius=0 and pi=3.1416
b. Input value for the radius
c. Compute the area using the formula a=pir2
d. Display the value of the area

FLOWCHART

3. Make a flowchart that computes the average grade of a student considering that its formula is (average
= (Prelim Grade + Midterm Grade + Semi-Final Grade + Final Grade)/4).
Solution:
MODULE 2
IT 101 – Introduction to Programming

ALGORITHM
1. Initialize variables prelim_grade=0, midterm_grade=0, sf_grade=0, final_grade=0 and
average_grade=0;
2. Put values into prelim_grade, midterm_grade, sf_grade, final_grade
3. Compute the average grade using the formula
average_grade = prelim_grade + midterm_grade + sf_grade + final_grade

FLOWCHART

Structured Flowcharting
Loops and Counters
Loop ➔ is used when it is desired to make the same calculation on more than one set of data.
Counters ➔ is a set up in a program loop to keep track of the number of times the program segment is
repeated.
Ex.:

1. Make a flowchart that continuously asks for a number then display it five (5) times.

Solution:

Select Case
Select Case ➔ is used when there are three (3) or more selections.
Ex.:
1. Make a flowchart that would ask for the age of a person. It will then display the age and remarks of the
person whether he/she is a kid (0 to 10 yrs. old), teen-ager (11 to 19 yrs. old), adult (20 to 59 yrs. old)
and senior citizen (60 above).
Solution:
MODULE 2
IT 101 – Introduction to Programming

Y
N
Y
N
Y
N

Flowcharting Structures
Structures in flowcharting:

1. Sequence
2. Decision
3. Loop

Sequence
 Also called “concatenation structure”
 In sequence, one program statement follows another.

Represented by the diagram:

Ex.

a. Make a flowchart that accepts numbers A and B, computes and display their sum.
Solution:
MODULE 2
IT 101 – Introduction to Programming

Decision
 Also called “selection structure”
 Occurs when a decision must be made.

Represented by the diagram:

Ex.

b. Make a flowchart that accepts number then determine if that number is positive or negative.
Solution:

stop

Loop
 Also called “repetition structure”
 The loop is a process that is repeated as long as a certain condition remains true.

Represented by the diagram:

Ex.

c. Make a flowchart that continuously asks for a number. It will only stop once the number entered is -1.

Solution:
MODULE 2
IT 101 – Introduction to Programming

The spaghetti Code


Spaghetti Code ➔ is a pejorative phrase for unstructured and difficult-to-maintain source code. Spaghetti
code can be caused by several factors, such as volatile project requirements, lack of programming style rules,
and insufficient ability or experience.
Ex.:

Figure 1: Example of a Spaghetti code (unstructured)

What are the algorithms?

1. After inputting A, proceed to B


2. There’s a question for B, if the answer is Yes, proceed to D, if it is No, proceed to C.
3. There’s a question for C, if the answer is Yes, proceed to F, if it is No, proceed to E.
4. There’s a question for D, if the answer is Yes, proceed to I.
5. There’s a question for E, if the answer is Yes, proceed to G, if it is No, proceed to H.
6. There’s a question for F, if the answer is Yes, proceed to I, if it is No, proceed to H.
7. There’s a question for G, if the answer is Yes, proceed to I, if it is No, proceed to H.
MODULE 2
IT 101 – Introduction to Programming

Figure 2: structured Spaghetti code

EVALUATION

REFERENCES
1. Introduction to flowcharting
http://www.tmv.edu.in/pdf/distance_education/bca%20books/bca%20ii%20sem/bca-
222%20%27c%27%20%27programming.pdf
2. Algorithm and Flowchart Manual for Students
http://www.yspuniversity.ac.in/cic/algorithm-manual.pdf

You might also like