-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfactory_method.cpp
More file actions
64 lines (53 loc) · 937 Bytes
/
factory_method.cpp
File metadata and controls
64 lines (53 loc) · 937 Bytes
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
enum class PointType
{
cartesian,
polar
};
class Point
{
/*Point(float a, float b, PointType type = PointType::cartesian)
{
if (type == PointType::cartesian)
{
x = a; b = y;
}
else
{
x = a*cos(b);
y = a*sin(b);
}
}*/
Point(const float x, const float y)
: x{x},
y{y}
{
}
public:
float x, y;
friend std::ostream& operator<<(std::ostream& os, const Point& obj)
{
return os
<< "x: " << obj.x
<< " y: " << obj.y;
}
static Point NewCartesian(float x, float y)
{
return{ x,y };
}
static Point NewPolar(float r, float theta)
{
return{ r*cos(theta), r*sin(theta) };
}
};
int main_z()
{
// will not work
//Point p{ 1,2 };
auto p = Point::NewPolar(5, M_PI_4);
std::cout << p << std::endl;
getchar();
return 0;
}