Шустрый

Профиль
Группа: Участник
Сообщений: 107
Регистрация: 12.10.2007
Где: Минск
Репутация: нет Всего: нет
|
есть реализация классов и их итераторов: circle.h | Код | #ifndef CIRCLE_H #define CIRCLE_H #include "point.h"
class Circle { Point centre; double rad; public: class Circle_iter; friend class Circle_iter; Circle(); Circle(double x, double y, double rad); Circle(Point ¢re, double rad); };
#endif // CIRCLE_H
|
circle_iter.h | Код | #ifndef CIRCLE_ITER_H #define CIRCLE_ITER_H #include "circle.h"
const double pi=3.14159265; class Circle::Circle_iter { float f; const Circle& th; float step; public: Circle_iter(const Circle &t); Point next(); Point begin(); void Set_step(float ); float Get_step(); bool end(); };
#endif // CIRCLE_ITER_H
|
line.h | Код | #ifndef LINE_H #define LINE_H #include "point.h" #include <math.h> class Line { Point first, second; public: Line(); Line(Point, Point); Line(double, double, double, double); double lenght(); };
#endif // LINE_H
|
point.h | Код | #ifndef POINT_H #define POINT_H #include <iostream> using namespace std; class Point { public: double x; double y; Point(double, double); Point(); friend ostream& operator << (ostream& stream, const Point &p); bool operator==(const Point&); };
#endif // POINT_H
|
triangle.h | Код | #ifndef TRIANGLE_H #define TRIANGLE_H #include "point.h"
class Triangle { public: Point mas[3]; class Triangle_iter; friend class Triangle_iter; Triangle(); Triangle(Point f, Point s, Point t); };
#endif // TRIANGLE_H
|
triangle_iter.h | Код | #ifndef TRIANGLE_ITER_H #define TRIANGLE_ITER_H #include "triangle.h"
class Triangle_iter { const Triangle &th; Point pres; int wpair[2]; double xstep; double ystep; bool xgo; void set(); public: Triangle_iter(Triangle &); void Set_xstep(double ); void Set_ystep(double ); Point begin(); bool end(); Point next(); };
#endif // TRIANGLE_ITER_H
|
circle.cpp | Код | #include "..\include\circle.h"
Circle::Circle(): rad(0.0) {}
Circle::Circle(double xt, double yt, double radt): centre(xt, yt), rad(radt) {}
Circle::Circle(Point ¢r, double radt):centre(centr), rad(radt) {}
|
circle_iter.cpp | Код | #include "..\include\circle_iter.h" #include <math.h>
Circle::Circle_iter::Circle_iter(const Circle& t): f(0.0), th(t), step(0.1) {}
Point Circle::Circle_iter::begin() { f=-(step); return next(); }
Point Circle::Circle_iter::next() { double x1, y1; f+=step; x1=th.centre.x+th.rad*cos(f*pi); y1=th.centre.y+th.rad*sin(f*pi); return Point(x1, y1); }
bool Circle::Circle_iter::end() { return f>=2.0; }
void Circle::Circle_iter::Set_step(float l) { step=l; }
float Circle::Circle_iter::Get_step() { return step; }
|
line.cpp | Код | #include "..\include\line.h"
Line::Line():first(0.0,0.0), second(0.0,0.0) {}
Line::Line(Point k, Point d):first(k), second(d) {}
Line::Line(double x1, double y1, double x2, double y2): first(x1, y1), second(x2, y2) {}
double Line::lenght() { return sqrt(pow(second.x - first.x, 2) + pow(second.y - first.y, 2)); }
|
point.cpp | Код | #include "..\include\point.h"
Point::Point(double xz, double yz):x(xz), y(yz) {}
Point::Point():x(0.0), y(0.0) {}
ostream& operator<<(ostream& stream, const Point &p) { stream << "x: " << p.x << "\ny: " << p.y << endl; return stream; }
bool Point::operator==(const Point& p) { return (x==p.x && y==p.y); }
|
triangle.cpp | Код | #include "..\include\triangle.h"
Triangle::Triangle() {}
Triangle::Triangle(Point f, Point s, Point t) { mas[0]=f; mas[1]=s; mas[2]=t; }
|
triangle_iter.cpp | Код | #include "..\include\triangle_iter.h"
Triangle_iter::Triangle_iter(Triangle &t):th(t) { wpair[0]=0; ystep=xstep=0; wpair[1]=0; }
void Triangle_iter::Set_xstep(double k) { xstep=k; }
void Triangle_iter::Set_ystep(double k) { ystep=k; }
Point Triangle_iter::begin() { wpair[1]=1; pres=th.mas[0]; set(); return pres; }
void Triangle_iter::set() { if(wpair[0]==0 && wpair[1]==1) { wpair[0]=1; wpair[1]=2; } if(wpair[0]==1 && wpair[1]==2) { wpair[0]=2; wpair[1]=0; } if(wpair[0]==2 && wpair[1]==0) { wpair[0]=0; wpair[1]=1; } pres=th.mas[wpair[0]];
double k=th.mas[wpair[1]].x - pres.x;
if(k) { xstep=k>0 ? xstep : -(xstep); xgo=true; }
k=th.mas[wpair[1]].y - pres.y;
if(k) { ystep= (k>0)? ystep : -(ystep); xgo=false; } }
Point Triangle_iter::next() { if(pres==th.mas[wpair[1]]) set();
if(xgo) { pres.x+=xstep; pres.y=((th.mas[wpair[1]].y - pres.y)*pres.x - ((pres.x - xstep)*th.mas[wpair[1]].y + pres.y*(th.mas[wpair[1]].x)))/(th.mas[wpair[1]].x - (pres.x - xstep)); } if(!xgo) { pres.y+=ystep; pres.x=((pres.x - th.mas[wpair[1]].x)*pres.y - (pres.x*th.mas[wpair[1]].y + (pres.y - ystep)*(th.mas[wpair[1]].x)))/(pres.y - ystep - th.mas[wpair[1]].y); } return pres; }
bool Triangle_iter::end() { if(wpair[1]==0 && pres==th.mas[0]) return true; else return false; }
|
и мейн | Код | #include <iostream> #include "include\circle_iter.h" #include "include\triangle_iter.h"
using namespace std;
int main() { Circle p(0, 0, 5); Triangle tr(Point(21,1), Point(21,2), Point(50,50)); Triangle::Triangle_iter triter(tr); Circle::Circle_iter pos(p); cout << pos.begin(); while(!pos.end()) { cout << pos.next(); } cout << triter.begin(); while(!triter.end()) { cout << triter.next(); } system("pause"); return 0; }
|
на все это добро студия выдает | Код | 1>k:\prog\laba5\main.cpp(11) : error C2079: 'triter' uses undefined class 'Triangle::Triangle_iter' 1>k:\prog\laba5\main.cpp(11) : error C2440: 'initializing' : cannot convert from 'Triangle' to 'int' 1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called 1>k:\prog\laba5\main.cpp(18) : error C2228: left of '.begin' must have class/struct/union 1> type is 'int' 1>k:\prog\laba5\main.cpp(19) : error C2228: left of '.end' must have class/struct/union 1> type is 'int' 1>k:\prog\laba5\main.cpp(19) : fatal error C1903: unable to recover from previous error(s); stopping compilation
|
не могу понять в чем дело... объясните пожалуйста) так прикреплены файлы проекта
Присоединённый файл ( Кол-во скачиваний: 2 )
laba5.rar 171,04 Kb
|