home *** CD-ROM | disk | FTP | other *** search
- /////////////////////////////
- // Program Name: Circle4.CPP
- /////////////////////////////
-
- ///////////////////
- // #include files
- ///////////////////
- #include <iostream.h>
-
- // Declare the CCircle class
- class CCircle
- {
- public:
- CCircle( int r); // Constructor
-
- void SetRadius(int r); // Overloaded
- void SetRadius(int r, int c ); // Overloaded
-
- int GetRadius(void);
- void DisplayArea(void);
- ~CCircle(); // Destructor
-
- int m_Color;
-
- private:
- float CalculateArea(void);
- int m_Radius;
- // int Color;
- };
-
-
- ///////////////////////////
- // The constructor function
- ///////////////////////////
- CCircle::CCircle ( int r )
- {
-
- // Set the radius
- m_Radius = r;
- m_Color = 0;
-
- }
-
-
- //////////////////////////
- // The destructor function
- //////////////////////////
- CCircle::~CCircle ()
- {
-
-
- }
-
-
- //////////////////////////////
- // Function Name: SetRadius()
- //////////////////////////////
- void CCircle::SetRadius ( int r)
- {
-
- m_Radius = r;
- m_Color = 255;
-
- }
-
-
- //////////////////////////////
- // Function Name: SetRadius()
- //////////////////////////////
- void CCircle::SetRadius ( int r, int c)
- {
-
- m_Radius = r;
- m_Color = c;
-
- }
-
-
- //////////////////////////////
- // Function Name: GetRadius()
- //////////////////////////////
- int CCircle::GetRadius ( void)
- {
-
- return m_Radius;
-
- }
-
- ///////////////////////////////
- // Function Name: DisplayArea()
- ///////////////////////////////
- void CCircle::DisplayArea ( void )
- {
-
- float fArea;
-
- fArea = CalculateArea ( );
-
- // Print the area
- cout << "The area of the circle is: " << fArea;
-
-
- }
-
-
- /////////////////////////////////
- // Function Name: CalculateArea()
- /////////////////////////////////
- float CCircle::CalculateArea ( void )
- {
-
- float f;
-
- f = (float) (3.14 * m_Radius * m_Radius);
-
- return f;
-
- }
-
-
-
- void main ( void)
- {
- // Create the MyCircle object with Radius equal to 10
- CCircle MyCircle (10);
-
- // Display the radius of the circle
- cout << "The Radius is: " << MyCircle.GetRadius();
- cout << "\n";
-
- // Display the color of the circle
- cout << "The Color of the circle is: " << MyCircle.m_Color;
- cout << "\n";
-
- //Set the Radius of MyCircle to 20.
- MyCircle.SetRadius (20);
-
- // Display the radius of the circle
- cout << "The Radius is: " << MyCircle.GetRadius();
- cout << "\n";
-
- // Display the color of the circle
- cout << "The Color of the circle is: " << MyCircle.m_Color;
- cout << "\n";
-
- // Use the other SetRadius() function
- MyCircle.SetRadius (40, 100);
-
- // Display the radius of the circle
- cout << "The Radius is: " << MyCircle.GetRadius();
- cout << "\n";
-
- // Display the color of the circle
- cout << "The Color of the circle is: " << MyCircle.m_Color;
-
- }
-