-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrctfun.cpp
More file actions
50 lines (43 loc) · 1.15 KB
/
strctfun.cpp
File metadata and controls
50 lines (43 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include <cmath>
struct polar
{
double distance;
double angle;
};
struct rect
{
double x;
double y;
};
void rect_to_polar(rect *re, polar *p);
void show_polar(polar *p);
void show_polar_po(polar *pp);
int main(int argc, char const *argv[])
{
rect rplace;
polar pplace;
std::cout << "Enter the x and y values: ";
while (std::cin >> rplace.x >> rplace.y) // 此时 cin 判断的标准输入的字符类型是否可以被转化为待接收的数据类型
{
rect_to_polar(&rplace, &pplace);
show_polar(&pplace);
show_polar_po(&pplace);
std::cout << "Next two numbers (q to quid): ";
}
std::cout << "Done.\n";
return 0;
}
void rect_to_polar(rect *rplace, polar *pp)
{
pp->distance = sqrt(rplace->x * rplace->x + rplace->y * rplace->y);
pp->angle = atan2(rplace->y, rplace->y);
}
void show_polar(polar *pplace)
{
std::cout << "distance = " << pplace->distance << " , angle = " << pplace->angle * 57 << " degrees\n";
}
void show_polar_po(polar *pp)
{
std::cout << "cout_by_point >>> distance = " << pp->distance << " , angle = " << pp->angle * 57 << " degrees\n";
}