【发布时间】:2017-07-17 03:06:57
【问题描述】:
我对 C++ 和一般编程还是很陌生,所以要温柔。
给定圆心和圆上的一个点,您可以使用此公式求圆的半径。编写一个程序,提示用户输入圆心和圆上的一个点。然后程序应该输出圆的半径、直径、周长和面积。您的程序必须至少具有以下功能:
calculateRadius:接收圆心和点的 x-y 坐标(由用户输入)并计算点之间的距离。该值作为圆的半径返回。
calculateArea:接收圆的半径,计算并返回圆的面积。
calculatePerimeter:接收圆的半径,计算并返回圆的周长。
输出应该清楚地显示结果圆的半径、面积和周长。
这是我目前所拥有的,它给了我数字和字母作为输出。
#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;
}
【问题讨论】:
-
你的问题是什么?这是相当广泛的。
-
@Carcigenicate 当我运行代码时,我得到了数字和字母,这显然是错误的。我不知道我做错了什么。所以我的问题是,是否有人能找到我得到错误答案的原因。
-
@Jcarlton55 如果您有任何更新(如您的评论),最好用清晰的信息编辑您自己的问题。
标签: c++