file2.cpp 739 B

123456789101112131415161718192021222324252627
  1. // file2.cpp -- contains functions called in file1.cpp
  2. #include <iostream>
  3. #include <cmath>
  4. #include "coordin.h" // structure templates, function prototypes
  5. // convert rectangular to polar coordinates
  6. polar rect_to_polar(rect xypos)
  7. {
  8. using namespace std;
  9. polar answer;
  10. answer.distance =
  11. sqrt( xypos.x * xypos.x + xypos.y * xypos.y);
  12. answer.angle = atan2(xypos.y, xypos.x);
  13. return answer; // returns a polar structure
  14. }
  15. // show polar coordinates, converting angle to degrees
  16. void show_polar (polar dapos)
  17. {
  18. using namespace std;
  19. const double Rad_to_deg = 57.29577951;
  20. cout << "distance = " << dapos.distance;
  21. cout << ", angle = " << dapos.angle * Rad_to_deg;
  22. cout << " degrees\n";
  23. }