PROGRAMMING LOGIC AND DESIGN
FREFACE
This book can be used in a stand-alone logic course or as a companion book to an introductory programming text using any programming language.
- Chapter 1 introduces concepts
- Chapter 2 discusses key concepts of structure
- Chapter 3 extends the structure discussion to modules
- Chapter 4 creates complete structured business programs
- Chapter 5 explores decision-making and Boolean logic
- Chapter 6 discusses looping
- Chapter 7 introduces control breaks
- Chapter 8 introduces arrays
- Chapter 9 deals with arrays used for sorting
- Chapter 10 explores interactive programming using menus
- Chapter 11 covers matching and sequential processing
- Chapter 12 addresses object-oriented programming
- Chapter 13 addresses event-driven programming and GUI
- Chapter 14 addresses good programming design in terms of reducing coupling and increasing cohesion
- Chapter 15 provides an introduction to UML, a graphical tool for designing object-oriented systems
Each chapter includes
- Objectives: A useful study aid
- Tips: Alternatives methods and terms
- Summaries: Recaps the programming concepts and techniques covered
- Exercises: Exercises increasing in difficulty designed to provide additional practice in skills and concepts
1. An Overview of Computers and Logic
Objectives:
- Understand components and operations
- Describe programming process
- Describe data hierarchy
- Understand flowchart symbols
- Understand pseudocode statements
- Use and name variables
- Understand sentinel variables
- Describe data types
Key terms:
Data: facts entering the computer system
CPU: Hardware that organizes data, checks for
accuracy, performs mathematical calculations on data
Programming Language: Basic, Visual Basic, Pascal,
COBOL, RPG, C#, C++, Java, Fortran
Syntax: rules governing word usage and punctuation
Compiler (or Interpreter): software to translate the
specific programming language into the computer’s on-off circuitry language
Machine Code: the computer’s on-off circuitry
language
Logic (of a program): the instructions given to a
computer in a specific sequence
Algorithm: the steps necessary to solve any problem
Conversion: the entire set of actions an organization
must take to switch over to using a new program
Flowcharts: pictorial representation of the logical
steps it takes to solve a problem
Pseudocode: an English-like representation of the
steps it takes to solve a problem
Variables: memory locations whose contents can vary
or differ over time
Decision: testing a value
Dummy Variable: pre-selected value that stops
execution of a program
EOF: end of file (of data)
Constants: named memory location, the value of which
never changes during a program (numeric or string)
Computer System Components
- Hardware: equipment or devices associated with a computer
- Software: instructions that tell the computer what to do
Major Operations
- Input
- Processing
- Output
- Storage
Every computer operates on circuitry that consists of
millions of on-off switches
The compiler or interpreter tells you if you have used a
programming language incorrectly
For a program to work correctly, you must not leave any
instructions out or add extraneous instructions
Logic errors are much more difficult to locate than syntax
errors
Once instructions have been input to the computer and
translated to machine language, a program can be run or executed.
Computers often have several input devices such as a
keyboard, a mouse, a CD drive or a disk drive
Disk and CD drives are often categorized as storage rather
than input devices
Storage
1) Internal
storage
- Memory
- Main memory / primary memory
2) External
storage
- Floppy disk
- Hard drive
- Magnetic tape
Internal memory is volatile, i.e. contents are lost every
time the computer loses power
External storage is permanent, i.e. non-volatile storage
Computer memory consists of millions of numbered locations
where data can be stored
Programming Steps
1) Understand
the problem
2) Plan
the logic – developing an algorithm
3) Code
the program
4) Translate
the program into machine language
5) Test
the program
6) Put
the program into production
7) Maintaining
a program
8) Retiring
a program
Understanding the problem may be one of the most
difficult aspects of programming:
- The description of what the user needs may be vague
- User may not know what it is he or she wants
Planning the logic entails deciding on the steps to
include and how to order them
- Utilizes flowcharts or pseudo-code
- Is more difficult than coding the program
Compilers and interpreters translate high-level languages
into low-level languages, i.e. machine language
A program that is free of syntax errors is not necessarily
free of logical errors
Programs should be tested with many sets of data
·
Many companies don’t know that their software
has a problem until an unusual circumstance occurs
Maintenance is necessary for a number of reasons
1) Changes
in the environment
2) Changes
in specifications
3) Formats
of input change
4) Errors
are found
Data Hierarchy
·
Bits
·
Bytes
·
Characters – smallest usable unit of data
·
Fields – a single data item
·
Records – logical groupings of fields
·
Files – logical grouping of records
·
Tables – groups of files that together serve the
needs an organization
·
Databases – organized groupings of files in
table form
Using pseudocode is similar to writing final statements in a
programming language
Flowcharts allow a programmer to more easily visualize how
the program statements will connect
Programmers seldom create both pseudocode and a flowchart
for the same program
Almost every program involves the steps of input, processing
and output
When you crate a flowchart, you draw geometric shapes around
the individual statements and connect them with arrows
·
A parallelogram represents input
A parallelogram represents input
·
A rectangle represents processing, i.e. such as performing arithmetical calculations
A rectangle represents processing, i.e. such as performing arithmetical calculations
·
Parallelograms are also used for output
·
A terminal or start/stop symbol is used at each end
A terminal or start/stop symbol is used at each end
·
A diamond is used as a decision symbol is used for branching
A diamond is used as a decision symbol is used for branching
·
A connector is often used on longer flowcharts
A connector is often used on longer flowcharts
Looping will allow a program to do repetitive calculations
It is the ability of memory variables to change in value
that makes computers and programming worthwhile
Because one memory location can be used over and over again
with different values, you can write program instructions once and then use
them for thousands of separate calculations
Most languages allow both letters and digits within variable
names
Different languages put different limits on the length of
variable names
Newer languages tend to be case-sensitive
Most languages use camel casing where multiple words
are run together with each new word being capitalized
Variable naming rules (for this book)
·
Must be one word
·
Names should have some appropriate meaning
·
Variable names may not begin with a digit
All good computer questions have two mutually exclusive
answers like yes or no or true or false
Sentinel values represent an entry or exit point for
a program
Programming languages can recognize the end of data in file
automatically without using a sentinel value through a code that is stored at
the end of the data.
Connectors should contain a letter or number that can be
matched with another location
Avoid using connectors whenever possible.
Most computer languages allow a shorthand expression for assignment
statements that give variables values
Whatever operation is performed to the right of the equal
sign results in the value that is placed in the memory location named to the
left of the equal sign
It might help to imagine the word “let” in front of an
assignment statement
It makes no sense to perform mathematical operations on
memory locations, but it does make sense to perform them on the contents of
memory locations
Many programming languages allow you to create constants
Some languages require single quotes surrounding character
constants while others require double quotes.
Programmers must distinguish between numeric and character
variables because computers handle the two types of data differently, i.e. you
cannot perform numeric calculations on string data.
Finer distinctions may exist in some languages, such as
those between integer and floating-point variables
Literals are generally represented between quotation marks
to distinguish them from variable names
Summary
- Together,
hardware and software accomplish input, processing, output, and storage.
- A
programmer’s job involves understanding the problem, planning the logic, coding
the program, translating the program into machine language, testing the program
and putting the program into production
- Data
is stored in a hierarchy of characters, fields, records, and files
- Pseudocode
and flowcharts are used to plan logic
- Variables
are named memory locations. All variable names must be written as one word
without embedded spaces and should mean something
- Testing
a value means making a decision. All computer decisions include discreet values
- Most
languages allow the equal sign to assign values to variables. Assignment always
takes place from right to left
- Programmers
must distinguish between numeric and character variables
Chapter Two: Understanding Structure
Objectives:
1) Understand
what makes spaghetti code
2) Describe
three basic structures making up structured programs
3) Understand
primary reads
4) Recognize
structure
Farrell,
Joyce. “Programming Logic and Design”, Comprehensive Second Edition, Copyright 2002 :
Course Technology, a division of Thompson Learning.
0 komentar:
Posting Komentar