PROGRAM DEVELOPMENT
CYCLE AND PROBLEM-
SOLVING TECHNIQUES
CPEN21A PROGRAMMING LOGIC AND DESIGN
PROGRAM DEVELOPMENT CYCLE
• Program Development Life Cycle (PDLC) is a
systematic way of developing quality software.
• It provides an organized plan for breaking down the task
of program development into manageable chunks, each of
which must be completed before moving on to the next
phase.
PROGRAM DEVELOPMENT CYCLE
1. Understand the problem
2. Plan the logic
3. Code the program
4. Use software (compiler or interpreter) to translate the
program into machine language
5. Test the program
6. Put the program into production
7. Maintain the program
Understanding the Problem
Professional computer programmers write programs
to satisfy the needs of others, called users or end
users.
When you plan a program, you think of the output
first. After you understand what the desired result is,
you can plan what to input and process to achieve it.
Does the director want a list of full-time employees
“Our department
only, or a list of full- and part-time employees
needs a list of all
together?
employees who
Does the director want people who have worked for
have been here
the company on a month-to-month contractual basis
over five years, over the past five years, or only regular, permanent
because we want employees?
to invite them to Do the listed employees need to have worked for the
a special thank- organization for five years as of today, as of the date of
the dinner, or as of some other cutoff date?
you dinner.”
What about an employee who, for example, worked
three years, took a two-year leave of absence, and has
been back for three years?
“Our department The user (HR director) must address these
needs a list of all questions:
employees who What data should be included for each listed
have been here employee? Should the list contain both first and
over five years, last names? Social Security numbers? Phone
numbers? Addresses?
because we want
Should the list be in alphabetical order?
to invite them to a
special thank-you Employee ID number order? Length-of-service
order? Some other order?
dinner.”
Should the employees be grouped by any
criteria, such as department number or years of
service?
Documentation
Documentation consists of all the supporting
paperwork for a program; it might include items such
as original requests for the program from users,
sample output, and descriptions of the data items
available for input.
Planning the Logic
During this phase of the process, the programmer plans the
steps of the program, deciding what steps to include and how
to order them.
The two most common planning tools are flowcharts and
pseudocode.
The process of walking through a program’s logic on paper before
you actually write the program is called desk-checking.
ALGORITHM
• An algorithm is a sequence of steps to solve a particular
problem or an ordered set of unambiguous steps that produces
a result and terminates in a finite time.
• The word “algorithm” relates to the name of the mathematician
Al-Khwarizmi, which means a procedure or a technique.
CHARACTERISTICS OF AN
ALGORITHM
• Algorithm has the following characteristics:
o Input: An algorithm may or may not require input.
o Output: Each algorithm is expected to produce at least one
result.
o Definiteness: Each instruction must be clear and unambiguous.
o Finiteness: If the instructions of an algorithm are executed, the
algorithm should terminate after finite number of steps.
Coding the Program
Programmers choose particular languages because some have
built-in capabilities that make them more efficient than others at
handling certain types of operations.
Only after choosing a language must the programmer be concerned
with proper punctuation and the correct spelling of commands—in
other words, using the correct syntax.
Using Software to Translate the Program
into Machine Language
Each computer knows only one language: its machine
language, which consists of 1s and 0s.
Syntax error is a misuse of a language’s grammar rules.
Data that the
program uses
If there are
no syntax
Write and correct Compile the Executable
errors
the program code program program
If there are
syntax errors
List of
syntax Program
error output
message
Figure 1-2 Creating an executable program
Testing the Program
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.
If you execute the program, provide the
value 2 as input to the program, and the
input myNumber answer 4 is displayed, you have
set myAnswer = myNumber * 2 executed one successful test run of the
output myAnswer program.
However, if the answer 40 is displayed, maybe the program contains a logical error.
input myNumber The programmer typed “20”
set myAnswer = myNumber * 20 instead of “2”.
output myAnswer
The process of finding and correcting program errors is called debugging.
Putting the Program into Production
Once the program is tested adequately, it is ready for the organization
to use.
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.
Conversion is the entire set of actions an organization must take to
switch over to using a new program or set of programs, can sometimes
take months or years to accomplish.
Maintaining the Program
After programs are put into production, making necessary changes
is called maintenance.
When you make changes to existing programs, you repeat the
development cycle.
Using Pseudocode Statements and
Flowchart Symbols
Pseudocode Flowchart
An English-like representation of the A pictorial representation of the
logical steps it takes to solve a same thing.
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.”
Writing Pseudocode
Using pseudocode involves writing
start
down all the steps you will use in a input myNumber
set myAnswer = myNumber
program. *2 output myAnswer
stop
Pseudocode is fairly flexible because it
is a planning tool, and not the final
product.
Writing Pseudocode
start, stop begin, end
get myNumber
input myNumber
read myNumber
calculate myAnswer = myNumber times 2
set myAnswer = myNumber * 2
compute myAnswer as myNumber doubled
display myAnswer
output myAnswer print myAnswer
write myAnswer
Drawing Flowcharts
Flowcharts allow programmers to
visualize more easily how the program
statements will connect.
Flowcharts are an excellent tool to help
them visualize how the statements in a
program are interrelated. Print Sum
Using the number-doubling program
Click icon to add picture Click icon to add picture Click icon to add picture
set myAnswer = output myAnswer
input myNumber
myNumber * 2
Input symbol Processing symbol Output symbol
• Indicates an input • Rectangle is used as the • Output statement, use
operation. processing symbol. the same symbol as for
input statements.
• You write an input • It contains a processing
statement in English statement.
inside the parallelogram. • Arithmetic operation
statements are
examples of processing
Use arrows, or flowlines, to connect
the steps and show the correct
sequence of these statements.
Most of a flowchart should read from
top to bottom or from left to right on
a page.
Terminal symbols, or start/stop
start symbols are used in the beginning and
end of the flowchart.
stop
start
Flowchart Pseudocode
input myNumber
start
input myNumber
set myAnswer = set myAnswer =
myNumber * 2 myNumber * 2 output
myAnswer
stop
output myAnswer
stop
start
input myNumber
set myAnswer = myNumber * 2
output myAnswer
input myNumber
set myAnswer = myNumber * 2
output myAnswer
input myNumber
set myAnswer = myNumber * 2
output myAnswer You would never want to
…and so on for 9,997 more times write such a repetitious list of
instructions.
Figure 1-7 Inefficient pseudocode for program that doubles 10,000
numbers
Figure 1-8 Flowchart of infinite number-doubling program
You represent a decision in a flowchart
by drawing a decision symbol, which
is shaped like a diamond.
myNumber = 0?
The diamond usually contains a
question, the answer to which is one of
two mutually exclusive options—often
yes or no.
start
This logic is not structured.
input myNumber
Yes
myNumber = 0? stop
No
set myAnswer =
myNumber * 2
output myAnswer
Figure 1-9 Flowchart of number-doubling program with sentinel value of 0
Print Loss Print Profit