>2.5 Write a program to represent a Circle to calculate area and perimeter
>
/*Write a program to represent a Circle. Include member functions to perform the following task:
a. Calculate area of the circle
b. Calculate perimeter of the circle
Programmed by:
Name: Jitendra Kr Yadav
Roll: 10116 (NCIT-ELX)
Date: 23 july 2011*/
#include <iostream.h>
#include <conio.h>
class Circle
{
private:
float r;
public:
void assign(float a)
{
r=a;
}
void area()
{
cout<<“Area of the circle is: “<<3.14*r*r<<endl;
}
void peri()
{
cout<<“The perimeter of circle is: “<<2*3.14*r;
}
};
int main()
{
Circle c;
float a;
cout<<“Enter the radius of a circle:”;
cin>>a;
c.assign(a);
c.area();
c.peri();
getch();
return(0);
}
Output sample:
Enter the radius of a circle: 2.24
Area of the circle is: 15.7553
The perimeter of circle is: 14.0672