类的初步知识(C++中直角坐标和极坐标之间的转换代码)

没有分拆成几个文件之前,这是一个完整的程序,下面要对其经行分拆。

#include

#include
using namespace std;
struct polar
{
double distance;
double angle;
};
struct rect
{#
double x;
double y;
};
polar rect_to_polar(rect xypos);
void show_polar(polar dapos);
int main()
{
rect rplace;
polar pplace;
cout << " Enter the x and y values: ";
while (cin >> rplace.x>>rplace.y)
{
pplace = rect_to_polar(rplace);
show_polar(pplace);
cout << "Next two number (q to quit):";


}
cout << "Done!\n";
return 0;
}
polar rect_to_polar(rect xypos)
{
polar answer;
answer.distance =
sqrt(xypos.x*xypos.x + xypos.y*xypos.y);
answer.angle =
atan(xypos.y / xypos.x);
return answer;


}
void show_polar(polar dapos)
{
const double Rad_to_deg = 57.29577951;
cout << "distance =" << dapos.distance< cout << "angle =" << dapos.angle*Rad_to_deg;
cout << " degrees\n";
}

你可能感兴趣的:(C++)