-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLineAndCircleClass.cpp
More file actions
318 lines (260 loc) · 6.27 KB
/
LineAndCircleClass.cpp
File metadata and controls
318 lines (260 loc) · 6.27 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
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
//////////////////////////////////////// Point Class /////////////////////////////////////
#ifndef POINT_H /////////////// http://www.cplusplus.com/forum/general/124555/
#define POINT_H
#include <iostream>
using namespace std;
class Point
{
public:
//Default constructor
Point();
Point(double new_x, double new_y);
/*******Member Fucntions*******/
//Accessors
double GetX();
double GetY();
//Mutators
void SetX(double x);
void SetY(double Y);
private:
double xCOORD, yCOORD;
};
ostream& operator<<(ostream& os, const Point& dt);
#endif // POINT_H
////////////////////////////////////// Line Class ////////////////////////////////////
#ifndef LINE_H
#define LINE_H
#include <iostream>
#include <sstream>
#include <string>
//#include "point.h"
using namespace std;
class Line
{
public:
Line();
Line(Point P1, Point P2);
Line(const Line& Obj);
double GetA();
double GetB();
string ToString();
private:
Point p1, p2;
double A,B;
};
ostream& operator<<(ostream& os, const Line& dt);
#endif // LINE_H
//////////////////////////////////// Circle Class ///////////////////////////////////////
#ifndef CIRCLE_H
#define CIRCLE_H
#include <iostream>
#include <sstream>
#include <string>
//#include "point.h"
using namespace std;
class Circle
{
public:
Circle();
Circle(Point P1, Point P2);
double GetXC();
double GetYC();
//CenterPoint();
double Radius();
// Diameter();
//Area();
//Circumference();
string ToString(Point P1, double radius);
private:
Point Center_P, Edge_P;
double Center_x, Center_y, Edge_x, Edge_y;
double m_radius;
};
#endif // CIRCLE_H
///////////////////////////////////// Circle.cpp //////////////////////////////////////////
//#include "line.h"
//#include "point.h"
#include <iostream>
#include <string>
#include <sstream>
#include <cmath>
//using namespace std;
//Default constructor
Circle::Circle():Center_x(0),Center_y(0), m_radius(0)
{
//left blank intentionally
}
Circle::Circle(Point P1, Point P2)
{
Center_P = P1;
Edge_P = P2;
//double x1,x2,y1,y2;
Center_x = P1.GetX();
Edge_x = P2.GetX();
Center_y = P1.GetY();
Edge_y = P2.GetY();
/*
//derived from slope(m) intercept(b) form
double dx,dy;
dx = Edge_x - Center_x;
dy = Edge_y - Center_y;
m_radius = std::sqrt(pow(dx,2) + pow(dy,2));
*/
double area, circom, diam;
area = M_PI*pow(m_radius,2);
circom = 2 * M_PI * m_radius;
diam = 2 * m_radius;
cout << Center_x << "," << Center_y << ", Radius "<< m_radius << ", Area " <<
area << ", Circ " << circom << ", Diam: "<< diam << endl;
}
double Circle::Radius()
{
//derived from slope(m) intercept(b) form
double dx,dy;
dx = Edge_x - Center_x;
dy = Edge_y - Center_y;
m_radius = std::sqrt(pow(dx,2) + pow(dy,2));
cout << m_radius;
return m_radius;
}
//ACCESSORS
double Circle::GetXC()
{
return Center_x;
}
double Circle::GetYC()
{
return Center_y;
}
/*
std::string Circle::ToString(Circle Center_P, Edge_P)
{
std::string out_string;
std:stringstream buffer;
buffer << "Resulting Circle: " << "Radius = " << m_radius << "x coord = " << endl;
out_string = buffer.str();
cout << out_string;
return out_string;
} */
//////////////////////////////////// Line.cpp File /////////////////////////////////////////
//#include "line.h"
//#include "point.h"
#include <iostream>
#include <string>
#include <sstream>
#include <cmath>
//using namespace std;
//Default constructor
Line::Line():A(0),B(0)
{
//left blank intentionally
}
//Point1_Object & Point2_Object were suppose to get
//Passed into here
Line::Line(Point P1, Point P2)
{
p1 = P1;
p2 = P2;
double x1,x2,y1,y2;
x1 = P1.GetX();
x2 = P2.GetX();
y1 = P1.GetY();
y2 = P2.GetY();
//derived from slope(m) intercept(b) form
double m,b;
m = (y2 - y1)/(x2-x1);
b = y1 - m*x1;
//B = -1/b;
//A = -B*m;
A = m;
B = b;
cout << "Constructor with start and end point called" << endl;
}
Line::Line(const Line& Obj)
{
cout << " Copy Constructor called" << endl;
}
//ACCESSORS
double Line::GetA()
{
return A;
}
double Line::GetB()
{
return B;
}
std::string Line::ToString()
{
std::string out_string;
std:stringstream buffer;
buffer << "Resulting line: " << "y = " << A << "x" << " + " << B << endl;
out_string = buffer.str();
cout << out_string;
return out_string;
}
ostream& operator<<(ostream& os, const Line& dt)
{
//os << dt.ToString() << endl;
return os;
}
//////////////////////////////////////// Point.cpp ///////////////////////////////////////////
//#include "point.h"
//#include <iostream>
using namespace std;
//INITIALIZES
Point::Point():xCOORD(0), yCOORD(0)
{
//default constructor
//does nothing
}
//Constructor acts as a mutator
//to get values
Point::Point(double new_x, double new_y)
{
xCOORD = new_x;
yCOORD = new_y;
}
//MUTATOR FUNCTIONS
void Point::SetX(double x)
{
xCOORD = x;
}
void Point::SetY(double y)
{
yCOORD = y;
}
ostream& operator<<(ostream& os, const Point& dt)
{
//os << dt.GetX() << '/' << dt.GetY() << '/' << endl;
return os;
}
//ACCESSOR FUNCTIONS
double Point::GetX()
{ return xCOORD; }
double Point::GetY()
{ return yCOORD; }
////////////////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <sstream>
#include <string>
//#include "point.h"
//#include "line.h"
using namespace std;
int main()
{
Point Point1_Object(5,5);
cout << "Point1 (x,y) is: (" << Point1_Object.GetX() << "," << Point1_Object.GetY() << ")" << endl;
cout<<endl;
Point Point2_Object(6,4);
cout<<"Point2 (x,y) is: (" << Point2_Object.GetX() << "," << Point2_Object.GetY() << ")" << endl;
cout<<endl;
Line THE_Line(Point1_Object, Point2_Object);
//cout<< "Resulting line: " << "y = " << THE_Line.GetA() << "x" << " + " << THE_Line.GetB() << endl;
THE_Line.ToString();
//double radius = 5;
Circle THE_Circle(Point1_Object, Point2_Object);
//THE_Circle.ToString(THE_Circle.GetXC(),, );
cout << endl << endl << endl << "END!!!" << endl;
return 0;
}
//Edit & Run