0% found this document useful (0 votes)
2 views10 pages

Programming Problem Solving Guide

cc101 lesson 2

Uploaded by

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

Programming Problem Solving Guide

cc101 lesson 2

Uploaded by

Russell Junio
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

FM-AA-CIA-15 Rev.

0 10-July-2020

Study Guide in (CC102 Fundamentals of Programming) Module No1

STUDY GUIDE FOR MODULE NO. 1

BASIC STEPS IN PROBLEM SOLVING

Introduction
Problem solving is the act of defining a problem; analysing the problem; selecting alternatives for a solution;
and implementing a solution. In the context of programming, basic steps in problem solving are problem
definition, problem analysis and algorithm design. In this unit, you will be familiarized in these basic steps in
preparation for program codes writing in C++.

Unit learning outcomes


By the end of this unit you should be able to:
 Analyse a given problem by identifying input, process and output.
 Familiarize with keywords and symbols used in pseudocode and flowchart.
 Formulate algorithms and represent them using pseudocode or flowchart.

1.1 Basic Steps in Problem Solving


 Problem solving for programming consists of three steps: problem definition, problem analysis and
algorithm design.
1. Defining and Analyzing the Problem
A. Stating the Problem
Problem 1:
Write a program to determine the sum of two numbers.
Problem 2:
Write a program that will compute the area of a circle.
B. Definitive Statement of the Problem
Problem 1: Write a program to determine the sum of two numbers.

Give the computer two numbers. It should be able to add the two numbers and give
the result.
Problem 2:
Write a program that will compute the area of a circle.
How will you re-state Problem No 2?
C. Analyzing the Problem
 NATURE. (What is it about)
 SCOPE. (Limitations)

Example 1
Problem 1:
Write a program to determine the sum of two numbers.
Nature: Mathematical
Scope: Limit the scope to numbers that are integers or whole numbers.

PANGASINAN STATE UNIVERSITY 1


FM-AA-CIA-15 Rev. 0 10-July-2020

Study Guide in (CC102 Fundamentals of Programming) Module No1

Example 2
Problem 2:
Write a program that will compute the area of a circle.
Nature: Geometry.
Scope: Allow fractions and decimals as acceptable values. No negative
values for the radius should be accepted.

B.1. Identifying the Output


Problem 1: Write a program to determine the sum of two numbers.
Output:
 [sum]
 The sum of the two numbers you gave is: [sum]
B.1. Identifying the Input
Problem 1: Write a program to determine the sum of two numbers.
Input:
 We need two numbers as the input. (keyed in the keyboard)

B.1. Identifying the Input


Problem 2:
Write a program that will compute the area of a circle.
What is the Input Required?
C. Defining the Process
Problem 1:
Write a program to determine the sum of two numbers.
Process:
 Enter two numbers using the keyboard. The computer must be able to
reject fractions and decimal numbers. The computer will then add the two
numbers. The result of the addition will be displayed on the computer
screen.
Problem 2:
Write a program that will compute the area of a circle.
Process:
 The program must be able to accept a number representing the radius. The
computer should make it sure that no negative number will be entered. The
computer must compute the area of the circle. Result must be displayed on
the screen.

2. Planning the Solution


Algorithm
o A set of rules for solving a problem in a finite number of steps.
Overview of an Algorithm

PANGASINAN STATE UNIVERSITY 2


FM-AA-CIA-15 Rev. 0 10-July-2020

Study Guide in (CC102 Fundamentals of Programming) Module No1

I. STEPS IN COOKING SCRAMBLED EGG


o Prepare all necessary items needed (egg, pan, oil etc.)
o Beat the egg
o Add salt
o Heat pan
o Put oil into the pan
o Pour beaten egg if pan is already hot enough
o Cook egg for at least two minutes
o Serve Egg
Control Structures
Structured programming
 is a technique that emphasizes the breaking of a program or algorithm into logical sections, or
modules following a universal programming standard. (Breaking of programs into smaller modules)
 Control structures is a step, or a series of steps, that determines what instructions or set of
instructions will be done next.
Three Basic Structures
 Sequential
 Selection
 Iteration

Sequential
 is the most straight forward. The program will just follow the instructions one after the other in a
sequential manner.

Example: Taking a Bath

Selection

PANGASINAN STATE UNIVERSITY 3


FM-AA-CIA-15 Rev. 0 10-July-2020

Study Guide in (CC102 Fundamentals of Programming) Module No1

 Let your program or algorithm make a decision. Choose one from two sets of instructions depending
on the condition.
o IF (condition) THEN (Process 1) ELSE (Process 2)

IF (it is dark) THEN (turn on the lights) ELSE (do not turn on the lights)

Iteration
 We use when we want our algorithm or program to repeat a process a specified number of times.
 The structure that repeats an instruction or a set of instructions until a condition is met is known as
iteration or loop.

Whether the scrambled egg is ready to be served or not


I. Beat the egg
II. Add salt
III. Place the pan in the stove
IV. Put on the stove
V. Pour cooking oil
VI. Heat the oil
VII. Put egg
VIII. Cook: { here is the example of the control structure}
IX. Heat the egg
X. IF the egg is done

PANGASINAN STATE UNIVERSITY 4


FM-AA-CIA-15 Rev. 0 10-July-2020

Study Guide in (CC102 Fundamentals of Programming) Module No1

XI. THEN serve the egg

XII. ELSE goo to Cook {End pf control structure}


Iteration control for serving scrambled egg

Flowcharting
 is one method of pictorially representing a procedural (step-by-step) solution to a problem before you
actually start to write the computer instructions required to produce the desired results.
 Two Types of Flowchart
o System (data) flowcharts
 Defines the major phases of the processing, as well as the various data media used.
o Programming flowcharts

Example of system flowchart

Programming Flowchart
 Constructed by the programmer to represent the sequence of operations the computer is to
perform to solve a specific problem.
 It graphically describes what is to take place in the program.
Standard Symbols

PANGASINAN STATE UNIVERSITY 5


FM-AA-CIA-15 Rev. 0 10-July-2020

Study Guide in (CC102 Fundamentals of Programming) Module No1

Examples on Flowcharting
Problem: Make a flowchart to determine the sum of two numbers.
Definitive Statement: Give the computer two numbers. It should be able to add the two numbers and
give the result.

Problem: Make a flowchart to determine the sum of two numbers.


Definitive Statement: Give the computer two numbers. It should be able to add the two numbers and
give the result.

Output: [sum] or
The sum of the two numbers is: [sum]
Input: we need two numbers as the input. The program allows both positive and negative integers.

PANGASINAN STATE UNIVERSITY 6


FM-AA-CIA-15 Rev. 0 10-July-2020

Study Guide in (CC102 Fundamentals of Programming) Module No1

PANGASINAN STATE UNIVERSITY 7


FM-AA-CIA-15 Rev. 0 10-July-2020

Study Guide in (CC102 Fundamentals of Programming) Module No1

Pseudocode
 Uses words and mathematical expressions to represent the logic, or the flow of the program.
 Informal language for writing algorithms.

Example of Pseudocode
o Problem: Write a pseudocode to determine the sum of two numbers.
o Definitive Statement: Give the computer two numbers. It should be able to add the two
numbers and give the result.

Output: The output of the computer should give us a number which is integer or a whole number.
[sum] or
The sum of the two numbers you gave is: [sum]

PANGASINAN STATE UNIVERSITY 8


FM-AA-CIA-15 Rev. 0 10-July-2020

Study Guide in (CC102 Fundamentals of Programming) Module No1

Example of Pseudocode
Problem: Write a pseudocode to determine the sum of two numbers.
Definitive Statement: Give the computer two numbers. It should be able to add the two numbers and
give the result.
Output: The output of the computer should give us a number which is integer or a whole number.
[sum] or
The sum of the two numbers you gave is: [sum]
Pseudocode:
BEGIN
INPUT the first number
INPUT the seocnd number
Add the two numbers
OUTPUT the sum
END

PANGASINAN STATE UNIVERSITY 9


FM-AA-CIA-15 Rev. 0 10-July-2020

Study Guide in (CC102 Fundamentals of Programming) Module No1

Activity:

A. Directions: Write your pseudocode or draw your flowchart on separate sheet(s) of paper.

1. Write pseudo code that reads two numbers and multiplies them together and print out their
product.
2. Write pseudo code that tells a user that the number they entered is not a 5 or a 6.
3. Draw flowchart that performs the following: Ask a user to enter a number. If the number is
between 0 and 10, write the word blue. If the number is between 10 and 20, write the word red.
if the number is between 20 and 30, write the word green. If it is any other number, write that it
is not a correct color option.
4. Write pseudo code that will count all the even numbers up to a user defined stopping point.
5. Draw flowchart that reads in three numbers and writes them all in sorted order.

PANGASINAN STATE UNIVERSITY 10

You might also like