SlideShare a Scribd company logo
1 of 47
A Beginner’s Guide to 
Programming Logic, 
Introductory 
Chapter 2 
Working with Data, Creating Modules, 
and Designing High-Quality Programs
Objectives 
In this chapter, you will learn about: 
• Declaring and using variables and constants 
• Assigning values to variables 
• The advantages of modularization 
• Modularizing a program 
• The most common configuration for mainline logic 
A Beginner's Guide to Programming Logic, Introductory 2
Objectives (continued) 
In this chapter, you will learn about: (continued) 
• Hierarchy charts 
• Some features of good program design 
A Beginner's Guide to Programming Logic, Introductory 3
Declaring and Using Variables 
and Constants 
• Data items 
– All the text, numbers, and other information that are 
processed by a computer 
– Stored in variables in memory 
• Different forms 
– Variables 
– Literals, or unnamed constants 
– Named constants 
A Beginner's Guide to Programming Logic, Introductory 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 
A Beginner's Guide to Programming Logic, Introductory 5
Working with Variables (continued) 
Figure 2-1 Flowchart and pseudocode for the number-doubling program 
A Beginner's Guide to Programming Logic, Introductory 6
Working with Variables (continued) 
• 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 a variable 
– Declare a starting value for any variable 
• Garbage 
– Variable’s unknown value before initialization 
A Beginner's Guide to Programming Logic, Introductory 7
Figure 2-2 Flowchart and pseudocode of number-doubling program 
with variable declarations 
A Beginner's Guide to Programming Logic, Introductory 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 
• Some languages allow dollar signs or other special 
characters 
• Different limits on the length of variable names 
A Beginner's Guide to Programming Logic, Introductory 9
Naming Variables (continued) 
• Camel casing 
– Variable names such as hourlyWage have a 
“hump” in the middle 
• Variable names used throughout book 
– Must be one word 
– Should have some appropriate meaning 
A Beginner's Guide to Programming Logic, Introductory 10
Understanding Unnamed, Literal 
Constants and their Data Types 
• Numeric constant (or literal numeric constant) 
– Specific numeric value 
• Example: 43 
– Does not change 
• String constant (or literal string constant) 
– String of characters enclosed within quotation marks 
– Example: “Amanda” 
• Unnamed constants 
– Do not have identifiers like variables do 
A Beginner's Guide to Programming Logic, Introductory 11
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 
• Assign data to a variable 
– Only if it is the correct type 
A Beginner's Guide to Programming Logic, Introductory 12
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 
– Purpose is not immediately apparent 
– Avoid this 
A Beginner's Guide to Programming Logic, Introductory 13
Assigning Values to Variables 
• Assignment statement 
– set myAnswer = myNumber * 2 
• Assignment operator 
– Equal sign 
– Always operates from right to left 
• Valid 
– set someNumber = 2 
– set someNumber = someOtherNumber 
• Not valid 
– set 2 + 4 = someNumber 
A Beginner's Guide to Programming Logic, Introductory 14
Performing Arithmetic Operations 
• Standard arithmetic operators: 
– + (plus sign)—addition 
– − (minus sign)—subtraction 
– * (asterisk)—multiplication 
– / (slash)—division 
A Beginner's Guide to Programming Logic, Introductory 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 
– Multiplication and division are evaluated next 
• From left to right 
– Addition and subtraction are evaluated next 
• From left to right 
A Beginner's Guide to Programming Logic, Introductory 16
Performing Arithmetic Operations 
(continued) 
• Left-to-right associativity 
– Operations with the same precedence take place 
from left to right 
A Beginner's Guide to Programming Logic, Introductory 17
Performing Arithmetic Operations 
(continued) 
Table 2-1 Precedence and associativity of five common operators 
A Beginner's Guide to Programming Logic, Introductory 18
Understanding the Advantages 
of Modularization 
• Modules 
– Subunit of programming problem 
– Also called subroutines, procedures, functions, or 
methods 
• Modularization 
– Breaking down a large program into modules 
– Reasons 
• Abstraction 
• Allows multiple programmers to work on a problem 
• Reuse your work more easily 
A Beginner's Guide to Programming Logic, Introductory 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 
A Beginner's Guide to Programming Logic, Introductory 20
Modularization Allows Multiple 
Programmers to Work on a Problem 
• More easily 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 
A Beginner's Guide to Programming Logic, Introductory 21
Modularization Allows You to Reuse 
Your Work 
• Reusability 
– Feature of modular programs 
– Allows individual modules to be used in a variety of 
applications 
– Many real-world examples of reusability 
• Reliability 
– Feature of programs that assures you a module has 
been tested and proven to function correctly 
A Beginner's Guide to Programming Logic, Introductory 22
Modularizing a Program 
• Main program 
– Basic steps (mainline logic) of the program 
• Include in a module 
– Header 
– Body 
– Return statement 
• Naming a module 
– Similar to naming a variable 
– Module names are followed by a set of parentheses 
A Beginner's Guide to Programming Logic, Introductory 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 
A Beginner's Guide to Programming Logic, Introductory 24
Figure 2-3 Program that produces a bill using only main program 
A Beginner's Guide to Programming Logic, Introductory 25
Modularizing a Program (continued) 
• Determine when to break down any particular 
program into modules 
– Does not depend on a fixed set of rules 
– Programmers do follow some guidelines 
– Statements should contribute to the same job 
• Functional cohesion 
A Beginner's Guide to Programming Logic, Introductory 26
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 
• Portable 
– Self-contained units that are easily transported 
A Beginner's Guide to Programming Logic, Introductory 27
Figure 2-5 The billing program with constants declared within the module 
A Beginner's Guide to Programming Logic, Introductory 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 
A Beginner's Guide to Programming Logic, Introductory 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 
– Detail loop tasks 
– End-of-job tasks 
A Beginner's Guide to Programming Logic, Introductory 30
Understanding the Most Common 
Configuration for Mainline Logic 
(continued) 
Figure 2-6 Flowchart and pseudocode of mainline logic for a typical 
procedural program 
A Beginner's Guide to Programming Logic, Introductory 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 
A Beginner's Guide to Programming Logic, Introductory 32
Features of Good Program Design 
• Use program comments where appropriate 
• Identifiers should be well-chosen 
• 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 
A Beginner's Guide to Programming Logic, Introductory 33
Using Program Comments 
• Program comments 
– Written explanations 
– 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 
A Beginner's Guide to Programming Logic, Introductory 34
Using Program Comments (continued) 
Figure 2-12 Pseudocode that declares some variables and includes comments 
A Beginner's Guide to Programming Logic, Introductory 35
Figure 2-13 Flowchart that includes some annotation symbols 
A Beginner's Guide to Programming Logic, Introductory 36
Choosing Identifiers 
• General guidelines 
– Give a variable or a constant a name that is a noun 
– Give a module an identifier that is a verb 
– Use meaningful names 
• Self-documenting 
– Use pronounceable names 
– Be judicious in your use of abbreviations 
– Avoid digits in a name 
A Beginner's Guide to Programming Logic, Introductory 37
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 (_) 
• Organizations sometimes enforce different rules for 
programmers to follow when naming variables 
– Hungarian notation 
A Beginner's Guide to Programming Logic, Introductory 38
Designing Clear Statements 
• Avoid confusing line breaks 
• Use temporary variables to clarify long statements 
A Beginner's Guide to Programming Logic, Introductory 39
Avoiding Confusing Line Breaks 
• Most modern programming languages are free-form 
• Take care to make sure your meaning is clear 
• Do not combine multiple statements on one line 
A Beginner's Guide to Programming Logic, Introductory 40
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 
A Beginner's Guide to Programming Logic, Introductory 41
Using Temporary Variables to Clarify 
Long Statements (continued) 
Figure 2-14 Two ways of achieving the same salespersonCommission 
result 
A Beginner's Guide to Programming Logic, Introductory 42
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 
A Beginner's Guide to Programming Logic, Introductory 43
Writing Clear Prompts and Echoing 
Input (continued) 
Figure 2-15 Beginning of a program that accepts a name 
and balance as input 
A Beginner's Guide to Programming Logic, Introductory 44
Figure 2-16 Beginning of a program that accepts a name and balance as 
input and uses a separate prompt for each item 
A Beginner's Guide to Programming Logic, Introductory 45
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 
A Beginner's Guide to Programming Logic, Introductory 46
Summary 
• Variables 
– Named memory locations with variable contents 
• Equal sign is the assignment operator 
• Break down programming problems into 
reasonable units called modules 
– Include a header, a body, and a return statement 
• Mainline logic of almost every procedural computer 
program can follow a general structure 
• As your programs become more complicated: 
– Need for good planning and design increases 
A Beginner's Guide to Programming Logic, Introductory 47

More Related Content

What's hot

Introduction to software engineering
Introduction to software engineeringIntroduction to software engineering
Introduction to software engineeringHitesh Mohapatra
 
Algorithm and Programming (Introduction of Algorithms)
Algorithm and Programming (Introduction of Algorithms)Algorithm and Programming (Introduction of Algorithms)
Algorithm and Programming (Introduction of Algorithms)Adam Mukharil Bachtiar
 
Process management in os
Process management in osProcess management in os
Process management in osSumant Diwakar
 
Classification of Programming Languages
Classification of Programming LanguagesClassification of Programming Languages
Classification of Programming LanguagesProject Student
 
Unit 1 - Introduction to Software Engineering.ppt
Unit 1 - Introduction to Software Engineering.pptUnit 1 - Introduction to Software Engineering.ppt
Unit 1 - Introduction to Software Engineering.pptDrTThendralCompSci
 
2.2. language evaluation criteria
2.2. language evaluation criteria2.2. language evaluation criteria
2.2. language evaluation criteriaannahallare_
 
Introduction to Programming Languages
Introduction to Programming LanguagesIntroduction to Programming Languages
Introduction to Programming Languageseducationfront
 
Introduction to computer programming
Introduction to computer programmingIntroduction to computer programming
Introduction to computer programmingSangheethaa Sukumaran
 
Programming Fundamentals lecture 2
Programming Fundamentals lecture 2Programming Fundamentals lecture 2
Programming Fundamentals lecture 2REHAN IJAZ
 
What Is Coding And Why Should You Learn It?
What Is Coding And Why Should You Learn It?What Is Coding And Why Should You Learn It?
What Is Coding And Why Should You Learn It?Syed Hassan Raza
 
Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis Dr. Pankaj Agarwal
 
Our presentation on algorithm design
Our presentation on algorithm designOur presentation on algorithm design
Our presentation on algorithm designNahid Hasan
 
Computer Programming Overview
Computer Programming OverviewComputer Programming Overview
Computer Programming Overviewagorolabs
 
Software Engineering (Introduction to Software Engineering)
Software Engineering (Introduction to Software Engineering)Software Engineering (Introduction to Software Engineering)
Software Engineering (Introduction to Software Engineering)ShudipPal
 
Design and analysis of algorithms
Design and analysis of algorithmsDesign and analysis of algorithms
Design and analysis of algorithmsDr Geetha Mohan
 
Lesson 1: Scratch Computer Programming
Lesson 1: Scratch Computer ProgrammingLesson 1: Scratch Computer Programming
Lesson 1: Scratch Computer ProgrammingSeniorInfants
 
Lesson 4.0 elements of computer and communication system
Lesson 4.0   elements of computer and communication systemLesson 4.0   elements of computer and communication system
Lesson 4.0 elements of computer and communication systemJoshua Hernandez
 
Round Robin Algorithm.pptx
Round Robin Algorithm.pptxRound Robin Algorithm.pptx
Round Robin Algorithm.pptxSanad Bhowmik
 

What's hot (20)

Introduction to software engineering
Introduction to software engineeringIntroduction to software engineering
Introduction to software engineering
 
Algorithm and Programming (Introduction of Algorithms)
Algorithm and Programming (Introduction of Algorithms)Algorithm and Programming (Introduction of Algorithms)
Algorithm and Programming (Introduction of Algorithms)
 
Process management in os
Process management in osProcess management in os
Process management in os
 
Classification of Programming Languages
Classification of Programming LanguagesClassification of Programming Languages
Classification of Programming Languages
 
Unit 1 - Introduction to Software Engineering.ppt
Unit 1 - Introduction to Software Engineering.pptUnit 1 - Introduction to Software Engineering.ppt
Unit 1 - Introduction to Software Engineering.ppt
 
2.2. language evaluation criteria
2.2. language evaluation criteria2.2. language evaluation criteria
2.2. language evaluation criteria
 
Introduction to Programming Languages
Introduction to Programming LanguagesIntroduction to Programming Languages
Introduction to Programming Languages
 
Introduction to computer programming
Introduction to computer programmingIntroduction to computer programming
Introduction to computer programming
 
Programming Fundamentals lecture 2
Programming Fundamentals lecture 2Programming Fundamentals lecture 2
Programming Fundamentals lecture 2
 
What Is Coding And Why Should You Learn It?
What Is Coding And Why Should You Learn It?What Is Coding And Why Should You Learn It?
What Is Coding And Why Should You Learn It?
 
Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis
 
Our presentation on algorithm design
Our presentation on algorithm designOur presentation on algorithm design
Our presentation on algorithm design
 
Computer Programming Overview
Computer Programming OverviewComputer Programming Overview
Computer Programming Overview
 
Software Engineering (Introduction to Software Engineering)
Software Engineering (Introduction to Software Engineering)Software Engineering (Introduction to Software Engineering)
Software Engineering (Introduction to Software Engineering)
 
Design and analysis of algorithms
Design and analysis of algorithmsDesign and analysis of algorithms
Design and analysis of algorithms
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
 
Introduction to Compiler design
Introduction to Compiler design Introduction to Compiler design
Introduction to Compiler design
 
Lesson 1: Scratch Computer Programming
Lesson 1: Scratch Computer ProgrammingLesson 1: Scratch Computer Programming
Lesson 1: Scratch Computer Programming
 
Lesson 4.0 elements of computer and communication system
Lesson 4.0   elements of computer and communication systemLesson 4.0   elements of computer and communication system
Lesson 4.0 elements of computer and communication system
 
Round Robin Algorithm.pptx
Round Robin Algorithm.pptxRound Robin Algorithm.pptx
Round Robin Algorithm.pptx
 

Viewers also liked

Komunikasyon
KomunikasyonKomunikasyon
Komunikasyondeathful
 
Program logic formulation
Program logic formulationProgram logic formulation
Program logic formulationSara Corpuz
 
Webpage Visual Design and Online Prototype
Webpage Visual Design and Online PrototypeWebpage Visual Design and Online Prototype
Webpage Visual Design and Online Prototypeamoore155
 
Chapter 7.4
Chapter 7.4Chapter 7.4
Chapter 7.4sotlsoc
 
Chapter 3.1
Chapter 3.1Chapter 3.1
Chapter 3.1sotlsoc
 
Basics in algorithms and data structure
Basics in algorithms and data structure Basics in algorithms and data structure
Basics in algorithms and data structure Eman magdy
 
Problem Solving with Algorithms and Data Structure - Lists
Problem Solving with Algorithms and Data Structure - ListsProblem Solving with Algorithms and Data Structure - Lists
Problem Solving with Algorithms and Data Structure - ListsYi-Lung Tsai
 
Problem Solving with Algorithms and Data Structure - Graphs
Problem Solving with Algorithms and Data Structure - GraphsProblem Solving with Algorithms and Data Structure - Graphs
Problem Solving with Algorithms and Data Structure - GraphsYi-Lung Tsai
 
Aralin sa Pakikinig
Aralin sa PakikinigAralin sa Pakikinig
Aralin sa Pakikinigdeathful
 
Mga Modelo ng Komunikasyon
Mga Modelo ng KomunikasyonMga Modelo ng Komunikasyon
Mga Modelo ng Komunikasyondeathful
 
Real Numbers
Real NumbersReal Numbers
Real Numbersdeathful
 
Data Structure & Algorithms | Computer Science
Data Structure & Algorithms | Computer ScienceData Structure & Algorithms | Computer Science
Data Structure & Algorithms | Computer ScienceTransweb Global Inc
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithmsJulie Iskander
 
មេរៀនៈ Data Structure and Algorithm in C/C++
មេរៀនៈ Data Structure and Algorithm in C/C++មេរៀនៈ Data Structure and Algorithm in C/C++
មេរៀនៈ Data Structure and Algorithm in C/C++Ngeam Soly
 

Viewers also liked (18)

Komunikasyon
KomunikasyonKomunikasyon
Komunikasyon
 
Program logic formulation
Program logic formulationProgram logic formulation
Program logic formulation
 
Data Structure Basics
Data Structure BasicsData Structure Basics
Data Structure Basics
 
Webpage Visual Design and Online Prototype
Webpage Visual Design and Online PrototypeWebpage Visual Design and Online Prototype
Webpage Visual Design and Online Prototype
 
Chapter 7.4
Chapter 7.4Chapter 7.4
Chapter 7.4
 
Chapter 3.1
Chapter 3.1Chapter 3.1
Chapter 3.1
 
Basics in algorithms and data structure
Basics in algorithms and data structure Basics in algorithms and data structure
Basics in algorithms and data structure
 
Chap 2(const var-datatype)
Chap 2(const var-datatype)Chap 2(const var-datatype)
Chap 2(const var-datatype)
 
2. electric field calculation
2. electric field calculation2. electric field calculation
2. electric field calculation
 
Digital Logic
Digital LogicDigital Logic
Digital Logic
 
Problem Solving with Algorithms and Data Structure - Lists
Problem Solving with Algorithms and Data Structure - ListsProblem Solving with Algorithms and Data Structure - Lists
Problem Solving with Algorithms and Data Structure - Lists
 
Problem Solving with Algorithms and Data Structure - Graphs
Problem Solving with Algorithms and Data Structure - GraphsProblem Solving with Algorithms and Data Structure - Graphs
Problem Solving with Algorithms and Data Structure - Graphs
 
Aralin sa Pakikinig
Aralin sa PakikinigAralin sa Pakikinig
Aralin sa Pakikinig
 
Mga Modelo ng Komunikasyon
Mga Modelo ng KomunikasyonMga Modelo ng Komunikasyon
Mga Modelo ng Komunikasyon
 
Real Numbers
Real NumbersReal Numbers
Real Numbers
 
Data Structure & Algorithms | Computer Science
Data Structure & Algorithms | Computer ScienceData Structure & Algorithms | Computer Science
Data Structure & Algorithms | Computer Science
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 
មេរៀនៈ Data Structure and Algorithm in C/C++
មេរៀនៈ Data Structure and Algorithm in C/C++មេរៀនៈ Data Structure and Algorithm in C/C++
មេរៀនៈ Data Structure and Algorithm in C/C++
 

Similar to Logic Formulation 2

test.pptx
test.pptxtest.pptx
test.pptxStacia7
 
Algorithmic problem sloving
Algorithmic problem slovingAlgorithmic problem sloving
Algorithmic problem slovingMani Kandan
 
C programming for Computing Techniques
C programming for Computing TechniquesC programming for Computing Techniques
C programming for Computing TechniquesAppili Vamsi Krishna
 
FPL -Part 2 ( Sem - I 2013)
FPL -Part 2 ( Sem - I 2013)FPL -Part 2 ( Sem - I 2013)
FPL -Part 2 ( Sem - I 2013)Yogesh Deshpande
 
01 introduction to cpp
01   introduction to cpp01   introduction to cpp
01 introduction to cppManzoor ALam
 
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 onessuserb7c8b8
 
Unit 1 python (2021 r)
Unit 1 python (2021 r)Unit 1 python (2021 r)
Unit 1 python (2021 r)praveena p
 
Unified modeling language basics and slides
Unified modeling language basics and slidesUnified modeling language basics and slides
Unified modeling language basics and slidesvenkatasubramanianSr5
 
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptxCOMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptxSherinRappai1
 
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptxCOMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptxSherinRappai
 
Algorithms and flow charts
Algorithms and flow chartsAlgorithms and flow charts
Algorithms and flow chartsChinnu Edwin
 
Programming language paradigms
Programming language paradigmsProgramming language paradigms
Programming language paradigmsAshok Raj
 

Similar to Logic Formulation 2 (20)

test.pptx
test.pptxtest.pptx
test.pptx
 
Chap1
Chap1Chap1
Chap1
 
Algorithmic problem sloving
Algorithmic problem slovingAlgorithmic problem sloving
Algorithmic problem sloving
 
C programming for Computing Techniques
C programming for Computing TechniquesC programming for Computing Techniques
C programming for Computing Techniques
 
Cs111 ch01 v4
Cs111 ch01 v4Cs111 ch01 v4
Cs111 ch01 v4
 
c#.pptx
c#.pptxc#.pptx
c#.pptx
 
FPL -Part 2 ( Sem - I 2013)
FPL -Part 2 ( Sem - I 2013)FPL -Part 2 ( Sem - I 2013)
FPL -Part 2 ( Sem - I 2013)
 
01 introduction to cpp
01   introduction to cpp01   introduction to cpp
01 introduction to cpp
 
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
 
Unit 1 python (2021 r)
Unit 1 python (2021 r)Unit 1 python (2021 r)
Unit 1 python (2021 r)
 
Unified modeling language basics and slides
Unified modeling language basics and slidesUnified modeling language basics and slides
Unified modeling language basics and slides
 
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptxCOMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
 
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptxCOMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
 
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
 
SMD.pptx
SMD.pptxSMD.pptx
SMD.pptx
 
pccf unit 1 _VP.pptx
pccf unit 1 _VP.pptxpccf unit 1 _VP.pptx
pccf unit 1 _VP.pptx
 
Introduction to problem solving in C
Introduction to problem solving in CIntroduction to problem solving in C
Introduction to problem solving in C
 
Algorithms and flow charts
Algorithms and flow chartsAlgorithms and flow charts
Algorithms and flow charts
 
FLOWCHARTS.pptx
FLOWCHARTS.pptxFLOWCHARTS.pptx
FLOWCHARTS.pptx
 
Programming language paradigms
Programming language paradigmsProgramming language paradigms
Programming language paradigms
 

More from deathful

Wastong Gamit ng mga Salita
Wastong Gamit ng mga SalitaWastong Gamit ng mga Salita
Wastong Gamit ng mga Salitadeathful
 
UST ICS Freshmen Orientation
UST ICS Freshmen OrientationUST ICS Freshmen Orientation
UST ICS Freshmen Orientationdeathful
 
College Algebra
College AlgebraCollege Algebra
College Algebradeathful
 
Special Products
Special ProductsSpecial Products
Special Productsdeathful
 
Theories About Light
Theories About LightTheories About Light
Theories About Lightdeathful
 
Provision For Depreciation
Provision For DepreciationProvision For Depreciation
Provision For Depreciationdeathful
 
Acid-Base Titration & Calculations
Acid-Base Titration & CalculationsAcid-Base Titration & Calculations
Acid-Base Titration & Calculationsdeathful
 
Microbiology Techniques
Microbiology TechniquesMicrobiology Techniques
Microbiology Techniquesdeathful
 
Streak Plating
Streak PlatingStreak Plating
Streak Platingdeathful
 
Egg Windowing
Egg WindowingEgg Windowing
Egg Windowingdeathful
 
Egg Injection
Egg InjectionEgg Injection
Egg Injectiondeathful
 
Colony Counter Compatibility Mode
Colony Counter Compatibility ModeColony Counter Compatibility Mode
Colony Counter Compatibility Modedeathful
 
Isolating Chromosomes
Isolating ChromosomesIsolating Chromosomes
Isolating Chromosomesdeathful
 
Aseptic Technique
Aseptic TechniqueAseptic Technique
Aseptic Techniquedeathful
 
Agar Culture Medium
Agar Culture MediumAgar Culture Medium
Agar Culture Mediumdeathful
 
Allium Cepa Genotoxicity Test
Allium Cepa Genotoxicity TestAllium Cepa Genotoxicity Test
Allium Cepa Genotoxicity Testdeathful
 
Tilapia Nilotica As A Biological Indicator
Tilapia Nilotica As A Biological IndicatorTilapia Nilotica As A Biological Indicator
Tilapia Nilotica As A Biological Indicatordeathful
 
Pagkonsumo
PagkonsumoPagkonsumo
Pagkonsumodeathful
 

More from deathful (19)

Wastong Gamit ng mga Salita
Wastong Gamit ng mga SalitaWastong Gamit ng mga Salita
Wastong Gamit ng mga Salita
 
UST ICS Freshmen Orientation
UST ICS Freshmen OrientationUST ICS Freshmen Orientation
UST ICS Freshmen Orientation
 
College Algebra
College AlgebraCollege Algebra
College Algebra
 
Special Products
Special ProductsSpecial Products
Special Products
 
Theories About Light
Theories About LightTheories About Light
Theories About Light
 
Provision For Depreciation
Provision For DepreciationProvision For Depreciation
Provision For Depreciation
 
Acid-Base Titration & Calculations
Acid-Base Titration & CalculationsAcid-Base Titration & Calculations
Acid-Base Titration & Calculations
 
Microbiology Techniques
Microbiology TechniquesMicrobiology Techniques
Microbiology Techniques
 
Streak Plating
Streak PlatingStreak Plating
Streak Plating
 
Egg Windowing
Egg WindowingEgg Windowing
Egg Windowing
 
Egg Injection
Egg InjectionEgg Injection
Egg Injection
 
Colony Counter Compatibility Mode
Colony Counter Compatibility ModeColony Counter Compatibility Mode
Colony Counter Compatibility Mode
 
Isolating Chromosomes
Isolating ChromosomesIsolating Chromosomes
Isolating Chromosomes
 
Autoclave
AutoclaveAutoclave
Autoclave
 
Aseptic Technique
Aseptic TechniqueAseptic Technique
Aseptic Technique
 
Agar Culture Medium
Agar Culture MediumAgar Culture Medium
Agar Culture Medium
 
Allium Cepa Genotoxicity Test
Allium Cepa Genotoxicity TestAllium Cepa Genotoxicity Test
Allium Cepa Genotoxicity Test
 
Tilapia Nilotica As A Biological Indicator
Tilapia Nilotica As A Biological IndicatorTilapia Nilotica As A Biological Indicator
Tilapia Nilotica As A Biological Indicator
 
Pagkonsumo
PagkonsumoPagkonsumo
Pagkonsumo
 

Recently uploaded

IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 

Recently uploaded (20)

IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 

Logic Formulation 2

  • 1. A Beginner’s Guide to Programming Logic, Introductory Chapter 2 Working with Data, Creating Modules, and Designing High-Quality Programs
  • 2. Objectives In this chapter, you will learn about: • Declaring and using variables and constants • Assigning values to variables • The advantages of modularization • Modularizing a program • The most common configuration for mainline logic A Beginner's Guide to Programming Logic, Introductory 2
  • 3. Objectives (continued) In this chapter, you will learn about: (continued) • Hierarchy charts • Some features of good program design A Beginner's Guide to Programming Logic, Introductory 3
  • 4. Declaring and Using Variables and Constants • Data items – All the text, numbers, and other information that are processed by a computer – Stored in variables in memory • Different forms – Variables – Literals, or unnamed constants – Named constants A Beginner's Guide to Programming Logic, Introductory 4
  • 5. 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 A Beginner's Guide to Programming Logic, Introductory 5
  • 6. Working with Variables (continued) Figure 2-1 Flowchart and pseudocode for the number-doubling program A Beginner's Guide to Programming Logic, Introductory 6
  • 7. Working with Variables (continued) • 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 a variable – Declare a starting value for any variable • Garbage – Variable’s unknown value before initialization A Beginner's Guide to Programming Logic, Introductory 7
  • 8. Figure 2-2 Flowchart and pseudocode of number-doubling program with variable declarations A Beginner's Guide to Programming Logic, Introductory 8
  • 9. 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 • Some languages allow dollar signs or other special characters • Different limits on the length of variable names A Beginner's Guide to Programming Logic, Introductory 9
  • 10. Naming Variables (continued) • Camel casing – Variable names such as hourlyWage have a “hump” in the middle • Variable names used throughout book – Must be one word – Should have some appropriate meaning A Beginner's Guide to Programming Logic, Introductory 10
  • 11. Understanding Unnamed, Literal Constants and their Data Types • Numeric constant (or literal numeric constant) – Specific numeric value • Example: 43 – Does not change • String constant (or literal string constant) – String of characters enclosed within quotation marks – Example: “Amanda” • Unnamed constants – Do not have identifiers like variables do A Beginner's Guide to Programming Logic, Introductory 11
  • 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 • Assign data to a variable – Only if it is the correct type A Beginner's Guide to Programming Logic, Introductory 12
  • 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 – Purpose is not immediately apparent – Avoid this A Beginner's Guide to Programming Logic, Introductory 13
  • 14. Assigning Values to Variables • Assignment statement – set myAnswer = myNumber * 2 • Assignment operator – Equal sign – Always operates from right to left • Valid – set someNumber = 2 – set someNumber = someOtherNumber • Not valid – set 2 + 4 = someNumber A Beginner's Guide to Programming Logic, Introductory 14
  • 15. Performing Arithmetic Operations • Standard arithmetic operators: – + (plus sign)—addition – − (minus sign)—subtraction – * (asterisk)—multiplication – / (slash)—division A Beginner's Guide to Programming Logic, Introductory 15
  • 16. 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 – Multiplication and division are evaluated next • From left to right – Addition and subtraction are evaluated next • From left to right A Beginner's Guide to Programming Logic, Introductory 16
  • 17. Performing Arithmetic Operations (continued) • Left-to-right associativity – Operations with the same precedence take place from left to right A Beginner's Guide to Programming Logic, Introductory 17
  • 18. Performing Arithmetic Operations (continued) Table 2-1 Precedence and associativity of five common operators A Beginner's Guide to Programming Logic, Introductory 18
  • 19. Understanding the Advantages of Modularization • Modules – Subunit of programming problem – Also called subroutines, procedures, functions, or methods • Modularization – Breaking down a large program into modules – Reasons • Abstraction • Allows multiple programmers to work on a problem • Reuse your work more easily A Beginner's Guide to Programming Logic, Introductory 19
  • 20. 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 A Beginner's Guide to Programming Logic, Introductory 20
  • 21. Modularization Allows Multiple Programmers to Work on a Problem • More easily 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 A Beginner's Guide to Programming Logic, Introductory 21
  • 22. Modularization Allows You to Reuse Your Work • Reusability – Feature of modular programs – Allows individual modules to be used in a variety of applications – Many real-world examples of reusability • Reliability – Feature of programs that assures you a module has been tested and proven to function correctly A Beginner's Guide to Programming Logic, Introductory 22
  • 23. Modularizing a Program • Main program – Basic steps (mainline logic) of the program • Include in a module – Header – Body – Return statement • Naming a module – Similar to naming a variable – Module names are followed by a set of parentheses A Beginner's Guide to Programming Logic, Introductory 23
  • 24. 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 A Beginner's Guide to Programming Logic, Introductory 24
  • 25. Figure 2-3 Program that produces a bill using only main program A Beginner's Guide to Programming Logic, Introductory 25
  • 26. Modularizing a Program (continued) • Determine when to break down any particular program into modules – Does not depend on a fixed set of rules – Programmers do follow some guidelines – Statements should contribute to the same job • Functional cohesion A Beginner's Guide to Programming Logic, Introductory 26
  • 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 • Portable – Self-contained units that are easily transported A Beginner's Guide to Programming Logic, Introductory 27
  • 28. Figure 2-5 The billing program with constants declared within the module A Beginner's Guide to Programming Logic, Introductory 28
  • 29. 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 A Beginner's Guide to Programming Logic, Introductory 29
  • 30. 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 – Detail loop tasks – End-of-job tasks A Beginner's Guide to Programming Logic, Introductory 30
  • 31. Understanding the Most Common Configuration for Mainline Logic (continued) Figure 2-6 Flowchart and pseudocode of mainline logic for a typical procedural program A Beginner's Guide to Programming Logic, Introductory 31
  • 32. 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 A Beginner's Guide to Programming Logic, Introductory 32
  • 33. Features of Good Program Design • Use program comments where appropriate • Identifiers should be well-chosen • 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 A Beginner's Guide to Programming Logic, Introductory 33
  • 34. Using Program Comments • Program comments – Written explanations – 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 A Beginner's Guide to Programming Logic, Introductory 34
  • 35. Using Program Comments (continued) Figure 2-12 Pseudocode that declares some variables and includes comments A Beginner's Guide to Programming Logic, Introductory 35
  • 36. Figure 2-13 Flowchart that includes some annotation symbols A Beginner's Guide to Programming Logic, Introductory 36
  • 37. Choosing Identifiers • General guidelines – Give a variable or a constant a name that is a noun – Give a module an identifier that is a verb – Use meaningful names • Self-documenting – Use pronounceable names – Be judicious in your use of abbreviations – Avoid digits in a name A Beginner's Guide to Programming Logic, Introductory 37
  • 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 (_) • Organizations sometimes enforce different rules for programmers to follow when naming variables – Hungarian notation A Beginner's Guide to Programming Logic, Introductory 38
  • 39. Designing Clear Statements • Avoid confusing line breaks • Use temporary variables to clarify long statements A Beginner's Guide to Programming Logic, Introductory 39
  • 40. Avoiding Confusing Line Breaks • Most modern programming languages are free-form • Take care to make sure your meaning is clear • Do not combine multiple statements on one line A Beginner's Guide to Programming Logic, Introductory 40
  • 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 A Beginner's Guide to Programming Logic, Introductory 41
  • 42. Using Temporary Variables to Clarify Long Statements (continued) Figure 2-14 Two ways of achieving the same salespersonCommission result A Beginner's Guide to Programming Logic, Introductory 42
  • 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 A Beginner's Guide to Programming Logic, Introductory 43
  • 44. Writing Clear Prompts and Echoing Input (continued) Figure 2-15 Beginning of a program that accepts a name and balance as input A Beginner's Guide to Programming Logic, Introductory 44
  • 45. Figure 2-16 Beginning of a program that accepts a name and balance as input and uses a separate prompt for each item A Beginner's Guide to Programming Logic, Introductory 45
  • 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 A Beginner's Guide to Programming Logic, Introductory 46
  • 47. Summary • Variables – Named memory locations with variable contents • Equal sign is the assignment operator • Break down programming problems into reasonable units called modules – Include a header, a body, and a return statement • Mainline logic of almost every procedural computer program can follow a general structure • As your programs become more complicated: – Need for good planning and design increases A Beginner's Guide to Programming Logic, Introductory 47