object-oriented design
DESCRIPTION
Object-Oriented Design. A technique for developing a program in which the solution is expressed in terms of objects -- self- contained entities composed of data and operations on that data. istream cin; // Input stream variables : type istream - PowerPoint PPT PresentationTRANSCRIPT
C++ Programming: Program Design Including Data Structures, Second Edition expanded by J. Goetz, 2004
Object-Oriented DesignA technique for developing a program in which
the solution is expressed in terms of objects -- self- contained entities composed of data and operations on that data.istream cin; // Input stream variables: type istream ostream cout; // Output stream variables: type ostream
Private data
<<
setf...
Private data
>>
get...
ignore
cin cout
setw
1
C++ Programming: Program Design Including Data Structures, Second Edition expanded by J. Goetz, 2004
2
Two Programming Methodologies
Functional Object-Oriented Decomposition Design
FUNCTION
FUNCTION
FUNCTION
OBJECT
Operations
Data
OBJECT
Operations
Data
OBJECT
Operations
Data
C++ Programming: Program Design Including Data Structures, Second Edition expanded by J. Goetz, 2004
3
What is an object?
OBJECT
Operations
Data
set of functions
internal state
C++ Programming: Program Design Including Data Structures, Second Edition expanded by J. Goetz, 2004
4
An object contains data and operations
Private data:
accoutNumber
balance
OpenAccount
WriteCheck
MakeDeposit
IsOverdrawn
GetBalance
checkingAccount
C++ Programming: Program Design Including Data Structures, Second Edition expanded by J. Goetz, 2004
5
Three C++ Program Stages
other code from libraries,
etc.
other code from libraries,
etc.
written in machine language
written in machine language
written in machine language
written in machine language
written in C++
written in C++
via compiler via linker
SOURCE OBJECT EXECUTABLE
myprog.cpp myprog.obj myprog.exe
C++ Programming: Program Design Including Data Structures, Second Edition expanded by J. Goetz, 2004
6
SEQUENCE
Statement Statement Statement . . .
C++ Programming: Program Design Including Data Structures, Second Edition expanded by J. Goetz, 2004
7
SELECTION (branch)
IF Condition THEN Statement1 ELSE Statement2
Statement1 Statement
Statement2
Condition . . .
True
False
C++ Programming: Program Design Including Data Structures, Second Edition expanded by J. Goetz, 2004
8
LOOP (repetition)
Statement
Condition. . .
False
True
WHILE Condition DO Statement1
C++ Programming: Program Design Including Data Structures, Second Edition expanded by J. Goetz, 2004
9
SUBPROGRAM (function)
SUBPROGRAM1 . . .
SUBPROGRAM1 a meaningful collection of SEQUENCE, SELECTION, LOOP, SUBPROGRAM
C++ Programming: Program Design Including Data Structures, Second Edition expanded by J. Goetz, 2004
10
Computer Components
Arithmetic Logic Unit
Control Unit
Auxiliary StorageDevice
Memory Unit ( RAM & Registers )
Central Processing Unit ( CPU )
Input Device
Output Device
Peripherals
C++ Programming: Program Design Including Data Structures, Second Edition expanded by J. Goetz, 2004
11
Program With Several Functions
main function
square function
cube function
C++ Programming: Program Design Including Data Structures, Second Edition expanded by J. Goetz, 2004
12
Output StatementsSYNTAX
It converts (appends) the right-hand operand to a sequence of characters (to an output stream – an endless sequence of characters) which goes to the standard output device.
These examples yield the same output:
cout << “The answer is “ ;
cout << 3 * 4 ;
cout << “The answer is “ << 3 * 4 ;
cout << Expression << Expression . . . ;
C++ Programming: Program Design Including Data Structures, Second Edition expanded by J. Goetz, 2004
13
Output StatementsSYNTAX
It converts (appends) the right-hand operand to a sequence of characters (to an output stream – an endless sequence of characters) which goes to the standard output device.
These examples yield the same output:
cout << “The answer is “ ;
cout << 3 * 4 ;
cout << “The answer is “ << 3 * 4 ;
cout << Expression << Expression . . . ;
C++ Programming: Program Design Including Data Structures, Second Edition expanded by J. Goetz, 2004
No I/O is built into C++
• instead, a library provides input stream and output stream
Keyboard Screenexecutingprogram
istream ostream
14
C++ Programming: Program Design Including Data Structures, Second Edition expanded by J. Goetz, 2004
SYNTAX
These examples yield the same result.
cin >> length ;
cin >> width ;
cin >> length >> width ;
Input Statements
cin >> Variable >> Variable . . . ;
15
C++ Programming: Program Design Including Data Structures, Second Edition expanded by J. Goetz, 2004
No I/O is built into C++
• Instead, a library provides an output stream
Screenexecutingprogram
ostream
16
C++ Programming: Program Design Including Data Structures, Second Edition expanded by J. Goetz, 2004
17
C++ Data TypesC++ Data Types
structured
array struct union class
address
pointer reference
simple
integral enum
char short int long bool
floating
float double long double
C++ Programming: Program Design Including Data Structures, Second Edition expanded by J. Goetz, 2004
18
C++ Simple Data TypesC++ Simple Data Types
simple types
integral floating
char short int long bool enum float double long double
unsigned
C++ Programming: Program Design Including Data Structures, Second Edition expanded by J. Goetz, 2004
Integration Testing Approaches
Ensures correct overall design logic and the interfaces between modulesare correct.
Ensures individual moduleswork together correctly, beginning with the lowest level.
TOP-DOWN
Assumption: the lower levels
work correctly
BOTTOM-UP
USES: placeholder USES: a test driver to callmodule “stubs” to test the functions being tested.the order of calls. A stub may consist a single/ Effective in a group programming group trace/debug output statements environment where each programmer has
tested already own modules/functions.