Chapter 1
Chapter 1
5 6
1
1/17/2011
9 10
Main Main
Program Program
11 12
2
1/17/2011
Main Main
Program Program
13 14
Main Main
Program Program
15 16
Main Main
Program Program
17 18
3
1/17/2011
The function definitions are placed into a The balance variable is declared in the
separate file called the class implementation file. private section of the class definition.
This file would be called checkbook.cpp (by
convention).
21 22
15 #include “checkbook.h”
16 21 bool Checkbook::writeCheck( float amount )
17 void Checkbook::setBalance( float amount ) 22 {
18 { 23 if ( amount > balance )
19 balance = amount; 24 return false;
20 } 25 balance -= amount;
26 lastCheck = amount;
Special notation for class function definitions 27 return true;
28 }
23 24
4
1/17/2011
end of checkbook.cpp
25 26
29 30
5
1/17/2011
• Your class may be used by hundreds or • First technique – make the classes and
even thousands of clients or drivers the main program and test everything all at
once
• Write your class for clients, not for – inefficient: takes a long time to track down
computer end-users each bug
• Do not put code in your class which gives • Second technique – test each class as it is
messages to users or asks users for made by writing a main program just to
information – let clients handle this the test it (called a test driver)
way they want
35 36
6
1/17/2011