Download as pdf or txt
Download as pdf or txt
You are on page 1of 39

COLLEGE-CCS DEPT.

CAMARINES SUR POLYTECHNIC


College of Computer Studies

EVENT-DRIVEN
PROGRAMMING
Module 1.2 – Algorithm Development
1

313
ITEC
COLLEGE-CCS DEPT.
CAMARINES SUR POLYTECHNIC
Module Objectives
01
Learn about the steps involved in the Program Development Cycle

02
Use Pseudocode Statements and Flowchart Symbols in solving
programming problems

03
Learn about modularizing a program and its advantage
2

04
Learn about structuring and modularizing unstructured logic

313
ITEC
COLLEGE-CCS DEPT.
CAMARINES SUR POLYTECHNIC
REMINDERS
• Please take the pre-test prior to studying the module (to be
submitted but score will not be recorded)
• Do the learning exercises after studying each objective.
• Take the post test after you finish studying the whole module. (to
be submitted and score will be recorded)
• Mark the activities done from the checklist found on the Learning
Plan section of your module
• Submit the exercises and post test on time
• Deadline: Must be submitted within 10 days
• Grace period: 4 days after the deadline but will be
marked as late
• Submit your activities to the following platform:
• High-Level Tech: CSPC LeOns
• Medium-Level Tech: CSPC LeOns / Gmail / Messenger
• Low-Level Tech: Drop off your activities to the designated
module pick-up points near you

313
ITEC
COLLEGE-CCS DEPT.
CAMARINES SUR POLYTECHNIC
Objective 1:

Understanding Program
Development Cycle
A programmer’s job involves writing
instructions, but a professional programmer
usually does not just sit down at a computer
keyboard and start typing. A programmer’s
4
job involves the steps in a program
development cycle.

313
ITEC
PAGE 01
COLLEGE-CCS DEPT.
CAMARINES SUR POLYTECHNIC
Program Development Cycle
It is the process of developing a software, according to the
desired needs of a user, by following a basic set
of interrelated procedures. It includes various set of
procedures and activities that are isolated and sequenced
for learning purposes but in real life they overlap and are
highly interrelated.
5

Figure 1-1

313
ITEC
PAGE 02
COLLEGE-CCS DEPT.
CAMARINES SUR POLYTECHNIC
STEPS IN PROGRAM DEVELOPMENT CYCLE
UNDERSTAND THE Professional programmers write programs to satisfy the needs of others,
PROBLEM called users or end users. Because programmers are providing a service to
these users, programmers must first understand what the user wants.
This is the most critical part of the program development cycle. User may
not really know what they want, and users who think they know frequently
change their minds after seeing sample output.

PLAN THE LOGIC The heart of the programming process wherein the programmer plans the
steps of the program, deciding what steps to include and how to order
them. It includes thinking carefully about all the possible data values a
program might6 encounter and how you want the program to handle each
scenario. When planning program, programmers call it as developing an
algorithm.
CODING THE PROGRAM Programmers chooses a particular languages because some have built in
capabilities that make them more efficient than others at handling certain
types of operations. The logic developed to solve a programming problem
can be executed using any number of languages.

313
ITEC
PAGE 03
COLLEGE-CCS DEPT.
CAMARINES SUR POLYTECHNIC
STEPS IN PROGRAM DEVELOPMENT CYCLE
USING A SOFTWARE TO Even though there are many programming languages, each computer
TRANSLATE THE PROGRAM knows only one language—its machine language, which consists of 1s
INTO MACHINE LANGUAGE and 0s. When you learn the syntax of a programming language, the
commands work on any machine on which the language software has
been installed. However, your commands then are translated to
machine language, which differs in various computer makes and
models.

313
Figure 1-2

ITEC
PAGE 04
COLLEGE-CCS DEPT.
CAMARINES SUR POLYTECHNIC
STEPS IN PROGRAM DEVELOPMENT CYCLE
TESTING THE A program that is free of syntax errors is not necessarily free of logical
PROGRAM errors. A logical error results when you use a syntactically correct statement
but use the wrong one for the current context. Once a program is free of
syntax errors, the programmer can test it—that is, execute it with some
sample data to see whether the results are logically correct. It is the process
called debugging. You debug a program by testing it using many sets of
data.
PUTTING THE Once the program is thoroughly tested and debugged, it is ready for the
PROGRAM INTO organization to use. Putting the program into production might mean simply
PRODUCTION running the program once, if it was written to satisfy a user’s request for a
special list. However, the process might take months if the program will be
run on a regular basis, or if it is one of a large system of programs being
developed.

MAINTAINING THE After programs are put into production, making necessary changes is called
PROGRAM maintenance. Maintenance can be required for many reasons: for example,
because new tax rates are legislated, the format of an input file is altered, or
the end user requires additional information not included in the original
output specifications.

313
ITEC
PAGE 05
COLLEGE-CCS DEPT.
CAMARINES SUR POLYTECHNIC
TRY AND LEARN
ACTIVITY 1 - Essay

In your own words, describe the steps


to writing a computer program.

Please refer to Module 1.2 – Activities Section for more detailed


instruction.

313
ITEC
PAGE 06
COLLEGE-CCS DEPT.
CAMARINES SUR POLYTECHNIC
Objective 2:
Using Pseudocodes
Statements and Flowcharts
PROGRAMMING IS DIFFICULT (like other useful and
worthwhile tasks — and like most of those tasks, it can be
satisfying and enjoyable too). You have to tell the machine
every little detail about what to do when you write a
program. So, you've got to get it right, because the machine
will follow your program blindly just as it's written. How,
then, are people writing any programs but 10the simplest?
Actually, it's not a big mystery. This is a matter of finding the
best way to think.

313
ITEC
PAGE 07
COLLEGE-CCS DEPT.
CAMARINES SUR POLYTECHNIC
Pseudocodes and Flowcharts

When programmers plan the logic for a solution to a programming


problem, they often use one of two tools: pseudocode (pronounced sue-
doe-code) or flowcharts.

Pseudocode is an English-like representation of the logical steps it takes to


solve a problem. Pseudo is a prefix that means false, and to code a
program means to put it in a programming language; therefore,
pseudocode simply means false code, or sentences thatappear to have
been written in a computer programming language but do not necessarily
follow all the syntax rules of any specific
11 language.

Flowchart is a pictorial representation of the same thing.

313
ITEC
PAGE 08
COLLEGE-CCS DEPT.
CAMARINES SUR POLYTECHNIC
Pseudocode Statements
Using pseudocode involves writing down all the steps you will use in
a program. It is fairly flexible because it is a planning tool, and not the
final product. Therefore, for example, you might prefer any of the
following:
• Instead of start and stop, some pseudocode developers would use
other terms such as begin and end.

• Instead of writing input myNumber, some developers would write


get myNumber or readmyNumber.

• Instead of writing set myAnswer = myNumber * 2, some developers


would write calculate myAnswer = myNumber times 2 or compute
myAnswer as myNumber doubled.

• Instead of writing output myAnswer, many pseudocode


developers would write display myAnswer, print myAnswer, or
write myAnswer.

313
ITEC
PAGE 09
COLLEGE-CCS DEPT.
CAMARINES SUR POLYTECHNIC
Pseudocode Statements

The point is, the pseudocode statements are


instructions to retrieve an original number from an
input device and store it in memory where it can be
used in a calculation, and then to get the
calculated answer from memory and send it to an
output device so a person can see it.

When you eventually convert your pseudocode to a


specific programming language, you do not have
such flexibility because specific syntax will be
required.

313
ITEC
PAGE 10
COLLEGE-CCS DEPT.
CAMARINES SUR POLYTECHNIC
Flowcharts
Some professional programmers prefer writing
pseudocode to drawing flowcharts, because using
pseudocode is more similar to writing the final
statements in the programming language. Others
prefer drawing flowcharts to represent the logical flow,
because flowcharts allow programmers to visualize
more easily how the program statements will connect.
For beginning programmers, flowcharts 14
are an
excellent tool to help them visualize how the
statements in a program are interrelated.

313
ITEC
PAGE 11
COLLEGE-CCS DEPT.
CAMARINES SUR POLYTECHNIC
FLOWCHART SYMBOLS
Defines the starting and ending point of a flowchart.

Defines the logical sequence of the program. It points to


the next symbol to be performed.
.
The inputting of data for processing and the printing out
of processed data.

Manipulation of data.

Process conditions using relational operators.

Named process such as subroutines or module

313
ITEC
PAGE 12
COLLEGE-CCS DEPT.
CAMARINES SUR POLYTECHNIC
FLOWCHART SYMBOLS

On Page Connector Connects to the flowchart to avoid spaghetti


A connection on the same page.

A Connects to the flowchart to avoid spaghetti


Off Page Connector connection on different page.

16

Annotation used to hold comments or sometimes statements that


Symbol are too long to fit neatly into a flowchart symbol.

313
ITEC
PAGE 13
PAGE 14
PSEUDOCODE

FLOWCHART
EXAMPLE
AND

CAMARINES SUR POLYTECHNIC


ITEC 313 COLLEGE-CCS DEPT.
PAGE 15
PSEUDOCODE

EXAMPLE
FLOWCHART
AND

CAMARINES SUR POLYTECHNIC


ITEC 313 COLLEGE-CCS DEPT.
PAGE 16
REPEATING INSTRUCTIONS

CAMARINES SUR POLYTECHNIC


ITEC 313 COLLEGE-CCS DEPT.
COLLEGE-CCS DEPT.
CAMARINES SUR POLYTECHNIC
USING SENTINEL TO END A
PROGRAM
• Testing a value is also called making a decision.
• You represent a decision in a flowchart by drawing decision symbol (shaped like a
diamond).
• It usually contains a question, the answer to which is one of the two mutually
exclusive options – often yes or no.
• A computer questions have only two mutually exclusive answers, such as yes and no
or true or false.
• A yes-or-no decision is called binary decision, because there are two possible
outcomes.

313
ITEC
PAGE 17
COLLEGE-CCS DEPT.
CAMARINES SUR POLYTECHNIC
USING SENTINEL TO END A
PROGRAM

A preselected value that stops the


execution of a program is often called YES
dummy value because it doesn’t
represent real data, but just a signal NO
to stop.

Such value is called sentinel value


because it represents an entry or exit
point.

313
ITEC
PAGE 18
COLLEGE-CCS DEPT.
CAMARINES SUR POLYTECHNIC
USING SENTINEL TO END A
PROGRAM

Programming languages can


recognize the end of the data in a YES
file automatically, through a code
that is stored at the end of the data. NO

EOF (end of file) – marker that


automatically acts a sentinel.

313
ITEC
PAGE 19
COLLEGE-CCS DEPT.
CAMARINES SUR POLYTECHNIC
USING THE CONNECTOR
You can use a connector when limited
page size forces you to continue a
flowchart in an unconnected location or
on another page.

Avoid using any connectors, if at all


possible; flowcharts are more difficult to
follow when their segments do not fit
together on a page.

313
ITEC
PAGE 20
COLLEGE-CCS DEPT.
CAMARINES SUR POLYTECHNIC
TRY AND LEARN
ACTIVITY 2 - Logic Exercise

Research current rates of monetary


exchange. Draw a flowchart or write
pseudocode to represent the logic of a
program that allows the user to enter a
number of dollars and convert it to Euros
and Japanese yen.
24

Please refer to Module 1.2 – Activities Section for more detailed


instruction.

313
ITEC
PAGE 21
COLLEGE-CCS DEPT.
CAMARINES SUR POLYTECHNIC
Objective 3:

MODULES
Programmers seldom write programs as one
long series of steps. Instead, they break down
their programming problems into smaller units
and tackle one cohesive task at a time.
These smaller units are modules.

Programmers also refer to them as subroutines,


procedures, functions, or methods;

3 reasons:
• it provides abstraction.
• allows multiple programmers to work on a problem.
• allows you to reuse your work more easily.

313
ITEC
PAGE 22
COLLEGE-CCS DEPT.
CAMARINES SUR POLYTECHNIC
MODULARIZATION
▪ MODULARIZATION PROVIDES ABSTRACTION
– Abstraction – process of paying attention to important properties while ignoring
nonessential details.

• Example:
With abstraction: Without abstraction:
- Do laundry - Pick up laundry basket
- Call Aunt Nan - Put laundry basket in car
- Start term paper - Drive to Laundromat
- Get out of car with basket
- Walk into Laundromat
- Set basket down
- Find quarters for washing machine
- … and so on.

313
ITEC
PAGE 23
COLLEGE-CCS DEPT.
CAMARINES SUR POLYTECHNIC
MODULARIZATION
▪ IT ALLOWS MULTIPLE PROGRAMMERS TO WORK ON A
PROBLEM
▪ When you dissect any large tasks into modules, you gain the ability to
more easily divide the tasks among various people.

▪ Professional software developers can write new programs in weeks or


months, instead of years, by dividing large programs into modules and
assigning each module to an individual or team.

313
ITEC
PAGE 24
COLLEGE-CCS DEPT.
CAMARINES SUR POLYTECHNIC
MODULARIZATION
▪ IT ALLOWS YOU TO REUSE YOUR WORK EASILY
▪ if a module is useful and well-written, you may want to use it more
than once within a program or in other program.

REUSABILITY – feature of modular programs that allows individual


modules to be used in a variety of applications

RELIABILITY – feature of programs that assures you a module has been


tested and proven to function correctly.

313
ITEC
PAGE 25
COLLEGE-CCS DEPT.
CAMARINES SUR POLYTECHNIC
MODULARIZING A PROGRAM
Most programs consists of main program, which contains
the basic steps or the mainline logic of the program.

MAIN PROGRAM – program that runs from start to stop and


calls other modules.

MAINLINE LOGIC – the overall logic of the main program


from beginning to end.

Module includes:
▪ HEADER – includes module identifier and possibly other
necessary identifying information.
▪ BODY – contains all the statements in the module.
▪ RETURN STATEMENT – marks the end of the module and
identifies the point at which control returns to the program or
module that called the module.

313
ITEC
PAGE 26
COLLEGE-CCS DEPT.
CAMARINES SUR POLYTECHNIC
MODULARIZING A PROGRAM
• Rules in naming modules:
▪ Module names must be one word and start with a letter.
▪ Module names should have some meaning.
▪ Module names are followed by a set of parentheses

The flowchart symbol used to call a module is a rectangle with a bar across the top.

INTERNAL MODULE CALL EXTERNAL MODULE CALL

313
ITEC
PAGE 27
COLLEGE-CCS DEPT.
CAMARINES SUR POLYTECHNIC
MODULE’S HEADER

MODULE’S BODY

MODULE’S RETURN
STATEMENT

313
ITEC
PAGE 28
COLLEGE-CCS DEPT.
CAMARINES SUR POLYTECHNIC
MODULARIZING A
PROGRAM EXAMPLE
Program that produces a bill using only
main program

313
ITEC
PAGE 29
COLLEGE-CCS DEPT.
CAMARINES SUR POLYTECHNIC
MODULARIZING A
PROGRAM EXAMPLE
Program that produces a bill using main
program that calls displayAddressInfo()

313
module

ITEC
PAGE 30
COLLEGE-CCS DEPT.
CAMARINES SUR POLYTECHNIC
TRY AND LEARN
ACTIVITY 3 – LOGIC EXERCISE
A. P lan t h e lo g i c f o r a p r o g r am t h at c alc u lat e s a p e r s o n ’ s
b ody mas s i n de x ( B M I ) . B M I i s a s t at i s t ic al me as u r e t h at
c omp ares a p e r s o n ’ s we i g h t an d h e i g h t . T h e p r o g r am u s e s
th ree modu le s . T h e f i r s t p r o mp t s a u s e r f o r an d ac c e p t s t h e
u s er’ s h ei g h t i n i n c h e s . T h e s e c o n d mo du le ac c e p t s t h e u s e r ’ s
wei gh t i n p o u n ds an d c o n v e r t s t h e u s e r ’ s h e i g h t t o me t e r s
an d wei gh t to k i lograms . Th en , i t c alc ulates B M I as wei gh t i n
k i lograms t i me s h e i g h t i n me t e r s s qu ar e d an d di s p lay s t h e
res u lts . Th e r e ar e 2 .54 c e n t i me t e r s i n an i n c h , 1 00
c en ti mete r s i n a me t e r , 453 .59 g r ams i n a p o u n d, an d 1 , 000
grams i n a k i lo g r am. T h e las t mo du le di s p lay s t h e me s s ag e
34
E n d of th e j o b .
B. R evi s e t h e B M I - de t e r mi n i n g p r o g r am t o e xe c u t e
c on ti n u ou s ly u n t i l t h e u s e r e n t e r s 0 f o r t h e h e i g h t i n i n c h e s .

Please refer to Module 1.2 – Activities Section for more detailed


instruction.

313
ITEC
PAGE 31
Objective 4:

COLLEGE-CCS DEPT.
CAMARINES SUR POLYTECHNIC
STRUCTURING AND MODULARIZING
UNSTRUCTURED LOGIC
Steps to structure the dog-washing process

313
ITEC
PAGE 32
STRUCTURING AND MODULARIZING

COLLEGE-CCS DEPT.
CAMARINES SUR POLYTECHNIC
UNSTRUCTURED LOGIC
Structured dog-washing flowchart and
pseudocode

313
ITEC
PAGE 33
COLLEGE-CCS DEPT.
CAMARINES SUR POLYTECHNIC
STRUCTURING AND MODULARIZING
UNSTRUCTURED LOGIC
Modularized version of the dog-washing
program

313
ITEC
PAGE 34
COLLEGE-CCS DEPT.
CAMARINES SUR POLYTECHNIC
TRY AND LEARN
ACTIVITY 4 – LOGIC EXERCISE
Each of the flowchart segments below is
unstructured. Redraw each segment so that it
does the same thing but is structured.

38

Please refer to Module 1.2 – Activities Section for more detailed


instruction.

313
ITEC
PAGE 35
COLLEGE-CCS DEPT.
CAMARINES SUR POLYTECHNIC
THANK YOU!
Make sure to finish and submit your activities
on time. Review your Module 1.2 on how to do
and submit it.

Got questions or need clarifications?


Email me at applekemeguia@cspc.edu.ph
PM me at m.me/aplkmmy
Send me a message via CSPC LeOns:
https://leons.cspc.edu.ph

313
ITEC
PAGE 36

You might also like