"The best way to cheer yourself up is to try to cheer somebody else up." Mark Twain

Tuesday, March 23, 2010

Write a C++ program to implement a circle class. Each Object of this class will represent a circle, storing its radius and the x and y coordinate of its center as floats. Include two access functions for: (a) Calculate area of circle , (b) calculating the circumference of circle.


#include<iostream.h>
#include<conio.h>
// start class
class circle
{

private :

float radius;
float x , y;

public :

void get_radius(float r)
{ radius = r; }

void get_xycoor(float a, float b)
{ x = a;
y = b;
}

void area( )
{
cout<< "\n\n The area of the circle of radius "<< radius <<" is " << 3.14 * radius * radius ;
}

void circum()
{
cout<< "\n\n The circumference of the circle of radius "<< radius <<" is " << 2 *3.14 * radius ;
}
};
//End of class

void main()
{
circle c1;
float rad;
cout<< "\n Enter radius :";
cin >> rad;
c1.get_radius(rad);
c1.area();
c1.circum();
getch();
}

No comments:

Post a Comment

C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off.
Now Playing: Ballade Pour Adeline

About Me

My photo
I m an IT lecturer of a college. I love social-work. I want to do something beneficial for society before dying , that can promote our society, to some extent.