-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShapes.cpp
190 lines (171 loc) · 3.25 KB
/
Shapes.cpp
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#include "pch.h"
#include <iostream>
#include <sstream>
#include <boost/math/constants/constants.hpp>
class Shape
{
public:
typedef int param_type;
public:
virtual param_type Area() const = 0;
virtual param_type Permiter() const = 0;
virtual bool ContainsPoint(param_type x, param_type y) = 0;
virtual void Move(param_type dx, param_type dy) = 0;
virtual void PrintInfo(std::ostream& out) const = 0;
virtual Shape* Clone() const = 0;
virtual ~Shape()
{
}
};
class Rectangle :public Shape
{
public:
Rectangle(param_type l, param_type r,param_type t,param_type b) :left_(l), right_(r),top_(t),bottom_(b)
{
}
~Rectangle()
{
}
param_type Area() const override
{
return (right_ - left_) * (bottom_ - top_);
}
param_type Permiter() const override
{
return 2 * ((right_ - left_) + (bottom_ - top_));
}
void PrintInfo(std::ostream& out) const override
{
out << "Rectange at topleft (" << left_ << "," << top_ << ")\n";
}
bool ContainsPoint(param_type x, param_type y) override
{
return x >= left_ && x <= right_ && y >= top_ && y <= bottom_;
}
void Move(param_type dx, param_type dy) override
{
left_ += dx;
right_ += dx;
top_ += dy;
bottom_ += dy;
}
Rectangle* Clone() const
{
return new Rectangle(*this);
}
private:
param_type top_;
param_type bottom_;
param_type left_;
param_type right_;
};
class Circle :public Shape
{
public:
Circle(param_type x, param_type y, param_type r) :x_(x), y_(y), radius_(r)
{
}
~Circle()
{
}
param_type Area() const override
{
return boost::math::constants::pi<double>() * radius_ * radius_;
}
param_type Permiter() const override
{
return 2 * boost::math::constants::pi<double>() * radius_;
}
void PrintInfo(std::ostream& out) const
{
out << "Circle at (" << x_ << "," << y_ << ") with radius " << radius_ << "\n";
}
bool ContainsPoint(param_type x, param_type y) override
{
const double dx = x - x_;
const double dy = y - y_;
return dx * dx + dy * dy <= radius_ * radius_;
}
void Move(param_type dx, param_type dy) override
{
x_ += dx;
y_ += dy;
}
Circle* Clone() const
{
return new Circle(*this);
}
private:
param_type x_;
param_type y_;
param_type radius_;
};
class Trinagle :public Shape
{
public:
param_type Area() const override
{
return 0;
}
~Trinagle()
{
}
param_type Permiter() const override
{
return 0;
}
void PrintInfo() const
{
}
bool ContainsPoint(param_type x, param_type y) override
{
return false;
}
private:
param_type x1_;
param_type y1_;
param_type x2_;
param_type y2_;
param_type x2_;
param_type y2_;
};
class Process
{
public:
Process() :selected_shape(nullptr)
{
}
void ProcessCommand(std::istream& in)
{
std::string keyword;
std::cin >> keyword;
if (keyword == "Add")
{
}
else if (keyword == "Select")
{
}
else if (keyword == "Move")
{
}
else if (keyword == "Print")
{
}
else if (keyword == "Clone")
{
}
else
{
throw std::invalid_argument("Unknown Command");
}
}
void ProcessAddShape(std::istream& in)
{
}
private:
std::vector<Shape*> shapes;
Shape* selected_shape;
};
int main()
{
}