Here is the code in C++.
#include <bits/stdc++.h>
using namespace std;
// function to calculate distance between two points
double distance(int a,int b,int c,int d )
{
// return the distance between center and point
return sqrt(pow(c - a, 2) +
pow(d - b, 2) * 1.0);
}
// driver function
int main()
{
// variables to store coordinates
int x1,y1,x2,y2;
cout<<"Please Enter the center(x y) of the circle: ";
//reading center
cin>>x1>>y1;
cout<<"\nPlease Enter a point(x1 y1) on the circle:";
//reading point
cin>>x2>>y2;
// calling distance() function with 4 parameters
double rad=distance(x1,y1,x2,y2);
// calculating Radius and print
cout<<"Radius of circle is: "<<rad<<endl;
// calculating Diameter and print
cout<<"Diameter of circle is: "<<2*rad<<endl;
// calculating Circumference and print
cout<<"Circumference of circle is: "<<2*3.14*rad<<endl;
// calculating Area and print
cout<<"Area of circle is: "<<3.14*rad*rad<<endl;
return 0;
}
Explanation:
First it will read coordinates of center and point on the circle.The distancebetween center and point on circle is Radius. Call distance() function withfour parameters which are coordinates of center and point. This will return the value of Radius. Diameter is 2 times of Radius.Diameter of a circle is 2*3.14*Radius. and Area of the circle is calculate as 3.14*Radius*Radius. After finding these value print them.
Output:
Please Enter the center(x y) of the circle: 0 0
Please Enter a point(x1 y1) on the circle: 3 4
Radius of circle is: 5
Diameter of circle is: 10
Circumference of circle is: 31.4
Area of circle is: 78.5