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

  1. // ex07001.cpp
  2. // The Cube class
  3. #include <iostream.h>
  4.  
  5. // ------------ a Cube class
  6. class Cube    {
  7. private:
  8.     int height, width, depth;    // private data members
  9. public:
  10.     Cube(int, int, int); // constructor function
  11.     ~Cube();             // destructor function
  12.     int volume(void);     // member function (compute volume)
  13. };
  14. // ---------- the constructor function
  15. Cube::Cube(int ht, int wd, int dp)
  16. {
  17.     height = ht;
  18.     width = wd;
  19.     depth = dp;
  20. }
  21. // ---------- the destructor function
  22. Cube::~Cube()
  23. {    
  24.     // does nothing   
  25. }
  26. // -------- member function to compute the Cube's volume
  27. int Cube::volume()
  28. {
  29.     return height * width * depth;
  30. }
  31.  
  32. // ========== an application to use the cube
  33. main()
  34. {
  35.     Cube thiscube(7, 8, 9);        // declare a Cube
  36.     cout << thiscube.volume();    // compute & display volume
  37. }
  38.