home *** CD-ROM | disk | FTP | other *** search
/ Master Visual C++ 1.5 / MASTERVC15.ISO / vcprog / original / ch03 / rect.cpp next >
Encoding:
C/C++ Source or Header  |  1994-02-11  |  1.1 KB  |  76 lines

  1. /////////////////////////
  2. // Program Name: Rect.CPP
  3. /////////////////////////
  4.  
  5.  
  6. ////////////
  7. // #include
  8. ////////////
  9. #include <iostream.h>
  10.  
  11.  
  12. ////////////////////////////////////
  13. // The CRectangle class declaration
  14. ////////////////////////////////////
  15. class CRectangle
  16. {
  17. public:
  18.       CRectangle(int w, int h);  // Constructor
  19.      
  20.       void DisplayArea (void);   // Member function
  21.  
  22.      ~CRectangle();              // Destructor
  23.  
  24.      int m_Width;   // Data member
  25.      int m_Height;  // Data member
  26.  
  27. };
  28.  
  29.  
  30. ////////////////////////////
  31. // The constructor function
  32. ////////////////////////////
  33. CRectangle::CRectangle( int w, int h)
  34. {
  35.  
  36. m_Width = w;
  37. m_Height = h;
  38.  
  39. }
  40.  
  41.  
  42. ////////////////////////////
  43. // The destructor function
  44. ////////////////////////////
  45. CRectangle::~CRectangle()
  46. {
  47.  
  48.  
  49.  
  50. }
  51.  
  52.  
  53. ////////////////////////////////
  54. // Function Name: DisplayArea()
  55. ////////////////////////////////
  56. void CRectangle::DisplayArea(void)
  57. {
  58.  
  59. int iArea;
  60.  
  61. iArea = m_Width * m_Height;
  62.  
  63. cout << "The area is: " << iArea << "\n";
  64.  
  65. }
  66.  
  67. void main(void)
  68. {
  69.  
  70. CRectangle MyRectangle ( 10, 5 );
  71.  
  72. MyRectangle.DisplayArea();
  73.  
  74.  
  75. }
  76.