// File: main3.C // Use the Box class. #include #include "box1.h" main() { Box boxes[4] ; // array of 4 boxes Box *bptr ; int i, items ; cout << "Automatically allocated array of boxes:\n" ; for (i = 0 ; i < 4 ; i++) { cout << "boxes[" << i << "]: " ; boxes[i].identify() ; } cout << "\nA dynamically allocated box\n" ; bptr = new Box ; // same as malloc(sizeof(Box)) (*bptr).identify() ; bptr->identify() ; delete bptr ; // same as free(bptr) cout << "\nDynamically allocated array of boxes:\n" ; items = 7 ; bptr = new Box[items] ; // same as malloc(items * sizeof(Box)) for (i = 0 ; i < items ; i++) { cout << "bptr[" << i << "]: " ; bptr[i].identify() ; } delete [] bptr ; // same as free(bptr) }