You are on page 1of 45

Computational Problem

Solving
CS001L.Module 1
First Term 2021 -2022
Mind Settings
Learning Understand the concepts and principles of Topic
Objective Process of Computational
computing including its history, application, Outline
benefits and costs in organizations and Problem Solving :
society.
Discover and apply the different models or # Problem Analysis, Design,
paradigms of computing.
Implementation, and Testing

Determine the requirements of # Algorithm


programming tasks in accordance with the
required output.

Apply required algorithm in accordance of # Pseudocode and Flowcharting


problem solving strategy.
COMPUTATIONAL
THINKING
Computational
Thinking
Decomposition

Pattern Recognition

Abstraction

Algorithmic Thinking
5 Steps in Problem Solving Process

01 02 03 04 05
Understand Plan Code Test Production

Understanding the Plan the Logic Coding the Program Testing the Program Putting Program
Problem into
Production
5 Steps in Problem Solving Process

May be the most difficult phase


01 Users may not be able to articulate their needs well
Understand User needs may be changing frequently
Programmers may have to learn the user’s functional job tasks
Documentation – supporting paperwork for a program.

Remember: Failure to analyze and understand the requirements leads to a failed solution!
Understanding the
Problem
5 Steps in Problem Solving Process
Plan the steps that the program will take
02 Use tools such as flowcharts and pseudocode
Plan
Flowchart: a pictorial representation of the logic steps
Pseudocode: Natural language representation of the
logic
Walk through the logic before coding by desk-
checking the logic.
Plan the Logic
5 Steps in Problem Solving Process
• Coding is one of the most tedious parts in programming.
• Programmers choose a particular language because some
03 languages have built-in capabilities to make them more
Code efficient than others at handling certain types of operations.

• Code the Solution


• Also called writing the program, and
• implementing the solution
• Program should contain well-defined patterns or structures of the
following types:
Coding the Program • Sequence
• Selection
• Iteration
5 Steps in Problem Solving Process
• Once a program has been coded, compiled and – or interpreted, you can
test if the program will run or not.
• Some compilers and interpreters will enable you to debug a code when
04 an error is apparent.
Test

• Test and Correct the Program


• Testing: method to verify correctness and that requirements are met
• Bug: a program error
• Debugging: the process of locating an error, and correcting and
verifying the correction
Testing the Program • Testing may reveal errors, but does not guarantee the absence of errors
5 Steps in Problem Solving Process
• Program adequately tested
– Ready for organizational use
• Putting program into production
05 – Time to implement
Production •Can be short or long
•Depends on program nature, size and user needs
– Factors
•Training, data format changes, new platform

• Conversion: entire set of actions organization must take to switch over


to new program(s)
Putting Program into
Production
ALGORITHM
Technical Terms
• Algorithm
• the step-by-step sequence of instructions that
describe how the data is to be processed to
produce the desired output
• Logic
• Art of reasoning
Technical Terms
• Syntax
• Rules governing usage of words and punctuation
• Semantics
• Rules governing the logic or idea of languages
• Machine Language
• The computer’s native language represented as a
series of 0’s and 1’s (binary form)
Technical Terms
• Compiler or Interpreter
• Translation software that converts programmer’s
statements to binary form notifies the programmer if
the programming language is used incorrectly
• Compiler
• Entire program is translated before it can execute
• Interpreter
• Each instruction is translated just prior to execution
Advantages of Writing Algorithm for Solving a
Problem
• Promotes effective communication between team
members.
• Enables analysis of problem at hand.
• Acts as blueprint for coding.
• Assists in debugging.
• Becomes part of software documentation for future
reference during maintenance phase.
COMPUTATIONAL THINKING
FLOWCHART PSEUDOCODE
PSEUDOCODE
PSEUDOCODE
• An English-like representation of the same thing.

PSEUDO = FALSE
A program means to put in a
CODE =
programming language
RULES FOR PSEUDOCODE
• The pseudocode must be language independent. Show
key words in CAPITAL LETTERS.
Example: IF condition THEN
DO action
ENDDO
ENDIF
• Indent lines to make the pseudocode easy to read and
understand.
RULES FOR PSEUDOCODE
• Punctuation is optional.
• Every IF must end with an ENDIF.
• Every DO, DO FOR and DO WHILE must end with
ENDDO.
• The main routine (the one that goes from START to
STOP) has to be shown first. All other routines are to
follow.
ADVANTAGES IN USING
PSEUDOCODE
• It bridges the gap between human language and
computer language.
• It is an intermediate notation that allows expression of
program logic in a straight forward, easy to
understand manner without concerning the
programmer with syntax details.
• It is easier to make changes to pseudocode than to a
source program in a high-level language.
RECIPE FOR SMALL SPONGE CAKES
Method:
• SET oven at 180oC.
• FOLLOW Method for Egg Sponge from Step a to d
• PLACE mixture in patty pans, half filling each one.
• BAKE at 180oC for approximately 10 minutes.
• COOL on cake cooler.
• CUT and FILL with whipped cream.
PASTILLAS RECIPE
• Procedures:
1. PLACE the condensed milk in a large mixing bowl.
2. GRADUALLY FOLD-IN the powdered milk. The texture of the
mixture will be similar to dough once all the powdered milk is
completely added.
3. SCOOP some of the mixture and mold into cylinders.
4. ROLL each molded cylindrical mixture on granulated sugar.
5. WRAP in paper or cellophane.
6. SERVE for dessert. Share and enjoy!
Example. Problem 1. We want to be able to enter the ages of two people
and have the computer calculate their average age and display the answer.

• DISPLAY a message asking the • CALCULATE the answer


user to enter the first age by adding the two ages
together and dividing by two
• GET the first age from the
keyboard • OUTPUT display the
answer on the screen
• DISPLAY a message asking
the user to enter the second age • PAUSE so the user can see
• GET the second age from the the answer
keyboard
Example.Problem 2:
• Create a pseudo-code that will convert Fahrenheit
temperature to Celsius temperature.
FLOWCHART
Flowchart Use of symbols and phrases to designate
the logical steps of how the problem is
solved.
Logical sequence in which a
combination of steps or operations is to
be performed
A pictorial representation of the logical
series to identify the basic Input,
Process and Output (IPO).
Basic Symbols Used in Flowchart
Terminal Symbol - shows the start and end points
in a process.

Preparation Symbol - is a preparation process flow


step, such as a set-up and mathematical initial values.

Input/output Symbol - indicates inputs to and outputs


from a process.
Basic Symbols Used in Flowchart

Process Symbol - shows a process or action step in both


process flowcharts and business process maps.

Decision Symbol - Indicates a question or


branch in the process flow.

Predefined Process (Subroutine) Symbol - is a


another process step or subroutines in programming
flowcharts.
Basic Symbols Used in Flowchart

On-Page Connector Symbol - to show a jump from


one point in the process flow to another.

Off-page Connector - used to connect flowchart


portion on different page.

Flow lines – a flow of control arrows


indicating the sequence of steps.
Flowchart
The following will show you the number of
entries and exits from each symbol.
1 entry

1 exit

1 entry, 2 exits
1 entry, 1 exit 1 entry, 1exit
Guidelines for Developing Flowchart
• Logical order • General flow of processes is top to
bottom or left to right.
• Flowchart can have only one (1)
start and one (1) end symbol. • Arrows should not cross each
other.
• On-page connectors are referenced
using numbers. • No ambiguity
• Off-page connectors are • Validity of the flowchart with a
referenced using alphabets. simple test data.
Three Building Blocks of an Algorithm
• Sequential: An algorithm is a step-by-step process, and
the order of those steps are crucial to ensuring the
correctness of an algorithm.
• Selection: Algorithms can use selection to determine a
different set of steps to execute based on a Boolean
expression.
• Iteration: Algorithms often use repetition to execute
steps a certain number of times or until a certain
condition is met.
START

SEQUENTIAL
Sum=0 START

Product=0

Sum=0

Read A,B Product=0

Sum = A + B Read A,B


Product = A * B

Sum = A + B
Print Sum, Product
Print Sum, Product = A * B
Product

END

END
SELECTION
START

Name = “ ”

START Remarks = “ “

Read A,B Read Name,


Grade

T
Is Print A,
A>B? “Higher”
Is
Grade Remarks=”Passed”
F >= 60

Print B,
“Higher” END
Print Name,
Remarks=”Failed” Grade,
Remarks

END
REPETITION START
START

Pi=3.1416
C=0
R=1
 

AreaCircle = Pi * R * R
C < 10 END

Print R,
C =C + 1 AreaCircle

Print C
R <= 5 END
MODULE 1: Review Activity
Instructions: Solve for the following problem.
Construct a Flowchart showing the program logic.
1. Problem: Calculate the area of a rectangle.

BEGIN
READ LENGHT, width
areaRec = length X width
DISPLAY areaRec
END
2. Problem: calculate a person’s age.

BEGIN
ENTER BIRTH_year
Age = current_year – birth_year
PRINT AGE
END
3. Problem: calculate a person’s age with conditions.

BEGIN
READ age
IF (age is greater than 60)
PRINT “Senior Citizen”
ELSE
PRINT “Not Senior Citizen”
ENDIF
END
4. Problem: Read a test score and identify if the test score is passing
or try again. BEGIN
READ score
IF(score is greater
than or equal to 75)
print “Passed”
ELSE
PRINT “Try Again”
END
END
5. Problem: Write a program that reads and displays the age of 10 people (one after another).

START
SET users = 1
WHILE(users <= 10)
READ age
PRINT age
users = users + 1
EndWhile
END
Merci!
Any questions?
You may send your question in MS Teams
asdelosantos@mcl.edu.ph

44
Computational Problem
Solving
CS001L.Module 1
First Term 2021 -2022

You might also like