PreludeProgramming6ed pp03 PDF
PreludeProgramming6ed pp03 PDF
Developing a Program
THE SUCCESS TRICK
WriMng
a
program
1)
Analyze
the
problem
2)
Design
the
program
3)
Code
the
program
4)
Test
the
program
Well
dened
Well
ordered
Must
produce
some
result
Must
terminate
in
a
nite
Mme
Syntax
Correct
syntax
for
telling
your
friend
where
you
put
a
cheese
sandwich
is:
I
have
put
it
on
the
table.
Input variables:
ComputaMons:
Output
Display:
ItemName
TotalPrice
DiscountRate
ItemName
Tax
SalePrice
Calling Modules
A
call
statement
causes
a
submodule
to
be
executed.
Afer
a
call
statement,
program
control
is
transferred
to
the
rst
line
of
the
called
module.
Afer
all
statements
in
the
submodule
have
been
executed,
control
returns
to
the
line
of
code
immediately
below
the
call
statement.
Format Output
o
Include
informaMon
about
what
the
output
means
If
a
program
calculates
the
temperature
converted
from
Fahrenheit
to
Celsius,
the
following
output
is
confusing:
But
the
following
output
makes
more
sense:
Hierarchy Charts
o
Like
an
organizaMon
chart
Documen6ng
Code
needs
to
contain
documentaMon
that
describes
to
the
reader
what
the
code
is
doing
Two
types
of
comments
are
used
within
the
code
Internal
documenta6on
is
for
the
programmers
to
read
External
documenta6on
is
for
the
user
*/
Users
Guides:
o
usually
wriXen
during
alpha
or
beta
test
phases
by
a
technical
writer
o Design
documentaMon
WriXen
by
programmer
to
explain
raMonale
behind
methods
and
code
used
Flowcharts
A
tool
for
programmers
to
design
programs
Describes
the
ow
of
a
program
modules
execuMon
with
diagrams
Completely
dierent
from
hierarchy
charts
Connected
symbols
are
used
to
describe
sequence,
repeMMon,
and
selecMon
structures
Some
prefer
to
use
owcharMng
to
learn
how
to
express
algorithms,
and
others
prefer
to
use
pseudocode
Many
programs
are
designed
with
a
combinaMon
of
pseudocode
and
owcharts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
30
31
Main module
Declare ItemName As String
Declare iscountRate, SalePrice, TotalPrice As Float
Write Sale Price Program
Write This program computes the total price, including tax, of an item that has
been discounted a certain percentage.
Call Input Data module
Call Perform Calculations module
Call Output Results module
End Program
Input Data module
Write What is the items name?
Input ItemName
Write What is its price and the percentage discounted?
Input OriginalPrice
Input DiscountRate
End Input Data Module
Perform Calculations module
Declare AmountSaved As Float
Set AmountSaved = OriginalPrice * (DiscountRate/100)
Set SalePrice = OriginalPrice AmountSaved
Set Tax = SalePrice * .065
Set TotalPrice = SalePrice + Tax
End Perform Calculations Module
Output Results module
Write The item is: + ItemName
Write Pre-sale price was: + OriginalPrice
Write Percentage discounted was: + DiscountRate + %
Write Sale price: + SalePrice + Sales tax: + Tax
Write Total: $ + TotalPrice
End Output Results Module
Control Structures
In
the
1960s
computer
scienMsts
proved
there
are
only
3
basic
control
structures
(also
called
constructs)
needed
to
create
any
program
or
algorithm!
Style Pointers
q
Write
modular
programs
q
Use
descripMve
variable
names
q
Provide
a
welcome
message
for
the
user
q
Use
a
prompt
before
an
input
q
IdenMfy
program
output
q
Document
your
programs