1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- #include <iostream>
- #include <cmath>
- 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()
- {
- using namespace std;
- 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 numbers (q to quit): ";
- }
- cout << "Done.\n";
- return 0;
- }
- polar rect_to_polar(rect xypos)
- {
- using namespace std;
- polar answer;
- answer.distance =
- sqrt( xypos.x * xypos.x + xypos.y * xypos.y);
- answer.angle = atan2(xypos.y, xypos.x);
- return answer;
- }
- void show_polar (polar dapos)
- {
- using namespace std;
- const double Rad_to_deg = 57.29577951;
- cout << "distance = " << dapos.distance;
- cout << ", angle = " << dapos.angle * Rad_to_deg;
- cout << " degrees\n";
- }
|