Introduction To Programming and Object-Oriented Design
Introduction To Programming and Object-Oriented Design
Davidson
1999 McGraw-Hill, Inc.
Ch 1 / Foil 2
Computer Organization
Ch 1 / Foil 3
Computer Organization
Memory
Output
Devices
Input
Devices
CPU
Ch 1 / Foil 4
CPU
Ch 1 / Foil 5
CPU
Ch 1 / Foil 6
Binary Arithmetic
01011 = 0 2
+ 1 23 + 0 22 + 1 21 + 1 20 = 11
00010 = 0 24 + 0 23 + 0 22 + 1 21 + 0 20 =
Binary
addition
00010
+ 01011
01101
2
+ 11
13
Equivalent
decimal
addition
Ch 1 / Foil 7
Binary Arithmetic
Binary
multiplication
0101
0011
0101
0101
0000
0000
0001111
Equivalent decimal
multiplication
5
3
15
Ch 1 / Foil 8
Twos Complement
Ch 1 / Foil 9
Ch 1 / Foil 10
= 1
Ch 1 / Foil 11
Control Unit
Increment the PC
Ch 1 / Foil 12
Ch 1 / Foil 13
Monitor
Display device
Also known as CRT (cathode ray tube)
Operates like a television
Controlled by an output device called a graphics card
Ch 1 / Foil 14
Refresh rate
1280
1024
pixels
How fast image is
pixels
across
updated on the screen
down
screen
screen
Resolution
Displayable area
Measured in dots per inch, dots
are often referred to as pixels (short for picture element)
Standard resolution is 640 by 480
Some cards support resolution up to 1280 by 1024
Number of colors supported
Ch 1 / Foil 15
Software
Application software
Programs designed to perform specific tasks that are
transparent to the user
System software
Programs that support the execution and development of
other programs
Two major types
Operating systems
Translation systems
Ch 1 / Foil 16
Application Software
Ch 1 / Foil 17
Operating System
Ch 1 / Foil 18
Translation System
Ch 1 / Foil 19
Software Development
Major activities
Editing
Compiling
Linking with precompiled files
Object files
Library modules
Loading and executing
Viewing the behavior of the program
Ch 1 / Foil 20
Compile
Library routines
Edit
Link
Other object files
Think
Load
Execute
Ch 1 / Foil 21
IDEs
Ch 1 / Foil 22
Engineering Software
Software engineering
Area of computer science concerned with building large
software systems
Challenge
Tremendous advances in hardware have not been
accompanied by comparable advances in software
Ch 1 / Foil 23
Complexity Trade-off
Ch 1 / Foil 24
Reliability
An unreliable life-critical system can be fatal
Understandability
Future development becomes very difficult if software is hard
to understand
Cost Effectiveness
Cost to develop and maintain should not exceed profit
Adaptability
System that is adaptive is easier to alter and expand
Reusability
Improves reliability and maintainability, and reduces
development costs
Ch 1 / Foil 25
Abstraction
Extract the relevant properties of an object while ignoring
inessential details
Encapsulation
Breaking down an object into parts, hiding and protecting its
essential information, and supplying an interface to modify
the information in a controlled and useful manner
Modularity
Dividing an object into smaller pieces or modules such that
the object is easier to understand and manipulate
Hierarchy
Ranking or ordering of objects based on some relationship
between them
Ch 1 / Foil 26
Abstraction
Oil change?
Ch 1 / Foil 27
Encapsulation
Ch 1 / Foil 28
Modularity
Ch 1 / Foil 29
Hierarchy
Ch 1 / Foil 30
Ch 1 / Foil 31
Ch 1 / Foil 32
Objects
Ch 1 / Foil 33
Object-Oriented Programming
Example
Sketch the design of a simple computer game called Bug
Hunt
Goal of game is to eliminate the bugs on the screen
Features of game
A moving bug is displayed in a window on the screen
The bug changes directions randomly
A bug is eliminated by swatting it several times
If a bug is eliminated, a faster one pops up
If an attempted swat misses the bug, the game ends
Ch 1 / Foil 34
Object-Oriented Programming
First step
Determine the objects
Mouse
Window
Bug
Ch 1 / Foil 35
Bug Hunt
Other possible
directions
Current
direction
Ch 1 / Foil 36
Bug Hunt
Yes or No
Response
Is Pointed
At?
Game
Controller
MouseClick
Mouse
Ch 1 / Foil 37
Bug Instantiation
DrawBug
Position
Image
Speed
Direction
Strength
Position: 9,2.2
Image:
Speed: 4
Direction: Left
Strength: 4
Set Direction
Hit
Kill
Is pointed at
Position: 5,3.8
Image:
Speed: 2
Direction: Right
Strength: 2
The bug
class
Bug objects
with
particular
properties
Ch 1 / Foil 38
Inheritance
Bug
Properties
Messages
Properties
inherited by
descendants
Position
Draw
Image
SetDirection
Velocity
Hit
Strength
Kill
Direction
IsPointed At
is a
SlowBug
Messages
Move
Messages
inherited by
descendants
is a
FastBug
Messages
Move