SlideShare a Scribd company logo
Programming Logic and Design
Eighth Edition
Chapter 2
Elements of High-Quality Programs
Objectives
In this chapter, you will learn about:
• Declaring and using variables and constants
• Performing arithmetic operations
• The advantages of modularization
• Modularizing a program
• Hierarchy charts
• Features of good program design
2Programming Logic and Design, Eighth Edition
Declaring and Using Variables
and Constants
• Understanding Unnamed, Literal Constants and
their Data Types
– Data types
• Numeric consists of numbers
• String is anything not used in math
– Different forms
• Integers and floating-point (also called real) numbers
• Numeric Constant (Literal numeric constant)
• String constants (alphanumeric vakues)
• Unnamed constants
3Programming Logic and Design, Eighth Edition
Working with Variables
• Named memory locations
• Contents can vary or differ over time
• Declaration
– Statement that provides a data type and an identifier for a
variable
• Identifier
– Variable’s name
4Programming Logic and Design, Eighth Edition
Working with Variables (continued)
Figure 2-1 Flowchart and pseudocode for the number-doubling program
5Programming Logic and Design, Eighth Edition
Working with Variables (continued)
• A declaration is a statement that provides a data
type and an identifier for a variable
• An identifier is a program component’s name
• Data type
– Classification that describes:
• What values can be held by the item
• How the item is stored in computer memory
• What operations can be performed on the data item
• Initializing the variable - Declare a starting value
• Garbage – a variable’s unknown value
6Programming Logic and Design, Eighth Edition
7Programming Logic and Design, Eighth Edition
Figure 2-2 Flowchart and pseudocode of number-doubling
program with variable declarations
Working with Variables (continued)
Naming Variables
• Programmer chooses reasonable and descriptive
names for variables
• Programming languages have rules for creating
identifiers
– Most languages allow letters and digits
– Some languages allow hyphens
– Reserved keywords are not allowed
• Variable names are case sensitive
8Programming Logic and Design, Eighth Edition
Naming Variables (continued)
• Camel casing
– Variable names such as hourlyWage have a “hump” in
the middle
• Be descriptive
– Must be one word
– Must start with a letter
– Should have some appropriate meaning
9Programming Logic and Design, Eighth Edition
Naming Variables (continued)
10Programming Logic and Design, Eighth Edition
Assigning Values to Variables
• Assignment statement
– set myAnswer = myNumber * 2
• Assignment operator
– Equal sign
– A binary operator, meaning it requires two operands—one
on each side
– Always operates from right to left, which means that it has
right-associativity or right-to-left associativity
– The result to the left of an assignment operator is called an
lvalue
11Programming Logic and Design, Eighth Edition
Understanding the Data Types of
Variables
• Numeric variable
– Holds digits
– Can perform mathematical operations on it
• String variable
– Can hold text
– Letters of the alphabet
– Special characters such as punctuation marks
• Type-safety
– Prevents assigning values of an incorrect data type
12Programming Logic and Design, Eighth Edition
Declaring Named Constants
• Named constant
– Similar to a variable
– Can be assigned a value only once
– Assign a useful name to a value that will never be changed
during a program’s execution
• Magic number
– Unnamed constant
– Use taxAmount = price * SALES_TAX_AMOUNT
instead of taxAmount = price * .06
13Programming Logic and Design, Eighth Edition
Performing Arithmetic Operations
• Standard arithmetic operators:
+ (plus sign)—addition
− (minus sign)—subtraction
* (asterisk)—multiplication
/ (slash)—division
14Programming Logic and Design, Eighth Edition
Performing Arithmetic Operations
(continued)
• Rules of precedence
– Also called the order of operations
– Dictate the order in which operations in the same
statement are carried out
– Expressions within parentheses are evaluated first
– All the arithmetic operators have left-to-right associativity
– Multiplication and division are evaluated next
• From left to right
– Addition and subtraction are evaluated next
• From left to right
15Programming Logic and Design, Eighth Edition
Performing Arithmetic Operations
(continued)
16Programming Logic and Design, Eighth Edition
The Integer Data Type
• Dividing an integer by another integer is a special
case
– Dividing two integers results in an integer, and any
fractional part of the result is lost
– The decimal portion of the result is cut off, or truncated
• A remainder operator (called the modulo operator
or the modulus operator) contains the remainder of
a division operation
– 24 Mod 10 is 4
– Because when 24 is divided by 10, 4 is the remainder
17Programming Logic and Design, Eighth Edition
Understanding the Advantages
of Modularization
• Modules
– Subunit of programming problem
– Also called subroutines, procedures, functions, or
methods
– To call a module is to use its name to invoke the module,
causing it to execute
• Modularization
– Breaking down a large program into modules
– Called functional decomposition
18Programming Logic and Design, Eighth Edition
Modularization Provides
Abstraction
• Abstraction
– Paying attention to important properties while ignoring
nonessential details
– Selective ignorance
• Newer high-level programming languages
– Use English-like vocabulary
– One broad statement corresponds to dozens of machine
instructions
• Modules provide another way to achieve abstraction
19Programming Logic and Design, Eighth Edition
Modularization Allows Multiple
Programmers to Work on a Problem
• Easier to divide the task among various people
• Rarely does a single programmer write a commercial
program
– Professional software developers can write new programs
quickly by dividing large programs into modules
– Assign each module to an individual programmer or team
20Programming Logic and Design, Eighth Edition
Modularization Allows You to
Reuse Work
• Reusability
– Feature of modular programs
– Allows individual modules to be used in a variety of
applications
– Many real-world examples of reusability
• Reliability
– Assures that a module has been tested and proven to
function correctly
21Programming Logic and Design, Eighth Edition
Modularizing a Program
• Main program
– Basic steps (mainline logic) of the program
• Include in a module
– Module header
– Module body
– Module return statement
• Naming a module
– Similar to naming a variable
– Module names are followed by a set of parentheses
22Programming Logic and Design, Eighth Edition
Modularizing a Program (continued)
• When a main program wants to use a module
– “Calls” the module’s name
• Flowchart
– Symbol used to call a module is a rectangle with a bar
across the top
– Place the name of the module you are calling inside the
rectangle
– Draw each module separately with its own sentinel
symbols
23Programming Logic and Design, Eighth Edition
24Programming Logic and Design, Eighth Edition
Figure 2-3 Program that produces a bill using only main program
Modularizing a Program (continued)
• Statements taken out of a main program and put into
a module have been encapsulated
• Main program becomes shorter and easier to
understand
• Modules are reusable
• When statements contribute to the same job, we get
greater functional cohesion
25Programming Logic and Design, Eighth Edition
26Programming Logic and Design, Eighth Edition
Figure 2-5 The billing program with constants declared within the module
Declaring Variables and Constants
within Modules
• Place any statements within modules
– Input, processing, and output statements
– Variable and constant declarations
• Variables and constants declared in a module are
usable only within the module
– Visible
– In scope, also called local
• Portable
– Self-contained units that are easily transported
27Programming Logic and Design, Eighth Edition
Declaring Variables and Constants
within Modules (continued)
• Global variables and constants
– Declared at the program level
– Visible to and usable in all the modules called by the
program
– Many programmers avoid global variables to minimize
errors
28Programming Logic and Design, Eighth Edition
Understanding the Most Common
Configuration for Mainline Logic
• Mainline logic of almost every procedural computer
program follows a general structure
– Declarations for global variables and constants
– Housekeeping tasks - steps you must perform at the
beginning of a program to get ready for the rest of the
program
– Detail loop tasks - do the core work of the program
– End-of-job tasks - steps you take at the end of the program
to finish the application
29Programming Logic and Design, Eighth Edition
Understanding the Most Common
Configuration for Mainline Logic (continued)
Figure 2-6 Flowchart and pseudocode of
mainline logic for a typical procedural program
30Programming Logic and Design, Eighth Edition
Creating Hierarchy Charts
• Hierarchy chart
– Shows the overall picture of how modules are related to
one another
– Tells you which modules exist within a program and which
modules call others
– Specific module may be called from several locations
within a program
• Planning tool
– Develop the overall relationship of program modules
before you write them
• Documentation tool
31Programming Logic and Design, Eighth Edition
Creating Hierarchy Charts (continued)
32Programming Logic and Design, Eighth Edition
Figure 2-10
Hierarchy chart
of payroll report
program in
Figure 2-8
Figure 2-11
Billing program
hierarchy chart
Features of Good Program Design
• Use program comments where appropriate
• Identifiers should be chosen carefully
• Strive to design clear statements within your
programs and modules
• Write clear prompts and echo input
• Continue to maintain good programming habits as
you develop your programming skills
33Programming Logic and Design, Eighth Edition
Using Program Comments
• Program comments
– Written explanations of programming statements
– Not part of the program logic
– Serve as documentation for readers of the program
• Syntax used differs among programming languages
• Flowchart
– Use an annotation symbol to hold information that
expands on what is stored within another flowchart
symbol
34Programming Logic and Design, Eighth Edition
Using Program Comments (continued)
35Programming Logic and Design, Eighth Edition
Figure 2-12 Pseudocode that declares some variables and includes comments
36Programming Logic and Design, Eighth Edition
Figure 2-13 Flowchart that includes annotation symbols
Choosing Identifiers
• General guidelines
– Give a variable or a constant a name that is a noun
(because it represents a thing)
– Give a module an identifier that is a verb (because it
performs an action)
– Use meaningful names
• Self-documenting
– Use pronounceable names
– Be judicious in your use of abbreviations
– Avoid digits in a name
37Programming Logic and Design, Eighth Edition
Choosing Identifiers (continued)
• General guidelines (continued)
– Use the system your language allows to separate words in
long, multiword variable names
– Consider including a form of the verb to be
– Name constants using all uppercase letters separated by
underscores (_)
• Programmers create a list of all variables
– Data dictionary
38Programming Logic and Design, Eighth Edition
Designing Clear Statements
• Avoid confusing line breaks
• Use temporary variables to clarify long statements
39Programming Logic and Design, Eighth Edition
Avoiding Confusing Line Breaks
• Most modern programming languages are
free-form
• Make sure your meaning is clear
• Do not combine multiple statements on one line
40Programming Logic and Design, Eighth Edition
Using Temporary Variables to
Clarify Long Statements
• Temporary variable
– Work variable
– Not used for input or output
– Working variable that you use during a program’s
execution
• Consider using a series of temporary variables to
hold intermediate results
41Programming Logic and Design, Eighth Edition
Using Temporary Variables to Clarify
Long Statements (continued)
Figure 2-14 Two ways of achieving the same salespersonCommission result
42Programming Logic and Design, Eighth Edition
Writing Clear Prompts and Echoing
Input
• Prompt
– Message displayed on a monitor to ask the user for a
response
– Used both in command-line and GUI interactive programs
• Echoing input
– Repeating input back to a user either in a subsequent
prompt or in output
43Programming Logic and Design, Eighth Edition
Writing Clear Prompts and Echoing
Input (continued)
Figure 2-15 Beginning of a program
that accepts a name and balance as input
44Programming Logic and Design, Eighth Edition
45Programming Logic and Design, Eighth Edition
Figure 2-16 Beginning of a program that accepts a
name and balance as input and uses a separate prompt for each item
Maintaining Good Programming
Habits
• Every program you write will be better if you:
– Plan before you code
– Maintain the habit of first drawing flowcharts or writing
pseudocode
– Desk-check your program logic on paper
– Think carefully about the variable and module names you
use
– Design your program statements to be easy to read and
use
46Programming Logic and Design, Eighth Edition
Summary
• Programs contain literals, variables, and named
constants
• Arithmetic follows rules of precedence
• Break down programming problems into modules
– Include a header, a body, and a return statement
• Hierarchy charts show relationship among modules
• As programs become more complicated:
– Need for good planning and design increases
47Programming Logic and Design, Eighth Edition

More Related Content

What's hot

Agile Methodology - Software Engineering
Agile Methodology - Software EngineeringAgile Methodology - Software Engineering
Agile Methodology - Software Engineering
Purvik Rana
 
Software process
Software processSoftware process
Software process
Dr. Loganathan R
 
Chapter 13 software testing strategies
Chapter 13 software testing strategiesChapter 13 software testing strategies
Chapter 13 software testing strategies
SHREEHARI WADAWADAGI
 
Component level design
Component   level designComponent   level design
Component level design
Midhula Chandren
 
SDLC - Software Development Life Cycle
SDLC - Software Development Life CycleSDLC - Software Development Life Cycle
SDLC - Software Development Life Cycle
Suresh Koujalagi
 
Basic programming concepts
Basic programming conceptsBasic programming concepts
Basic programming concepts
salmankhan570
 
Software Development Life Cycle (SDLC )
Software Development Life Cycle (SDLC )Software Development Life Cycle (SDLC )
Software Development Life Cycle (SDLC )
eshtiyak
 
ccs356-software-engineering-notes.pdf
ccs356-software-engineering-notes.pdfccs356-software-engineering-notes.pdf
ccs356-software-engineering-notes.pdf
VijayakumarKadumbadi
 
UML
UMLUML
Sdlc models
Sdlc modelsSdlc models
Unit1
Unit1Unit1
Requirement Engineering
Requirement EngineeringRequirement Engineering
Requirement Engineering
Slideshare
 
Software development life cycle
Software development life cycleSoftware development life cycle
Software development life cycle
Gurban Daniel
 
Ian Sommerville, Software Engineering, 9th Edition Ch1
Ian Sommerville,  Software Engineering, 9th Edition Ch1Ian Sommerville,  Software Engineering, 9th Edition Ch1
Ian Sommerville, Software Engineering, 9th Edition Ch1
Mohammed Romi
 
Software process
Software processSoftware process
Software process
Jennifer Polack
 
Chapter 01 software engineering pressman
Chapter 01  software engineering pressmanChapter 01  software engineering pressman
Chapter 01 software engineering pressman
RohitGoyal183
 
Design Patterns - General Introduction
Design Patterns - General IntroductionDesign Patterns - General Introduction
Design Patterns - General Introduction
Asma CHERIF
 
Ian Sommerville, Software Engineering, 9th Edition Ch 4
Ian Sommerville,  Software Engineering, 9th Edition Ch 4Ian Sommerville,  Software Engineering, 9th Edition Ch 4
Ian Sommerville, Software Engineering, 9th Edition Ch 4
Mohammed Romi
 
Software Development Life Cycle (SDLC)
Software Development Life Cycle (SDLC)Software Development Life Cycle (SDLC)
Software Development Life Cycle (SDLC)
Angelin R
 
Object oriented programming interview questions
Object oriented programming interview questionsObject oriented programming interview questions
Object oriented programming interview questions
Keet Sugathadasa
 

What's hot (20)

Agile Methodology - Software Engineering
Agile Methodology - Software EngineeringAgile Methodology - Software Engineering
Agile Methodology - Software Engineering
 
Software process
Software processSoftware process
Software process
 
Chapter 13 software testing strategies
Chapter 13 software testing strategiesChapter 13 software testing strategies
Chapter 13 software testing strategies
 
Component level design
Component   level designComponent   level design
Component level design
 
SDLC - Software Development Life Cycle
SDLC - Software Development Life CycleSDLC - Software Development Life Cycle
SDLC - Software Development Life Cycle
 
Basic programming concepts
Basic programming conceptsBasic programming concepts
Basic programming concepts
 
Software Development Life Cycle (SDLC )
Software Development Life Cycle (SDLC )Software Development Life Cycle (SDLC )
Software Development Life Cycle (SDLC )
 
ccs356-software-engineering-notes.pdf
ccs356-software-engineering-notes.pdfccs356-software-engineering-notes.pdf
ccs356-software-engineering-notes.pdf
 
UML
UMLUML
UML
 
Sdlc models
Sdlc modelsSdlc models
Sdlc models
 
Unit1
Unit1Unit1
Unit1
 
Requirement Engineering
Requirement EngineeringRequirement Engineering
Requirement Engineering
 
Software development life cycle
Software development life cycleSoftware development life cycle
Software development life cycle
 
Ian Sommerville, Software Engineering, 9th Edition Ch1
Ian Sommerville,  Software Engineering, 9th Edition Ch1Ian Sommerville,  Software Engineering, 9th Edition Ch1
Ian Sommerville, Software Engineering, 9th Edition Ch1
 
Software process
Software processSoftware process
Software process
 
Chapter 01 software engineering pressman
Chapter 01  software engineering pressmanChapter 01  software engineering pressman
Chapter 01 software engineering pressman
 
Design Patterns - General Introduction
Design Patterns - General IntroductionDesign Patterns - General Introduction
Design Patterns - General Introduction
 
Ian Sommerville, Software Engineering, 9th Edition Ch 4
Ian Sommerville,  Software Engineering, 9th Edition Ch 4Ian Sommerville,  Software Engineering, 9th Edition Ch 4
Ian Sommerville, Software Engineering, 9th Edition Ch 4
 
Software Development Life Cycle (SDLC)
Software Development Life Cycle (SDLC)Software Development Life Cycle (SDLC)
Software Development Life Cycle (SDLC)
 
Object oriented programming interview questions
Object oriented programming interview questionsObject oriented programming interview questions
Object oriented programming interview questions
 

Similar to CIS110 Computer Programming Design Chapter (2)

Logic Formulation 2
Logic Formulation 2Logic Formulation 2
Logic Formulation 2
deathful
 
test.pptx
test.pptxtest.pptx
test.pptx
Stacia7
 
chapter1-161229182113 (1).pdf
chapter1-161229182113 (1).pdfchapter1-161229182113 (1).pdf
chapter1-161229182113 (1).pdf
BernardVelasco1
 
Cs111 ch01 v4
Cs111 ch01 v4Cs111 ch01 v4
Cs111 ch01 v4
ArnoldNarte
 
SMD.pptx
SMD.pptxSMD.pptx
SMD.pptx
kirtisatpute4
 
CS6502 OOAD - Question Bank and Answer
CS6502 OOAD - Question Bank and AnswerCS6502 OOAD - Question Bank and Answer
CS6502 OOAD - Question Bank and Answer
Gobinath Subramaniam
 
C programming for Computing Techniques
C programming for Computing TechniquesC programming for Computing Techniques
C programming for Computing Techniques
Appili Vamsi Krishna
 
Intro to Programming: Modularity
Intro to Programming: ModularityIntro to Programming: Modularity
Intro to Programming: Modularity
Nicole Ryan
 
CIS110 Computer Programming Design Chapter (9)
CIS110 Computer Programming Design Chapter  (9)CIS110 Computer Programming Design Chapter  (9)
CIS110 Computer Programming Design Chapter (9)
Dr. Ahmed Al Zaidy
 
9781285852744 ppt ch12
9781285852744 ppt ch129781285852744 ppt ch12
9781285852744 ppt ch12
Terry Yoast
 
Design and Analysis of Algorithm ppt for unit one
Design and Analysis of Algorithm ppt for unit oneDesign and Analysis of Algorithm ppt for unit one
Design and Analysis of Algorithm ppt for unit one
ssuserb7c8b8
 
pccf unit 1 _VP.pptx
pccf unit 1 _VP.pptxpccf unit 1 _VP.pptx
pccf unit 1 _VP.pptx
vishnupriyapm4
 
CH-1.1 Introduction (1).pptx
CH-1.1 Introduction (1).pptxCH-1.1 Introduction (1).pptx
CH-1.1 Introduction (1).pptx
satvikkushwaha1
 
Fundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptxFundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptx
Vigneshkumar Ponnusamy
 
Chap1
Chap1Chap1
lect 1-ds algo(final)_2.pdf
lect 1-ds  algo(final)_2.pdflect 1-ds  algo(final)_2.pdf
lect 1-ds algo(final)_2.pdf
MuhammadUmerIhtisham
 
Unit 1 python (2021 r)
Unit 1 python (2021 r)Unit 1 python (2021 r)
Unit 1 python (2021 r)
praveena p
 
UML (Hemant rajak)
UML (Hemant rajak)UML (Hemant rajak)
UML (Hemant rajak)
hrajak5
 
Modular programming
Modular programmingModular programming
object oriented programming part inheritance.pptx
object oriented programming part inheritance.pptxobject oriented programming part inheritance.pptx
object oriented programming part inheritance.pptx
urvashipundir04
 

Similar to CIS110 Computer Programming Design Chapter (2) (20)

Logic Formulation 2
Logic Formulation 2Logic Formulation 2
Logic Formulation 2
 
test.pptx
test.pptxtest.pptx
test.pptx
 
chapter1-161229182113 (1).pdf
chapter1-161229182113 (1).pdfchapter1-161229182113 (1).pdf
chapter1-161229182113 (1).pdf
 
Cs111 ch01 v4
Cs111 ch01 v4Cs111 ch01 v4
Cs111 ch01 v4
 
SMD.pptx
SMD.pptxSMD.pptx
SMD.pptx
 
CS6502 OOAD - Question Bank and Answer
CS6502 OOAD - Question Bank and AnswerCS6502 OOAD - Question Bank and Answer
CS6502 OOAD - Question Bank and Answer
 
C programming for Computing Techniques
C programming for Computing TechniquesC programming for Computing Techniques
C programming for Computing Techniques
 
Intro to Programming: Modularity
Intro to Programming: ModularityIntro to Programming: Modularity
Intro to Programming: Modularity
 
CIS110 Computer Programming Design Chapter (9)
CIS110 Computer Programming Design Chapter  (9)CIS110 Computer Programming Design Chapter  (9)
CIS110 Computer Programming Design Chapter (9)
 
9781285852744 ppt ch12
9781285852744 ppt ch129781285852744 ppt ch12
9781285852744 ppt ch12
 
Design and Analysis of Algorithm ppt for unit one
Design and Analysis of Algorithm ppt for unit oneDesign and Analysis of Algorithm ppt for unit one
Design and Analysis of Algorithm ppt for unit one
 
pccf unit 1 _VP.pptx
pccf unit 1 _VP.pptxpccf unit 1 _VP.pptx
pccf unit 1 _VP.pptx
 
CH-1.1 Introduction (1).pptx
CH-1.1 Introduction (1).pptxCH-1.1 Introduction (1).pptx
CH-1.1 Introduction (1).pptx
 
Fundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptxFundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptx
 
Chap1
Chap1Chap1
Chap1
 
lect 1-ds algo(final)_2.pdf
lect 1-ds  algo(final)_2.pdflect 1-ds  algo(final)_2.pdf
lect 1-ds algo(final)_2.pdf
 
Unit 1 python (2021 r)
Unit 1 python (2021 r)Unit 1 python (2021 r)
Unit 1 python (2021 r)
 
UML (Hemant rajak)
UML (Hemant rajak)UML (Hemant rajak)
UML (Hemant rajak)
 
Modular programming
Modular programmingModular programming
Modular programming
 
object oriented programming part inheritance.pptx
object oriented programming part inheritance.pptxobject oriented programming part inheritance.pptx
object oriented programming part inheritance.pptx
 

More from Dr. Ahmed Al Zaidy

Chapter 14 Exploring Object-based Programming
Chapter 14 Exploring Object-based ProgrammingChapter 14 Exploring Object-based Programming
Chapter 14 Exploring Object-based Programming
Dr. Ahmed Al Zaidy
 
Chapter 13 Programming for web forms
Chapter 13 Programming for web formsChapter 13 Programming for web forms
Chapter 13 Programming for web forms
Dr. Ahmed Al Zaidy
 
Chapter 12 Working with Document nodes and style sheets
Chapter 12 Working with Document nodes and style sheetsChapter 12 Working with Document nodes and style sheets
Chapter 12 Working with Document nodes and style sheets
Dr. Ahmed Al Zaidy
 
Chapter 11 Working with Events and Styles
Chapter 11 Working with Events and StylesChapter 11 Working with Events and Styles
Chapter 11 Working with Events and Styles
Dr. Ahmed Al Zaidy
 
Chapter 10 Exploring arrays, loops, and conditional statements
Chapter 10 Exploring arrays, loops, and conditional statementsChapter 10 Exploring arrays, loops, and conditional statements
Chapter 10 Exploring arrays, loops, and conditional statements
Dr. Ahmed Al Zaidy
 
Chapter 9 Getting Started with JavaScript
Chapter 9 Getting Started with JavaScriptChapter 9 Getting Started with JavaScript
Chapter 9 Getting Started with JavaScript
Dr. Ahmed Al Zaidy
 
Chapter 8 Enhancing a website with multimedia
Chapter 8 Enhancing a website with multimediaChapter 8 Enhancing a website with multimedia
Chapter 8 Enhancing a website with multimedia
Dr. Ahmed Al Zaidy
 
Chapter 7 Designing a web form
Chapter 7 Designing a web formChapter 7 Designing a web form
Chapter 7 Designing a web form
Dr. Ahmed Al Zaidy
 
Chapter 6 Working with Tables and Columns
Chapter 6 Working with Tables and ColumnsChapter 6 Working with Tables and Columns
Chapter 6 Working with Tables and Columns
Dr. Ahmed Al Zaidy
 
Chapter 5 Designing for the mobile web
Chapter 5 Designing for the mobile webChapter 5 Designing for the mobile web
Chapter 5 Designing for the mobile web
Dr. Ahmed Al Zaidy
 
Chapter 4 Graphic Design with CSS
Chapter 4 Graphic Design with CSSChapter 4 Graphic Design with CSS
Chapter 4 Graphic Design with CSS
Dr. Ahmed Al Zaidy
 
Chapter 3 Designing a Page Layout
Chapter 3 Designing a Page LayoutChapter 3 Designing a Page Layout
Chapter 3 Designing a Page Layout
Dr. Ahmed Al Zaidy
 
Chapter 2 Getting Started with CSS
Chapter 2 Getting Started with CSSChapter 2 Getting Started with CSS
Chapter 2 Getting Started with CSS
Dr. Ahmed Al Zaidy
 
Chapter 1 Getting Started with HTML5
Chapter 1 Getting Started with HTML5Chapter 1 Getting Started with HTML5
Chapter 1 Getting Started with HTML5
Dr. Ahmed Al Zaidy
 
Integer overflows
Integer overflowsInteger overflows
Integer overflows
Dr. Ahmed Al Zaidy
 
testing throughout-the-software-life-cycle-section-2
testing throughout-the-software-life-cycle-section-2testing throughout-the-software-life-cycle-section-2
testing throughout-the-software-life-cycle-section-2
Dr. Ahmed Al Zaidy
 
Fundamental of testing
Fundamental of testingFundamental of testing
Fundamental of testing
Dr. Ahmed Al Zaidy
 
Chapter 15 Risk Mitigation
Chapter 15 Risk MitigationChapter 15 Risk Mitigation
Chapter 15 Risk Mitigation
Dr. Ahmed Al Zaidy
 
Chapter 14 Business Continuity
Chapter 14 Business ContinuityChapter 14 Business Continuity
Chapter 14 Business Continuity
Dr. Ahmed Al Zaidy
 
Chapter 13 Vulnerability Assessment and Data Security
Chapter 13 Vulnerability Assessment and Data SecurityChapter 13 Vulnerability Assessment and Data Security
Chapter 13 Vulnerability Assessment and Data Security
Dr. Ahmed Al Zaidy
 

More from Dr. Ahmed Al Zaidy (20)

Chapter 14 Exploring Object-based Programming
Chapter 14 Exploring Object-based ProgrammingChapter 14 Exploring Object-based Programming
Chapter 14 Exploring Object-based Programming
 
Chapter 13 Programming for web forms
Chapter 13 Programming for web formsChapter 13 Programming for web forms
Chapter 13 Programming for web forms
 
Chapter 12 Working with Document nodes and style sheets
Chapter 12 Working with Document nodes and style sheetsChapter 12 Working with Document nodes and style sheets
Chapter 12 Working with Document nodes and style sheets
 
Chapter 11 Working with Events and Styles
Chapter 11 Working with Events and StylesChapter 11 Working with Events and Styles
Chapter 11 Working with Events and Styles
 
Chapter 10 Exploring arrays, loops, and conditional statements
Chapter 10 Exploring arrays, loops, and conditional statementsChapter 10 Exploring arrays, loops, and conditional statements
Chapter 10 Exploring arrays, loops, and conditional statements
 
Chapter 9 Getting Started with JavaScript
Chapter 9 Getting Started with JavaScriptChapter 9 Getting Started with JavaScript
Chapter 9 Getting Started with JavaScript
 
Chapter 8 Enhancing a website with multimedia
Chapter 8 Enhancing a website with multimediaChapter 8 Enhancing a website with multimedia
Chapter 8 Enhancing a website with multimedia
 
Chapter 7 Designing a web form
Chapter 7 Designing a web formChapter 7 Designing a web form
Chapter 7 Designing a web form
 
Chapter 6 Working with Tables and Columns
Chapter 6 Working with Tables and ColumnsChapter 6 Working with Tables and Columns
Chapter 6 Working with Tables and Columns
 
Chapter 5 Designing for the mobile web
Chapter 5 Designing for the mobile webChapter 5 Designing for the mobile web
Chapter 5 Designing for the mobile web
 
Chapter 4 Graphic Design with CSS
Chapter 4 Graphic Design with CSSChapter 4 Graphic Design with CSS
Chapter 4 Graphic Design with CSS
 
Chapter 3 Designing a Page Layout
Chapter 3 Designing a Page LayoutChapter 3 Designing a Page Layout
Chapter 3 Designing a Page Layout
 
Chapter 2 Getting Started with CSS
Chapter 2 Getting Started with CSSChapter 2 Getting Started with CSS
Chapter 2 Getting Started with CSS
 
Chapter 1 Getting Started with HTML5
Chapter 1 Getting Started with HTML5Chapter 1 Getting Started with HTML5
Chapter 1 Getting Started with HTML5
 
Integer overflows
Integer overflowsInteger overflows
Integer overflows
 
testing throughout-the-software-life-cycle-section-2
testing throughout-the-software-life-cycle-section-2testing throughout-the-software-life-cycle-section-2
testing throughout-the-software-life-cycle-section-2
 
Fundamental of testing
Fundamental of testingFundamental of testing
Fundamental of testing
 
Chapter 15 Risk Mitigation
Chapter 15 Risk MitigationChapter 15 Risk Mitigation
Chapter 15 Risk Mitigation
 
Chapter 14 Business Continuity
Chapter 14 Business ContinuityChapter 14 Business Continuity
Chapter 14 Business Continuity
 
Chapter 13 Vulnerability Assessment and Data Security
Chapter 13 Vulnerability Assessment and Data SecurityChapter 13 Vulnerability Assessment and Data Security
Chapter 13 Vulnerability Assessment and Data Security
 

Recently uploaded

How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 

Recently uploaded (20)

How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 

CIS110 Computer Programming Design Chapter (2)

  • 1. Programming Logic and Design Eighth Edition Chapter 2 Elements of High-Quality Programs
  • 2. Objectives In this chapter, you will learn about: • Declaring and using variables and constants • Performing arithmetic operations • The advantages of modularization • Modularizing a program • Hierarchy charts • Features of good program design 2Programming Logic and Design, Eighth Edition
  • 3. Declaring and Using Variables and Constants • Understanding Unnamed, Literal Constants and their Data Types – Data types • Numeric consists of numbers • String is anything not used in math – Different forms • Integers and floating-point (also called real) numbers • Numeric Constant (Literal numeric constant) • String constants (alphanumeric vakues) • Unnamed constants 3Programming Logic and Design, Eighth Edition
  • 4. Working with Variables • Named memory locations • Contents can vary or differ over time • Declaration – Statement that provides a data type and an identifier for a variable • Identifier – Variable’s name 4Programming Logic and Design, Eighth Edition
  • 5. Working with Variables (continued) Figure 2-1 Flowchart and pseudocode for the number-doubling program 5Programming Logic and Design, Eighth Edition
  • 6. Working with Variables (continued) • A declaration is a statement that provides a data type and an identifier for a variable • An identifier is a program component’s name • Data type – Classification that describes: • What values can be held by the item • How the item is stored in computer memory • What operations can be performed on the data item • Initializing the variable - Declare a starting value • Garbage – a variable’s unknown value 6Programming Logic and Design, Eighth Edition
  • 7. 7Programming Logic and Design, Eighth Edition Figure 2-2 Flowchart and pseudocode of number-doubling program with variable declarations Working with Variables (continued)
  • 8. Naming Variables • Programmer chooses reasonable and descriptive names for variables • Programming languages have rules for creating identifiers – Most languages allow letters and digits – Some languages allow hyphens – Reserved keywords are not allowed • Variable names are case sensitive 8Programming Logic and Design, Eighth Edition
  • 9. Naming Variables (continued) • Camel casing – Variable names such as hourlyWage have a “hump” in the middle • Be descriptive – Must be one word – Must start with a letter – Should have some appropriate meaning 9Programming Logic and Design, Eighth Edition
  • 10. Naming Variables (continued) 10Programming Logic and Design, Eighth Edition
  • 11. Assigning Values to Variables • Assignment statement – set myAnswer = myNumber * 2 • Assignment operator – Equal sign – A binary operator, meaning it requires two operands—one on each side – Always operates from right to left, which means that it has right-associativity or right-to-left associativity – The result to the left of an assignment operator is called an lvalue 11Programming Logic and Design, Eighth Edition
  • 12. Understanding the Data Types of Variables • Numeric variable – Holds digits – Can perform mathematical operations on it • String variable – Can hold text – Letters of the alphabet – Special characters such as punctuation marks • Type-safety – Prevents assigning values of an incorrect data type 12Programming Logic and Design, Eighth Edition
  • 13. Declaring Named Constants • Named constant – Similar to a variable – Can be assigned a value only once – Assign a useful name to a value that will never be changed during a program’s execution • Magic number – Unnamed constant – Use taxAmount = price * SALES_TAX_AMOUNT instead of taxAmount = price * .06 13Programming Logic and Design, Eighth Edition
  • 14. Performing Arithmetic Operations • Standard arithmetic operators: + (plus sign)—addition − (minus sign)—subtraction * (asterisk)—multiplication / (slash)—division 14Programming Logic and Design, Eighth Edition
  • 15. Performing Arithmetic Operations (continued) • Rules of precedence – Also called the order of operations – Dictate the order in which operations in the same statement are carried out – Expressions within parentheses are evaluated first – All the arithmetic operators have left-to-right associativity – Multiplication and division are evaluated next • From left to right – Addition and subtraction are evaluated next • From left to right 15Programming Logic and Design, Eighth Edition
  • 17. The Integer Data Type • Dividing an integer by another integer is a special case – Dividing two integers results in an integer, and any fractional part of the result is lost – The decimal portion of the result is cut off, or truncated • A remainder operator (called the modulo operator or the modulus operator) contains the remainder of a division operation – 24 Mod 10 is 4 – Because when 24 is divided by 10, 4 is the remainder 17Programming Logic and Design, Eighth Edition
  • 18. Understanding the Advantages of Modularization • Modules – Subunit of programming problem – Also called subroutines, procedures, functions, or methods – To call a module is to use its name to invoke the module, causing it to execute • Modularization – Breaking down a large program into modules – Called functional decomposition 18Programming Logic and Design, Eighth Edition
  • 19. Modularization Provides Abstraction • Abstraction – Paying attention to important properties while ignoring nonessential details – Selective ignorance • Newer high-level programming languages – Use English-like vocabulary – One broad statement corresponds to dozens of machine instructions • Modules provide another way to achieve abstraction 19Programming Logic and Design, Eighth Edition
  • 20. Modularization Allows Multiple Programmers to Work on a Problem • Easier to divide the task among various people • Rarely does a single programmer write a commercial program – Professional software developers can write new programs quickly by dividing large programs into modules – Assign each module to an individual programmer or team 20Programming Logic and Design, Eighth Edition
  • 21. Modularization Allows You to Reuse Work • Reusability – Feature of modular programs – Allows individual modules to be used in a variety of applications – Many real-world examples of reusability • Reliability – Assures that a module has been tested and proven to function correctly 21Programming Logic and Design, Eighth Edition
  • 22. Modularizing a Program • Main program – Basic steps (mainline logic) of the program • Include in a module – Module header – Module body – Module return statement • Naming a module – Similar to naming a variable – Module names are followed by a set of parentheses 22Programming Logic and Design, Eighth Edition
  • 23. Modularizing a Program (continued) • When a main program wants to use a module – “Calls” the module’s name • Flowchart – Symbol used to call a module is a rectangle with a bar across the top – Place the name of the module you are calling inside the rectangle – Draw each module separately with its own sentinel symbols 23Programming Logic and Design, Eighth Edition
  • 24. 24Programming Logic and Design, Eighth Edition Figure 2-3 Program that produces a bill using only main program
  • 25. Modularizing a Program (continued) • Statements taken out of a main program and put into a module have been encapsulated • Main program becomes shorter and easier to understand • Modules are reusable • When statements contribute to the same job, we get greater functional cohesion 25Programming Logic and Design, Eighth Edition
  • 26. 26Programming Logic and Design, Eighth Edition Figure 2-5 The billing program with constants declared within the module
  • 27. Declaring Variables and Constants within Modules • Place any statements within modules – Input, processing, and output statements – Variable and constant declarations • Variables and constants declared in a module are usable only within the module – Visible – In scope, also called local • Portable – Self-contained units that are easily transported 27Programming Logic and Design, Eighth Edition
  • 28. Declaring Variables and Constants within Modules (continued) • Global variables and constants – Declared at the program level – Visible to and usable in all the modules called by the program – Many programmers avoid global variables to minimize errors 28Programming Logic and Design, Eighth Edition
  • 29. Understanding the Most Common Configuration for Mainline Logic • Mainline logic of almost every procedural computer program follows a general structure – Declarations for global variables and constants – Housekeeping tasks - steps you must perform at the beginning of a program to get ready for the rest of the program – Detail loop tasks - do the core work of the program – End-of-job tasks - steps you take at the end of the program to finish the application 29Programming Logic and Design, Eighth Edition
  • 30. Understanding the Most Common Configuration for Mainline Logic (continued) Figure 2-6 Flowchart and pseudocode of mainline logic for a typical procedural program 30Programming Logic and Design, Eighth Edition
  • 31. Creating Hierarchy Charts • Hierarchy chart – Shows the overall picture of how modules are related to one another – Tells you which modules exist within a program and which modules call others – Specific module may be called from several locations within a program • Planning tool – Develop the overall relationship of program modules before you write them • Documentation tool 31Programming Logic and Design, Eighth Edition
  • 32. Creating Hierarchy Charts (continued) 32Programming Logic and Design, Eighth Edition Figure 2-10 Hierarchy chart of payroll report program in Figure 2-8 Figure 2-11 Billing program hierarchy chart
  • 33. Features of Good Program Design • Use program comments where appropriate • Identifiers should be chosen carefully • Strive to design clear statements within your programs and modules • Write clear prompts and echo input • Continue to maintain good programming habits as you develop your programming skills 33Programming Logic and Design, Eighth Edition
  • 34. Using Program Comments • Program comments – Written explanations of programming statements – Not part of the program logic – Serve as documentation for readers of the program • Syntax used differs among programming languages • Flowchart – Use an annotation symbol to hold information that expands on what is stored within another flowchart symbol 34Programming Logic and Design, Eighth Edition
  • 35. Using Program Comments (continued) 35Programming Logic and Design, Eighth Edition Figure 2-12 Pseudocode that declares some variables and includes comments
  • 36. 36Programming Logic and Design, Eighth Edition Figure 2-13 Flowchart that includes annotation symbols
  • 37. Choosing Identifiers • General guidelines – Give a variable or a constant a name that is a noun (because it represents a thing) – Give a module an identifier that is a verb (because it performs an action) – Use meaningful names • Self-documenting – Use pronounceable names – Be judicious in your use of abbreviations – Avoid digits in a name 37Programming Logic and Design, Eighth Edition
  • 38. Choosing Identifiers (continued) • General guidelines (continued) – Use the system your language allows to separate words in long, multiword variable names – Consider including a form of the verb to be – Name constants using all uppercase letters separated by underscores (_) • Programmers create a list of all variables – Data dictionary 38Programming Logic and Design, Eighth Edition
  • 39. Designing Clear Statements • Avoid confusing line breaks • Use temporary variables to clarify long statements 39Programming Logic and Design, Eighth Edition
  • 40. Avoiding Confusing Line Breaks • Most modern programming languages are free-form • Make sure your meaning is clear • Do not combine multiple statements on one line 40Programming Logic and Design, Eighth Edition
  • 41. Using Temporary Variables to Clarify Long Statements • Temporary variable – Work variable – Not used for input or output – Working variable that you use during a program’s execution • Consider using a series of temporary variables to hold intermediate results 41Programming Logic and Design, Eighth Edition
  • 42. Using Temporary Variables to Clarify Long Statements (continued) Figure 2-14 Two ways of achieving the same salespersonCommission result 42Programming Logic and Design, Eighth Edition
  • 43. Writing Clear Prompts and Echoing Input • Prompt – Message displayed on a monitor to ask the user for a response – Used both in command-line and GUI interactive programs • Echoing input – Repeating input back to a user either in a subsequent prompt or in output 43Programming Logic and Design, Eighth Edition
  • 44. Writing Clear Prompts and Echoing Input (continued) Figure 2-15 Beginning of a program that accepts a name and balance as input 44Programming Logic and Design, Eighth Edition
  • 45. 45Programming Logic and Design, Eighth Edition Figure 2-16 Beginning of a program that accepts a name and balance as input and uses a separate prompt for each item
  • 46. Maintaining Good Programming Habits • Every program you write will be better if you: – Plan before you code – Maintain the habit of first drawing flowcharts or writing pseudocode – Desk-check your program logic on paper – Think carefully about the variable and module names you use – Design your program statements to be easy to read and use 46Programming Logic and Design, Eighth Edition
  • 47. Summary • Programs contain literals, variables, and named constants • Arithmetic follows rules of precedence • Break down programming problems into modules – Include a header, a body, and a return statement • Hierarchy charts show relationship among modules • As programs become more complicated: – Need for good planning and design increases 47Programming Logic and Design, Eighth Edition