I am still very new to C++ and programming in general, so be gentle.
Given the center and a point on the circle, you can use this formula to find the radius of the circle. Write a program that prompts the user to enter the center and a point on the circle. The program should then output the circle’s radius, diameter, circumference, and area. Your program must have at least the following functions:
calculateRadius: Receives the x-y coordinates of the center and point on the circle (as input by the user) and calculates the distance between the points. This value is returned as the radius of the circle.
calculateArea: Receives the radius of a circle, calculates and returns the area of the circle.
calculatePerimeter: Receives the radius of a circle, calculates and returns the perimeter of the circle.
The output should clearly display the radius, area, and perimeter of the resulting circle.
This is what I have so far and it is giving me numbers and letters as an output.
#include <iostream>
#include <cmath>
#define PI 3.141592
using namespace std;
int calculateRadius(float x1, float x2, float y1, float y2);
int calculateArea(float radius);
int calculatePerimeter(float radius);
int main()
{
float x1;
float x2;
float y1;
float y2;
cout << "Please enter the first X Coordinate: " << endl;
cin >> x1;
cout << "Please enter the first Y Coordinate: " << endl;
cin >> y1;
cout << "Please enter the second X Coordinate: " << endl;
cin >> x2;
cout << "Please enter the second Y Coordinate: " << endl;
cin >> y2;
cout << "The radius of the circle is: " << calculateRadius << endl;
cout << "The diameter of the circle is: " << endl;
cout << "The cirfumference of the circle is: " << calculatePerimeter << endl;
cout << "The area of the circle is: " << calculateArea << endl;
system("pause");
return 0;
}
int calculateRadius(float x1, float x2, float y1, float y2)
{
float distance;
float radius;
distance = sqrt((pow(x2 - x1, 2)) + (pow(y2 - y1, 2)));
radius = (distance / 2);
return radius;
}
int calculateArea(float radius)
{
float area;
area = PI * pow(radius, 2);
return area;
}
int calculatePerimeter(float radius)
{
float perimeter;
perimeter = 2 * PI * radius;
return perimeter;
}