50% found this document useful (2 votes)
6K views

Circle Class Implementation in C++

The document describes implementing a Circle class in C++. The Circle class stores the radius, x coordinate of the center, and y coordinate of the center of a circle as private data members. It includes a default constructor, getter and setter methods to obtain circle data from the user and display it, and methods to calculate the area and circumference of the circle based on the radius. An object of the Circle class is created in the main function, and the getter, calculation, and setter methods are called on it to get the circle data, compute the area and circumference, and output the results.

Uploaded by

vinod_3466
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
50% found this document useful (2 votes)
6K views

Circle Class Implementation in C++

The document describes implementing a Circle class in C++. The Circle class stores the radius, x coordinate of the center, and y coordinate of the center of a circle as private data members. It includes a default constructor, getter and setter methods to obtain circle data from the user and display it, and methods to calculate the area and circumference of the circle based on the radius. An object of the Circle class is created in the main function, and the getter, calculation, and setter methods are called on it to get the circle data, compute the area and circumference, and output the results.

Uploaded by

vinod_3466
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

CIRCLE CLASS

Implement a Circle class in C++. Each object of this class will represent a circle,
storing its radius and the x and y co-ordinates of its centre as floats. Include a
default constructor, access functions, an area() function and a circumference()
function. The program must print the co-ordinates of the centre with radius, area
and circumference of the circle.

Theory:
This program uses the concept of class in C++. A class binds the data and its related functions
together. In the following class declaration, the data members r, area, cir, x, y are private
member functions.

class Circle
{
private:
int r; //Data Members
float area, cir, x, y;
public:
Circle(); // Constructor
void getdata (void); // Methods
void putdata (void);
void calarea (void);
void calcir (void);
};

Thus, data and the function are hidden, i.e. not visible to outside functions.
In the main() function, we have declared an object c of class Circle. The components of this
object are x, y, r, area and cir.
The constructor function Circle() is used to initialize the object.

CODE:
// Author :
// Purpose: To implement a class Circle
#include <iostream.h>
#include <conio.h>
#define PI 3.142
class Circle
{
private:
int r; //Data Members
float area, cir, x, y;
public:
Circle(); // Constructor
void getdata (void); // Methods
void putdata (void);
void calarea (void);
void calcir (void);
};
// Function Definitions
Circle :: Circle() // Constructor function
{
r = 0;
area = 0.0;
cir = 0.0;
x = 0.0;
y = 0.0;
}
Hiddencomputertricks.blogspot.com
void Circle :: getdata(void)
{
cout << "Please enter the radius of the circle ";
cin >> r;
cout << "Please enter the x co-ordinate of the center ";
cin >> x;
cout << "Please enter the y co-ordinate of the center ";
cin >> y;
}
void Circle :: putdata(void)
{
cout << endl;
cout << "Radius of the circle is : " << r << endl;
cout << "The x-cordinate of the circle is : " << x << endl;
cout << "The y-cordinate of the circle is : " << y << endl;
cout << "Area of the circle is : " << area << endl;
cout << "Circumference of the circle is : " << cir << endl;
}
void Circle :: calarea(void)
{
area = PI * r * r;
}
void Circle :: calcir(void)
{
cir = 2 * PI * r;
}

main()
{
Circle c; // c is an object of class Circle
clrscr();
cout << " \t\t * TO IMPLEMENT A CLASS CIRCLE * \t\t " << endl;
c.getdata();
c.calarea();
c.calcir();
c.putdata();
getch();
return 0;
}
// End of the Program

Hiddencomputertricks.blogspot.com

You might also like