1- #include < vector> // provides STL vector
2- #include " CreditCard.h" // provides CreditCard, cout, string
3-
4- using namespace std ; // make std accessible
5-
6- void testCard () { // CreditCard test function
7- vector<CreditCard*> wallet (10 ); // vector of 10 CreditCard pointers
8-
9- // allocate 3 new cards
10- wallet[0 ] = new CreditCard (" 5391 0375 9387 5309" , " John Bowman" , 2500 );
11- wallet[1 ] = new CreditCard (" 3485 0399 3395 1954" , " John Bowman" , 3500 );
12- wallet[2 ] = new CreditCard (" 6011 4902 3294 2994" , " John Bowman" , 5000 );
13-
14- for (int j=1 ; j <= 16 ; j++) { // make some charges
15- wallet[0 ]->chargeIt (double (j)); // explicitly cast to double
16- wallet[1 ]->chargeIt (2 * j); // implicitly cast to double
17- wallet[2 ]->chargeIt (double (3 * j));
18- }
19-
20- cout << " Card payments:\n " ;
21- for (int i=0 ; i < 3 ; i++){ // make more charges
22- cout << *wallet[i];
23- while (wallet[i]->getBalance () > 100.0 ) {
24- wallet[i]->makePayment (100.0 );
25- cout << " New balance = " << wallet[i]->getBalance () << " \n " ;
26- }
27- cout << " \n " ;
28- delete wallet[i]; // deallocate storage
29- }
1+ #include " CreditCard.h" // provides CreditCard, cout, string
2+ #include < vector> // provides STL vector
3+
4+ using namespace std ; // make std accessible
5+
6+ void testCard () { // CreditCard test function
7+ vector<CreditCard *> wallet (10 ); // vector of 10 CreditCard pointers
8+
9+ // allocate 3 new cards
10+ wallet[0 ] = new CreditCard (" 5391 0375 9387 5309" , " John Bowman" , 2500 );
11+ wallet[1 ] = new CreditCard (" 3485 0399 3395 1954" , " John Bowman" , 3500 );
12+ wallet[2 ] = new CreditCard (" 6011 4902 3294 2994" , " John Bowman" , 5000 );
13+
14+ for (int j = 1 ; j <= 16 ; j++) { // make some charges
15+ wallet[0 ]->chargeIt (double (j)); // explicitly cast to double
16+ wallet[1 ]->chargeIt (2 * j); // implicitly cast to double
17+ wallet[2 ]->chargeIt (double (3 * j));
18+ }
19+
20+ cout << " Card payments:\n " ;
21+ for (int i = 0 ; i < 3 ; i++) { // make more charges
22+ cout << *wallet[i];
23+
24+ while (wallet[i]->getBalance () > 100.0 ) {
25+ wallet[i]->makePayment (100.0 );
26+ cout << " New balance = " << wallet[i]->getBalance () << " \n " ;
27+ }
28+
29+ cout << " \n " ;
30+ delete wallet[i]; // deallocate storage
31+ }
3032}
3133
32- int main () { // main function
33- testCard ();
34- return EXIT_SUCCESS; // successful execution
35- }
34+ int main (int argc, char const *argv[]) {
35+ testCard ();
36+ return EXIT_SUCCESS; // successful execution
37+ }
0 commit comments