home *** CD-ROM | disk | FTP | other *** search
- // ex07003.cpp
- // Constructor with default parameters
- #include <iostream.h>
-
- // ------------ a Cube class
- class Cube {
- int height, width, depth; // private data members
- public:
- // ----- constructor function with default initializers
- Cube(int ht = 1, int wd = 2, int dp = 3)
- { height = ht; width = wd; depth = dp; }
- // ----- member function
- int volume() { return height * width * depth; }
- };
-
- main()
- {
- Cube thiscube(7, 8, 9); // declare a Cube
- Cube defaultcube; // no initializers
- cout << thiscube.volume(); // volume of the Cube
- cout << '\n';
- cout << defaultcube.volume();// volume of the default
- }