0% found this document useful (0 votes)
210 views15 pages

LEC3A

The document provides information about flowcharting in computer programming. It defines a flowchart as a representation of an algorithm using standard symbols with each symbol representing a different function. The steps in an algorithm are linked together using directional arrows. Examples of flowcharts are given to demonstrate how to represent simple programs graphically. Standard symbols used in flowcharts like decision diamonds and connectors are described. The advantages and disadvantages of decision tables are also outlined.

Uploaded by

jhaz saying
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)
210 views15 pages

LEC3A

The document provides information about flowcharting in computer programming. It defines a flowchart as a representation of an algorithm using standard symbols with each symbol representing a different function. The steps in an algorithm are linked together using directional arrows. Examples of flowcharts are given to demonstrate how to represent simple programs graphically. Standard symbols used in flowcharts like decision diamonds and connectors are described. The advantages and disadvantages of decision tables are also outlined.

Uploaded by

jhaz saying
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

LECTURE in Computer Programming 1: FLOWCHARTING LEC3

Flowchart

Flowchart

Flowchart is a representation of the algorithm using standard symbols. Each symbols have a
new function.
The Algorithm steps determine which symbol to use to represent it in the flow each step is
linked to another step by using the directional arrows
A flowchart is a representation of the sequence of steps and decisions needed to perform a
process. Each step in the sequence is noted within a diagram shape. Steps are linked by
connecting lines and directional arrows. ... A flowchart is a powerful business tool.
• A flowchart is a graphical representation of a sequence of operation
• A flowchart contains symbols describing how an algorithm or program operates
• A flowchart has steps are linked by connecting lines and directional arrow

Figure 1. Example of flowchart

Prepared by: Mrs. Jasmin G. Geronaga


Computer Programming 1 Instructor
LECTURE in Computer Programming 1: FLOWCHARTING LEC3

What are the symbols used in flowchart?

Other symbols used in flowchart


Connector/Inspection: In Flowchart, this symbol is typically small
and used as a connector to show a jump from one point in the
process flow to another.
Used for declaring/initializing variables needed to solve a certain
process
DECLARATION
- stating a variables name to be used
INITIALIZATION
- to set (a starting value of a variable)

Prepared by: Mrs. Jasmin G. Geronaga


Computer Programming 1 Instructor
LECTURE in Computer Programming 1: FLOWCHARTING LEC3

Example 1: Create a flowchart that display “Hello”.


START
Solution
(Pseudocode)
• Display hello
• Print “Hello” Print “Hello”
(Algorithm)
Step1. Print “hello”
(Flowchart)
END
Example 2. Create a flowchart that display the sum of 2 and 5.
(Pseudocode)
• input the number 2 and 5
START
• Compute the sum of 2 and 5
• Print the sum
(Algorithm)
Step 1. Compute for the sum of 2 and 5;
Sum=0
Sum=2+5
Step 2. Print Sum
(Flowchart)
Sum=2+5

Print Sum

END

Prepared by: Mrs. Jasmin G. Geronaga


Computer Programming 1 Instructor
LECTURE in Computer Programming 1: FLOWCHARTING LEC3

Example 3. Create a flowchart that ask the user to enter two number. Compute and display
the sum.
(Pseudocode)
• Input two numbers
• Compute the sum of the two numbers
• Print the sum
(Algorithm)
Step 1. Enter 1st number
(num1)
Step 2. Enter 2nd number START
(num2)
Step 3. Compute for the sum of num1 and num2
Sum=num1+num2 Sum=0;
Step 4. Print Sum
Num1,
(Flowchart)
Num2

Enter Num1;
Enter Num2;

Sum=Num1+Num2

Print Sum

END
Prepared by: Mrs. Jasmin G. Geronaga
Computer Programming 1 Instructor
LECTURE in Computer Programming 1: FLOWCHARTING LEC3

Decision/Condition
A decision box is a diamond-shaped box in a flowchart containing a decision to be made.
Each box has either Yes, No, or both near them to indicate the direction the user should
follow on the flowchart.
Decision Table
A decision Table is a form of truth table that structures the logic of a problem into simple YES
and No form. It is easily adapted to the needs of business data processing. It provides a
structure for showing logical relationships between conditions that exist and actions to be
taken as a result of these conditions

TRUE FALSE

T F

YES NO

Y N

Example of decision table:

Advantages of Decision Tables


1. They are simple, practicable and economical .All that is regarded to developed a
decision table is a piece of paper and a pencil
2. It makes the system designer to express the logic of the problem in direct and concise
terms, which results in the development of an effective and efficient program.
3. It is useful in program documentation i.e decision tables provide a quick and easily
understood overview of the system.

Prepared by: Mrs. Jasmin G. Geronaga


Computer Programming 1 Instructor
LECTURE in Computer Programming 1: FLOWCHARTING LEC3

4. It is an excellent communication device to breach the gap between the computer


personnel who are responsible for developing the system and the non-data processing
personnel who use the output of the system.
5. Decision tables are easy to update.
6. It is easy to learn how to use decision table.
7. The complexity and the amount of detail that can be handed by a decision table is
un-limited.
Disadvantages of Decision Table
1. Total sequence: The total sequence of an operation is not clearly shown in the
decision table i.e no overall picture is given as with flowcharts.
2. Logic: Where the logic of a system is simple flowcharts always serve the purpose
better.
Processes of Decision Making
There are 7 detailed steps as follows to make a decision.
• Step 1. Fully analyze the problem and identify the decision purpose.
• Step 2. Try to collect all the information and stakeholders related to the problem.
• Step 3. Set up the criteria for judging the alternatives.
• Step 4. Brainstorm all the ideas and evaluate them.
• Step 5. Choose the best one among alternative
• Step 6. Carry out the decision.
• Step 7. Review your decision and its consequence
Example Decision problem using flowchart

Prepared by: Mrs. Jasmin G. Geronaga


Computer Programming 1 Instructor
LECTURE in Computer Programming 1: FLOWCHARTING LEC3

Decisional/Conational Statement
• Statement that results to true or false or yes or no.
• More on decision block
Single Alternative Selection Structure Dual Alternative Selection Structure

This type of decision control structure includes a


statement or block of statements on both paths.
This is the simplest decision control If the expression evaluates to true , the
structure. It includes a statement or block statement or block of statements 1 is executed;
of statements on the “true” path only. If otherwise, the statement or block of statements
the expression evaluates to true , the 2 is executed.
statement, or block of statements, of the
structure is executed; otherwise, the
statements are skipped.

Decision making is critical to computer programming. There will be many situations when you
will be given two or more options and you will have to select an option based on the given
conditions. For example, we want to print a remark about a student based on his secured
marks. Following is the situation –
• Assume given marks are x for a student:
• If given marks are more than 95, then
• Student is brilliant
• If given marks are less than 30, then
• Student is poor
• If given marks are less than 95 and more than 30, then
• Student is average

Prepared by: Mrs. Jasmin G. Geronaga


Computer Programming 1 Instructor
LECTURE in Computer Programming 1: FLOWCHARTING LEC3

Example 1. Draw a flowchart that will ask the user to enter a character indicating the user’s
gender. If the user’s enter “M” display male.
Algorithm START

Step 1. Get the user’s gender


Step 2. Ask if the user is “M” Gender
Step 3. If yes; display “You’re a Male”

Get Gender

T Is F
Gender==M

Print “You’re a Male”

END

Prepared by: Mrs. Jasmin G. Geronaga


Computer Programming 1 Instructor
LECTURE in Computer Programming 1: FLOWCHARTING LEC3

Example 2. Draw a flowchart that will ask the user to enter a character indicating the user’s
gender. If the user’s enter “M” display male. If not assume the users is female thus display
“You’re a Female”.
Algorithm
Step 1. Get the user’s gender
Step 2. Ask if the user is “M”
Step 3. If yes; display “You’re a Male” START
Step 4. If no; display “You’re a Female”
Step 2. Ask if the user is “M”
Gender
Step 3. If yes; display “You’re a Male”

Get Gender

T Is F
Gender==M

Print “You’re a Male” Print “You’re a Male”

END

character indicating the user’s gender. If the user’s enter “M” display male.

Prepared by: Mrs. Jasmin G. Geronaga


Computer Programming 1 Instructor
LECTURE in Computer Programming 1: FLOWCHARTING LEC3

Repetition Structures
Repetition structures, or loops, are used when a program needs to repeatedly process one or
more instructions until some condition is met, at which time the loop ends. Many programming
tasks are repetitive, having little variation from one item to the next.
Types of Repletion Structure
• While Loop
• Do while Loop
• For Loop

1. While loop statement that is repeated as long as some condition is satisfied

T Conditio
F Action/Statement
n

Action/Statement

Example: Create a flowchart that ask the user if he/she wants to display the word “hello”.
The answer maybe “Y” yes or “N” no.

Algorithm
Step 1. Ask the user if he/she wants to display the word “hello”
N for No
Y for Yes OUTPUT
Step 2. Y print “hello” Do you want to print “Hello”? Y
Ask again the user Hello
Step 3. N Do you want to print “Hello”? Y
Terminate Hello
Do you want to print “Hello”? N

Prepared by: Mrs. Jasmin G. Geronaga


Computer Programming 1 Instructor
LECTURE in Computer Programming 1: FLOWCHARTING LEC3

START

Answer=‘’

Print ”Do you want to display the word “Hello ?”

Get the Answer=‘’

If answer ==’Y’
F END

T
Print “Hello”

Prepared by: Mrs. Jasmin G. Geronaga


Computer Programming 1 Instructor
LECTURE in Computer Programming 1: FLOWCHARTING LEC3

2. Do while loop the action or statement is executed first before asking a condition.

Action or statement

T Conditio
F
n

Action/Statement

Example: Create a flowchart that display the word “hello”. Then ask the user if he/she
wants to print it again, the answer may either Y for yes or N for no.

Algorithm
Step 1. Print “hello”
Step 2. Ask the user if he/she wants to print again the word “hello”
N for No
Y for Yes OUTPUT
Step 3. Y print again “hello” Hello
Do you want to print again? Y
Hello
Step 4. N Do you want to print again? Y
Terminate Hello
Do you want to print again? N

Prepared by: Mrs. Jasmin G. Geronaga


Computer Programming 1 Instructor
LECTURE in Computer Programming 1: FLOWCHARTING LEC3

START

Print “Hello”

Print ”Do you want to print again?”

Get the Answer


F END

T
If answer ==’Y’

Prepared by: Mrs. Jasmin G. Geronaga


Computer Programming 1 Instructor
LECTURE in Computer Programming 1: FLOWCHARTING LEC3

3. For loop executed action/statement repeatedly. There are many applications for a For
Loop, including tasks such as reading through a list of data items or initializing array.

Initialization

Conditio
F
n

Action/Statement

T
Action/statement

iteration

Example: Display the word “hello” five times.


Algorithm
Step 1. Print “hello”
Step 2. Ask if printed five times OUTPUT
Hello
Hello
Hello
Hello
Hello

Prepared by: Mrs. Jasmin G. Geronaga


Computer Programming 1 Instructor
LECTURE in Computer Programming 1: FLOWCHARTING LEC3

START

Count=1

If count <=5
F END

T
Print “Hello”

Count ++

First Stimulation
Count =1
If1<=5

End of Topic

Note: “I am not here to be AVERAGE, I am here to be AWESOME”


STUDY HARD!!!

Prepared by: Mrs. Jasmin G. Geronaga


Computer Programming 1 Instructor

You might also like