Skip to content

Commit

Permalink
程序清单9.1-9.3
Browse files Browse the repository at this point in the history
单独编译
  • Loading branch information
LinXin04 committed Apr 17, 2017
1 parent 525f0e4 commit 93b0519
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
19 changes: 19 additions & 0 deletions file/coordin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef COORDIN_H_
#define COORDIN_H_

struct polar
{
double distance;
double angle;
};

struct rect
{
double x;
double y;
};

polar rect_to_polar(rect xypos);
void show_polar(polar dapos);

#endif
17 changes: 17 additions & 0 deletions file/file1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <iostream>
#include "coordin.h"
using namespace std;
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 numbers (q to quit): ";
}
cout << "Bye!" << endl;
return 0;
}
18 changes: 18 additions & 0 deletions file/file2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <iostream>
#include <cmath>
#include "coordin.h"
using namespace std;
polar rect_to_polar(rect xypos)
{
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)
{
const double Rad_to_deg = 57.29577951;
cout << "distance = " << dapos.distance;
cout << ", angle = " << dapos.angle*Rad_to_deg;
cout << " degrees" << endl;
}

0 comments on commit 93b0519

Please sign in to comment.