-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
单独编译
- Loading branch information
Showing
3 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |