Vous êtes sur la page 1sur 43

About the Presentations

The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning of each presentation. You may customize the presentations to fit your class needs. Some figures from the chapters are included. A complete set of images from the book can be found on the Instructor Resources disc.

An Object-Oriented Approach to Programming Logic and Design Third Edition


Chapter 1 An Overview of Computer Programming

Objectives
In this chapter, you will learn about: Computer components and operations Simple program logic The evolution of programming techniques The steps involved in the programming process Pseudocode and flowcharts Program comments Programming and user environments

An Object-Oriented Approach to Programming Logic and Design

Understanding Computer Components and Operations


Two major computer system components
Hardware
Physical devices associated with the computer

Software
Programs (sets of instructions) written by programmers Application software: applied to a task (word processing, spreadsheets, payroll, etc.) System software: manages computer resources

An Object-Oriented Approach to Programming Logic and Design

Understanding Computer Components and Operations (contd.)


Three major hardware and software operations
Input Processing Output

Input operation
A means for data to enter computer through an input device
Mouse Keyboard

An Object-Oriented Approach to Programming Logic and Design

Understanding Computer Components and Operations (contd.)


Processing data operation
Organizing Checking for accuracy Performing mathematical operations Tasks occur in central processing unit (CPU)

An Object-Oriented Approach to Programming Logic and Design

Understanding Computer Components and Operations (contd.)


Output operation
A means to view, print, interpret, store data using output devices
Printer Monitor Storage devices (disks, flash media)

An Object-Oriented Approach to Programming Logic and Design

Understanding Computer Components and Operations (contd.)


Programming language
Instructions controlling data manipulation Examples include Visual Basic, C#, C++, or Java Rules governing word usage and punctuation are called syntax

Computer memory
Temporary, internal storage (RAM)

An Object-Oriented Approach to Programming Logic and Design

Understanding Computer Components and Operations (contd.)


Computer program execution
High level (English-like) programming language statements are translated to low-level (machine, or binary language) A compiler or interpreter is software used for the translation Compiler or interpreter points out syntax errors

An Object-Oriented Approach to Programming Logic and Design

Understanding Computer Components and Operations (contd.)


Compilers
Translate entire program before execution

Interpreters
Each instruction is translated just prior to execution Scripting languages such as Python, Lua, Perl, and PHP use interpreters

An Object-Oriented Approach to Programming Logic and Design

10

Understanding Simple Program Logic


Logic
A programs set of instructions Specific sequence is important Dont leave out or add extraneous instructions Example: logic errors in cake-making instructions
Stir Add two eggs Add a gallon of gasoline Bake at 350 degrees for 45 minutes Add three cups of flour
An Object-Oriented Approach to Programming Logic and Design 11

Understanding Simple Program Logic (contd.)


Example: program instructions written in English-like language
Three operations (input, processing, output)
input myNumber myAnswer = myNumber * 2 output myAnswer

Instructions are independent of type of input device, computer hardware, and output device

An Object-Oriented Approach to Programming Logic and Design

12

Understanding the Evolution of Programming Techniques


Modern computer programs
Around since 1940s

Oldest programming languages


Programmers worked with memory addresses Memorized awkward codes associated with machine languages Written as one piece

An Object-Oriented Approach to Programming Logic and Design

13

Understanding the Evolution of Programming Techniques (contd.)


Newer programming languages
Look like natural language Easier to use Reasons for ease of use
Use meaningful names for memory locations No awkward machine language codes Allow creation of self-contained modules or program segments Can be pieced together

An Object-Oriented Approach to Programming Logic and Design

14

Understanding the Evolution of Programming Techniques (contd.)


Program development techniques
Procedural programming
Focuses on actions that are carried out Breaks down process into manageable subtasks

Object-oriented programming
Focuses on objects Objects have attributes, behaviors, and states
Attributes: object feature Behaviors: what object does States: set of all values of attributes

Primary difference is focus on early planning stages


An Object-Oriented Approach to Programming Logic and Design 15

Understanding the Evolution of Programming Techniques (contd.)


Some types of object-oriented approach applications
Computer simulations
Mimic real-world activities

Graphical user interfaces (GUIs)


Users interact with program in graphical environment Natural use for object orientation

An Object-Oriented Approach to Programming Logic and Design

16

Understanding the Steps in the Programming Process


Developing programs or groups of programs (such as payroll system) involves three tasks
Analyzing the system Designing the system Writing the programs

Programmer may do all tasks or use systems analysts and/or software testers

An Object-Oriented Approach to Programming Logic and Design

17

Understanding the Steps in the Programming Process (contd.)


Types of software testing
Black box
Tester provides input and checks for valid output

White box
Tester looks at code, tests all logical paths

An Object-Oriented Approach to Programming Logic and Design

18

Analyzing the System


Programmers provide a service to users Object-oriented analysis (OOA)
Understand users needs Can be difficult and time consuming Needs often not well defined Frequently several program revisions necessary to satisfy user

An Object-Oriented Approach to Programming Logic and Design

19

Designing the System


Object-oriented design (OOD)
Designers envision the objects needed

Data modeling
Identifying objects and their relationships
Data entity types (categories) Data attributes (characteristics of entities) Relationships

An Object-Oriented Approach to Programming Logic and Design

20

Designing the System (contd.)


Examples of entity type in an ordering system
Product, customer, delivery method

Examples of attributes
Stock number, description, price

Examples of relationships
Has a, is a, creates a

An Object-Oriented Approach to Programming Logic and Design

21

Designing the System (contd.)


Class
A general category that describes entities May be reused from other programs or modified

An Object-Oriented Approach to Programming Logic and Design

22

Writing the Program


Involves several subtasks
Developing program logic Coding the program Translating the program into machine language Testing the program

An Object-Oriented Approach to Programming Logic and Design

23

Writing the Program (contd.)


Planning the logic
Heart of programming process Decide steps to include and order Planning tools
Flowcharts and pseudocode Both use English-like code

Language syntax not a concern Desk-checking


Reviewing program logic on paper

An Object-Oriented Approach to Programming Logic and Design

24

Writing the Program (contd.)


Coding the program
Writing program statements in programming language Object-oriented languages
C++, C#, Java, Visual Basic, SmallTalk, OO COBOL, Simula All create objects and establish communication between them Language chosen determines syntax

Coding usually less difficult than planning step

An Object-Oriented Approach to Programming Logic and Design

25

Writing the Program (contd.)


Using software to translate program into machine language
Many programming languages Computer knows only machine language (1s and 0s)

Compilers or interpreters
Translate English-like high-level programming into low-level machine language

An Object-Oriented Approach to Programming Logic and Design

26

Writing the Program (contd.)


Syntax error
Occurs when translator cannot translate the code Examples: misspellings, illegal grammar, or using words that dont exist Must be corrected before program can execute

An Object-Oriented Approach to Programming Logic and Design

27

Writing the Program (contd.)

Figure 1-1 Creating an executable program

An Object-Oriented Approach to Programming Logic and Design

28

Writing the Program (contd.)


Testing the program
A program that is free of syntax errors is not necessarily free of free of logical errors
Must test for logical errors

Requires entering of sample data


Select test data carefully Error discovery may require changes to program logic

An Object-Oriented Approach to Programming Logic and Design

29

Writing the Program (contd.)


After the program is written and tested
Ready for organizational use

Other related tasks


Preparing manuals Training users Converting existing data to new systems format

Conversion
Actions an organization must take to switch to new system Can take months or years to accomplish
An Object-Oriented Approach to Programming Logic and Design 30

Writing the Program (contd.)


Maintenance
Process of making required changes

Why necessary
Fixing errors: e.g., handling numbers over a certain value Updating values: e.g., new tax rate Format of input data changes: e.g., zip+4 Input data may no longer be available User wants additional functionality

An Object-Oriented Approach to Programming Logic and Design

31

Using Pseudocode and Flowcharts


Pseudocode
English-like representation of logical program steps Looks like programming language but is not

Flowchart
Pictorial representation of logical program steps

An Object-Oriented Approach to Programming Logic and Design

32

Writing Pseudocode
Example
start input myNumber myAnswer = myNumber * 2 output myAnswer stop

Starting and ending statements usually used Punctuation, syntax, and capitalization are unimportant in pseudocode

An Object-Oriented Approach to Programming Logic and Design

33

Drawing Flowcharts
Flowchart
Helps programmer visualize how statements connect Uses geometric shapes connected with arrows (flowlines)

Common flowchart symbols


Input symbols (parallelograms) Processing symbols (rectangles) Output symbols (parallelograms) Terminal symbols (lozenges flattened ovals) Decision symbols (diamonds)
34

Top-to-bottom or left-to-right flow is preferred


An Object-Oriented Approach to Programming Logic and Design

Drawing Flowcharts (contd.)

Figure 1-3 Flowchart and pseudocode of program that doubles a number if it is less than 10
An Object-Oriented Approach to Programming Logic and Design 35

Drawing Flowcharts (contd.)


Software applications with flowcharting tools
Microsoft Word Microsoft PowerPoint Visio Visual Logic

An Object-Oriented Approach to Programming Logic and Design

36

Understanding Program Comments


Nonexecuting statements for documentation Programmers write comments for themselves and others who read program Comments should include author, date, and purpose of program In C++, Java, and C#, two forward slashes are used
// This is a comment

An Object-Oriented Approach to Programming Logic and Design

37

Understanding Program Comments (contd.)


Annotation symbol is used for comments on a flowchart
Three-sided box with dashed line that connects to the step it explains

Figure 1-4 Flowchart and pseudocode with comments

An Object-Oriented Approach to Programming Logic and Design

38

Understanding Programming Environments


Flowcharts can be created by hand or using software Pseudocode written by hand or with word processor
Plain text editor
Notepad is one example Advantage is it requires little storage space

Integrated development environment (IDE)


Software package that provides text editor, compiler, and other tools

An Object-Oriented Approach to Programming Logic and Design

39

Understanding Programming Environments (contd.)


Advantages of using IDE
Uses colors to display various language components Highlights syntax errors visually Automatic statement completion Provides tools to step through program execution to find errors

Disadvantages of using IDE


Requires much more storage space than plain text editor

An Object-Oriented Approach to Programming Logic and Design

40

Understanding User Environments


User might execute program in different environments: command line, GUI
Figure 1-7 Executing a numberdoubling program in a commandline environment Figure 1-8 Executing a number-doubling program in a GUI environment

Programming process is the same regardless of user environment


An Object-Oriented Approach to Programming Logic and Design 41

Summary
Hardware and software accomplish three major operations: input, processing, and output For a program to work properly, you must develop correct logic Logical errors are more difficult to locate than syntax errors Developing a system involves analyzing the system, designing it, and writing the programs Writing programs involves planning the logic, coding the program, translating into machine language, and testing
An Object-Oriented Approach to Programming Logic and Design 42

Summary (contd.)
Flowcharts and pseudocode are tools for planning a programs logic Program comments are nonexecuting statements for documentation purposes Plain text editor or integrated development environment (IDE) can be used to type a program A programs data input can be at a command line or a graphical user interface (GUI)

An Object-Oriented Approach to Programming Logic and Design

43

Vous aimerez peut-être aussi