Sei sulla pagina 1di 7

Objectives

In this chapter, you will learn about:


Programming Logic and • Computer systems
Design • Simple program logic
Sixth Edition • The steps involved in the program development
cycle
Chapter 1 • Pseudocode statements and flowchart symbols
An Overview of Computers and • Using a sentinel value to end a program
• Programming and user environments
Programming • The evolution of programming models

Programming Logic & Design, Sixth Edition 2

Understanding Computer Systems


Understanding Computer Systems
(continued)
• Computer system • Programming
– Combination of all the components required to – Writing software instructions
process and store data using a computer • Computer hardware and software accomplish three
• Hardware major operations
– Equipment associated with a computer – Input
• Software • Data items enter computer
– Computer instructions – Processing
– Tell the hardware what to do • By central processing unit (CPU)
– Programs – Output
• Instructions written by programmers

Programming Logic & Design, Sixth Edition 3 Programming Logic & Design, Sixth Edition 4

Understanding Computer Systems Understanding Computer Systems


(continued) (continued)
• Programming language • Permanent storage devices
– Use to write computer instructions – Nonvolatile
– Examples • Compiler or an interpreter
• Visual Basic, C#, C++, or Java – Translates program code into machine language
• Syntax (binary language)
– Rules governing its word usage and punctuation – Checks for syntax errors
• Computer memory • Program executes or runs
– Computer’s temporary, internal storage – Input will be accepted, some processing will occur,
– Volatile and results will be output

Programming Logic & Design, Sixth Edition 5 Programming Logic & Design, Sixth Edition 6

1
Understanding the Program
Understanding Simple Program Logic
Development Cycle
• Program with syntax errors cannot execute • Program development cycle
• Logical errors – Understand the problem
– Errors in program logic – Plan the logic
– Produce incorrect output as a result – Code the program
• Logic of the computer program – Use software (a compiler or interpreter) to translate
– Sequence of specific instructions in specific order the program into machine language
– Test the program
• Variable
– Put the program into production
– Named memory location whose value can vary
– Maintain the program

Programming Logic & Design, Sixth Edition 7 Programming Logic & Design, Sixth Edition 8

Understanding the Program


Understanding the Problem
Development Cycle (continued)
• One of the most difficult aspects of programming
• Users or end users
– People for whom program is written
• Documentation
– Supporting paperwork for a program

Figure 1-1 The program development cycle

Programming Logic & Design, Sixth Edition 9 Programming Logic & Design, Sixth Edition 10

Planning the Logic Coding the Program

• Heart of the programming process • Hundreds of programming languages are available


• Most common planning tools – Choose based on features
– Flowcharts – Alike in their basic capabilities
– Pseudocode • Easier than planning step
• Desk-checking
– Walking through a program’s logic on paper before
you actually write the program

Programming Logic & Design, Sixth Edition 11 Programming Logic & Design, Sixth Edition 12

2
Using Software to Translate the
Using Software to Translate the
Program into Machine Language
Program into Machine Language
(continued)
• Translator program
– Compiler or interpreter
– Changes the programmer’s English-like high-level
programming language into the low-level
machine language
• Syntax error
– Misuse of a language’s grammar rules
– Programmer corrects listed syntax errors
Figure 1-2 Creating an executable program
– Might need to recompile the code several times

Programming Logic & Design, Sixth Edition 13 Programming Logic & Design, Sixth Edition 14

Testing the Program Putting the Program into Production

• Logical error • Process depends on program’s purpose


– Use a syntactically correct statement but use the – May take several months
wrong one for the current context • Conversion
• Test – Entire set of actions an organization must take to
– Execute the program with some sample data to see switch over to using a new program or set of
whether the results are logically correct programs
• Programs should be tested with many sets of data

Programming Logic & Design, Sixth Edition 15 Programming Logic & Design, Sixth Edition 16

Using Pseudocode Statements


Maintaining the Program
and Flowchart Symbols
• Maintenance • Pseudocode
– Making changes after program is put into production – English-like representation of the logical steps it
• Common first programming job takes to solve a problem
– Maintaining previously written programs • Flowchart
• Make changes to existing programs – Pictorial representation of the logical steps it takes to
solve a problem
– Repeat the development cycle

Programming Logic & Design, Sixth Edition 17 Programming Logic & Design, Sixth Edition 18

3
Writing Pseudocode Writing Pseudocode (continued)

• Pseudocode representation of a number-doubling • Programmers preface their pseudocode with a


problem beginning statement like start and end it with a
start terminating statement like stop
input myNumber • Flexible because it is a planning tool
set myAnswer = myNumber * 2
output myAnswer
stop

Programming Logic & Design, Sixth Edition 19 Programming Logic & Design, Sixth Edition 20

Drawing Flowcharts Drawing Flowcharts (continued)

• Create a flowchart • Output symbol


– Draw geometric shapes that contain the individual – Represents output statements
statements – Parallelogram
– Connect shapes with arrows • Flowlines
• Input symbol – Arrows that connect steps
– Indicates input operation • Terminal symbols
– Parallelogram – Start/stop symbols
• Processing symbol – Shaped like a racetrack
– Processing statements such as arithmetic – Also called lozenge
– Rectangle
Programming Logic & Design, Sixth Edition 21 Programming Logic & Design, Sixth Edition 22

Drawing Flowcharts (continued) Repeating Instructions


• After the flowchart or pseudocode has been
developed, the programmer only needs to:
– Buy a computer
– Buy a language compiler
– Learn a programming language
– Code the program
– Attempt to compile it
– Fix the syntax errors
– Compile it again
Figure 1-6 Flowchart and pseudocode of program that doubles a number
– Test it with several sets of data
– Put it into production
Programming Logic & Design, Sixth Edition 23 Programming Logic & Design, Sixth Edition 24

4
Repeating Instructions (continued) Repeating Instructions (continued)

• Loop
– Repetition of a series of steps
• Infinite loop
– Repeating flow of logic with no end

Figure 1-8 Flowchart of infinite number-doubling program

Programming Logic & Design, Sixth Edition 25 Programming Logic & Design, Sixth Edition 26

Using a Sentinel Value to End Using a Sentinel Value to End


a Program a Program (continued)
• Making a decision
– Testing a value
– Decision symbol
• Diamond shape
• Dummy value
– Data-entry value that the user will never need
– Sentinel value
• eof (“end of file”)
– Marker at the end of a file that automatically acts as Figure 1-9 Flowchart of number-doubling program with sentinel value of 0
a sentinel
Programming Logic & Design, Sixth Edition 27 Programming Logic & Design, Sixth Edition 28

Using a Sentinel Value to End Understanding Programming


a Program (continued) and User Environments
• Many options for programming and user
environments

Figure 1-10 Flowchart using eof

Programming Logic & Design, Sixth Edition 29 Programming Logic & Design, Sixth Edition 30

5
Understanding Programming Understanding Programming
Environments Environments (continued)
• Use a keyboard to type program statements into an
editor
– Plain text editor
• Similar to a word processor but without as many
features
– Text editor that is part of an integrated
development environment (IDE)
• Software package that provides an editor, compiler,
and other programming tools

Figure 1-12 A C# number-doubling program in Visual Studio

Programming Logic & Design, Sixth Edition 31 Programming Logic & Design, Sixth Edition 32

Understanding User Environments


Understanding User Environments
(continued)
• Command line
– Location on your computer screen at which you type
text entries to communicate with the computer’s
operating system
• Graphical user interface (GUI)
– Allows users to interact with a program in a graphical
environment Figure 1-13 Executing a number-doubling program
in a command-line environment

Programming Logic & Design, Sixth Edition 33 Programming Logic & Design, Sixth Edition 34

Understanding User Environments Understanding the Evolution


(continued) of Programming Models
• People have been writing modern computer
programs since the 1940s
• Newer programming languages
– Look much more like natural language
– Easier to use
– Create self-contained modules or program segments
Figure 1-14 Executing a number-doubling program in a GUI environment that can be pieced together in a variety of ways

Programming Logic & Design, Sixth Edition 35 Programming Logic & Design, Sixth Edition 36

6
Understanding the Evolution
Summary
of Programming Models (continued)
• Major models or paradigms used by programmers • Computer programming
– Procedural programming – Requires specific syntax
• Focuses on the procedures that programmers create – Must develop correct logic
– Object-oriented programming • Programmer’s job
• Focuses on objects, or “things,” and describes their – Understanding the problem, planning the logic,
features (or attributes) and their behaviors coding the program, translating the program into
– Major difference machine language, testing the program, putting the
• Focus the programmer takes during the earliest program into production, and maintaining it
planning stages of a project
• Procedural and object-oriented programmers
approach problems differently

Programming Logic & Design, Sixth Edition 37 Programming Logic & Design, Sixth Edition 38

Potrebbero piacerti anche