Вы находитесь на странице: 1из 24

# SimpleSequence

ControlStructure
ToolsforStructuredand
ObjectOrientedDesign

Objectives
Defineanalgorithm
Namethecharacteristicsofanalgorithm
Identify,anduseinprogramflowchartandsystem
flowchart
Identify,anduseinprogramdesign,theterminal
interrupt,generalI/O,andprocessprogram
flowchartingsymbol
Identify,anduseinprogramdesign,variables,
constants,andassignmentstatements.

Objective(continued)
Distinguishbetweeninputandoutput,and
explainwhyinputandoutputstepsare
neededinprogramdesign
Performaprocedureexecutionofasimple
algorithm

Algorithm?
What is an algorithm? (alg&-rith-&m) (n.)
A formula or set of steps for solving a particular
problem.
To be an algorithm, a set of rules must be
unambiguous and have a clear stopping point.
Algorithms can be expressed in any language,
from natural languages like English or French to
programming languages like FORTRAN.

## What are the characteristics of an algorithm?

UnderstandingUnstructuredSpaghetti
Code

Thepopularname
forsnarledprogram
statementsis
spaghetticode
Thereasonforthe
nameshouldbe
obviousthecode
isasconfusingto
onenoodlethrough
aplateofspaghetti

UnderstandingtheSimpleSequence
Structures

Astructureisabasicunit
ofprogramminglogic;
eachstructureisa
sequence,selection,or
loop
Thefirstofthese
structuresisasequence,
asshowninFigure23
Withasequencestructure,
youperformanactionor
event,andthenyou
performthenextaction,in
order

WakeupAlgorithm

UnderstandingtheDataHierarchy
Whendataisstoredforuseoncomputersystems,
smallestusableunitofdataisthecharacter
Charactersareletters,numbers,andspecial
symbols,suchasA,7,and\$
Afieldisasingledataitem,suchaslastName,

UnderstandingtheDataHierarchy
(continued)
Recordsaregroupsoffieldsthatgotogetherfor
somelogicalreason
Filesaregroupsofrecordsthatgotogetherfor
somelogicalreason
tables,thattogetherservetheinformationneedsof
anorganization
Databasesoftwareestablishesandmaintains
relationshipsbetweenfieldsinthesetables,sothat
userscanwritequestionscalledqueries

DataHierarchy

Systemvs.Program
Flowchart
SystemFlowchart
Illustratingthebasicinputs,processes,and
outputsofthecomputersystem.

ProgramFlowchart
Stepbysteplogicoftheprogram

SystemFlowchart

ProgramFlowchart

Systemvs.Program

FlowchartForm

UsingandNamingVariables
Variablesarememorylocations,whosecontents
canvaryordifferovertime
Sometimes,inputNumbercanholda2and
times,inputNumbercanholda6and
Avariablenameisalsocalledanidentifier

UsingandNamingVariables
(continued)
Variablenamesusedherefollowonlytworules:
1. Mustbeoneword
2. Havesomeappropriatemeaning

AssigningValuestoVariables
Whenyoucreateaflowchartorpseudocodefora
programthatdoublesnumbers,youcaninclude
as inputNumber times 2
Thisstatementincorporatestwoactions:
First,thecomputercomputesthearithmeticvalue
ofinputNumber times 2
Second,thecomputedvalueisstoredinthe

AssigningValuestoVariables
(continued)
Mostprogramminglanguagesallowashorthand
expressionforassignmentstatementssuchas
inputNumber times 2
Theshorthandtakestheform
2
Theequalsignistheassignmentoperator,which
alwaysrequiresthenameofamemorylocationon
itsleftsidethelocationwheretheresultwillbe
stored

UnderstandingDataTypes
Computersdealwithtwobasictypesofdata
characterandnumeric
Whenyouuseaspecificnumericvalue,suchas
43,withinaprogram,youwriteitusingthedigits
andnoquotationmarks
Aspecificnumericvalueisoftencalledanumeric
constantbecauseitdoesnotchangea43always
hasthevalue43
Whenyouuseaspecificcharactervalue,orstring
ofcharacters,suchasChrisyouenclosethe
string,orcharacterconstant,withinquotation
marks

UnderstandingDataTypes(continued)
Mostcomputerlanguagesallowatleasttwo
distincttypesofvariables:
Oneholdsanumber,oftencalledanumeric
variable
Othersholdlettersofthealphabetandvarious
arecalledcharacter,text,orstringvariables,
dependingonthelanguagebeingused

UnderstandingDataTypes(continued)
Somelanguagesallowforseveraltypesof
numericdata
LanguagessuchasPascal,C++,C#,andJava
distinguishbetweeninteger(wholenumber)
numericvariablesandfloatingpoint(fractional)