//座标的两种表标方法的转换 #include<iostream> #include<cmath> struct polar { double distance; double angle; }; struct rect { double x; double y; }; polar rectToPolar(rect xypos); void showPolar(polar dapos); int main() { using namespace std; rect rplace; polar pplace; cout << "Enter the x and y value : "; while(cin >> rplace.x >> rplace.y) { pplace = rectToPolar( rplace ); showPolar( pplace ); cout << "Next two numbers(q to quit): "; } cout << "-DONE-" << endl; return 0; } polar rectToPolar(rect xy) { using namespace std; polar answer; answer.distance = sqrt(xy.x*xy.x+xy.y*xy.y); answer.angle = atan2(xy.y, xy.x); return answer; } void showPolar(polar dapos) { using namespace std; const double red_to_deg = 57.29577951; cout << "distance = " << dapos.distance << ". angle = " << dapos.angle * red_to_deg <<" degrees/n"; }