home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 13 / CDA13.ISO / cdactual / demobin / share / program / C / ANSICPP.ZIP / EX07003.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-24  |  643 b   |  24 lines

  1. // ex07003.cpp
  2. // Constructor with default parameters
  3. #include <iostream.h>
  4.  
  5. // ------------ a Cube class
  6. class Cube    {
  7.     int height, width, depth;     // private data members
  8. public:
  9.      // ----- constructor function with default initializers
  10.     Cube(int ht = 1, int wd = 2, int dp = 3)
  11.         { height = ht; width = wd; depth = dp; }
  12.     // ----- member function
  13.     int volume() { return height * width * depth; }
  14. };
  15.  
  16. main()
  17. {
  18.     Cube thiscube(7, 8, 9);         // declare a Cube
  19.     Cube defaultcube;             // no initializers
  20.     cout << thiscube.volume();     // volume of the Cube
  21.     cout << '\n';
  22.     cout << defaultcube.volume();// volume of the default
  23. }
  24.