
Опытный
 
Профиль
Группа: Участник
Сообщений: 635
Регистрация: 22.10.2008
Где: Украина-ZPсity
Репутация: нет Всего: нет
|
Есть код: Код | // Unit1.h //---------------------------------------------------------------- #ifndef Unit1H #define Unit1H //---------------------------------------------------------------- #include <Classes.hpp> #include <Controls.hpp> #include <StdCtrls.hpp> #include <Forms.hpp> #include <ExtCtrls.hpp> //---------------------------------------------------------------- class TForm1 : public TForm { __published: // IDE-managed Components TEdit *Edit1; TEdit *Edit2; TEdit *Edit3; TEdit *Edit4; TEdit *Edit5; TLabel *Label1; TLabel *Label2; TLabel *Label3; TEdit *Edit6; TImage *Image1; TButton *Button1; TButton *Button2; TLabel *Label4; TEdit *Edit7; TLabel *Label5; TEdit *Edit8; TEdit *Edit9; TButton *Button3; TButton *Button4; void __fastcall Button1Click(TObject *Sender); void __fastcall Button2Click(TObject *Sender); void __fastcall Button3Click(TObject *Sender); void __fastcall Button4Click(TObject *Sender); private: // User declarations public: // User declarations __fastcall TForm1(TComponent* Owner); }; //----------------------------------------------------------------extern PACKAGE TForm1 *Form1; #endif //---------------------------------------------------------------- // Myclass.h class GeometrFig{ public: virtual void Draw()=0; virtual void Rotation(float)=0; virtual void Move(float, float)=0; };
class Triangle:public GeometrFig{ float xcentre, ycentre, // координати центру degrOfRotat, // кут повороту scaleparam, // масштабний фактор x1, y1, x2, y2, x3, y3; public: Triangle(float _x1, float _y1, float _x2, float _y2, float _x3, float _y3); void Draw(); void Rotation(float); void Move(float, float); }; bool ExistFigure=false; //--------------------------------------------------------------- // Unit.cpp //----------------------------------------------------------------#include <vcl.h> #pragma hdrstop #include "Unit1.h" #include "Myclass.h" #include "Math.h" //---------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; float x1, y1, x2, y2, x3, y3, degr, m, n; //---------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner){ Button2->Enabled=false; Button3->Enabled=false; } //---------------------------------------------------------------- Triangle::Triangle(float _x1, float _y1, float _x2, float _y2, float _x3, float _y3){ x1=_x1; y1=_y1; x2=_x2; y2=_y2; x3=_x3; y3=_y3; xcentre=(x1+x2+x3)/3; ycentre=(y1+y2+y3)/3; } void Triangle::Draw(){ if(ExistFigure==true){ Form1->Image1->Canvas->FillRect(Rect(0,0,Form1-> Image1->Width,Form1->Image1->Height)); } Form1->Image1->Canvas->MoveTo(x1,y1); Form1->Image1->Canvas->LineTo(x2,y2); Form1->Image1->Canvas->MoveTo(x2,y2); Form1->Image1->Canvas->LineTo(x3,y3); Form1->Image1->Canvas->MoveTo(x1,y1); Form1->Image1->Canvas->LineTo(x3,y3); ExistFigure=true; }
void Triangle::Rotation(float degr){ degrOfRotat=degr; degrOfRotat=degrOfRotat/180*M_PI; float _x1=x1, _x2=x2, _x3=x3; x1=x1*cos(degrOfRotat)-y1*sin(degrOfRotat)- xcentre*(cos(degrOfRotat)-1)+ycentre*sin(degrOfRotat); y1=_x1*sin(degrOfRotat)+y1*cos(degrOfRotat)-ycentre*(cos(degrOfRotat)-1)-xcentre*sin(degrOfRotat); x2=x2*cos(degrOfRotat)-y2*sin(degrOfRotat)-xcentre*(cos(degrOfRotat)-1)+ycentre*sin(degrOfRotat); y2=_x2*sin(degrOfRotat)+y2*cos(degrOfRotat)-ycentre*(cos(degrOfRotat)-1)-xcentre*sin(degrOfRotat); x3=x3*cos(degrOfRotat)-y3*sin(degrOfRotat)-xcentre*(cos(degrOfRotat)-1)+ycentre*sin(degrOfRotat); y3=_x3*sin(degrOfRotat)+y3*cos(degrOfRotat)-ycentre*(cos(degrOfRotat)-1)-xcentre*sin(degrOfRotat); this->Draw(); Form1->Edit1->Text=FloatToStr(x1); Form1->Edit2->Text=FloatToStr(y1); Form1->Edit3->Text=FloatToStr(x2); Form1->Edit4->Text=FloatToStr(y2); Form1->Edit5->Text=FloatToStr(x3); Form1->Edit6->Text=FloatToStr(y3); }
void Triangle::Move(float m, float n){ x1+=m; x2+=m; x3+=m; y1+=n; y2+=n; y3+=n; this->Draw(); Form1->Edit1->Text=FloatToStr(x1); Form1->Edit2->Text=FloatToStr(y1); Form1->Edit3->Text=FloatToStr(x2); Form1->Edit4->Text=FloatToStr(y2); Form1->Edit5->Text=FloatToStr(x3); Form1->Edit6->Text=FloatToStr(y3); }
void __fastcall TForm1::Button1Click(TObject *Sender){ if(((Edit1->Text).Length()!=0) && ((Edit2-> Text).Length()!=0) && ((Edit3->Text).Length()!=0) && ((Edit4-> Text).Length()!=0) && ((Edit5->Text).Length()!=0) && ((Edit6-> Text).Length()!=0)){ x1 = StrToFloat(Edit1->Text); y1 = StrToFloat(Edit2->Text); x2 = StrToFloat(Edit3->Text); y2 = StrToFloat(Edit4->Text); x3 = StrToFloat(Edit5->Text); y3 = StrToFloat(Edit6->Text); Triangle tr(x1, y1, x2, y2, x3, y3); tr.Draw(); ExistFigure=true; Button2->Enabled=true; Button3->Enabled=true; }
} //---------------------------------------------------------------- void __fastcall TForm1::Button2Click(TObject *Sender){ if((Edit7->Text).Length()!=0){ degr=StrToFloat(Edit7->Text); Triangle tr(x1, y1, x2, y2, x3, y3); tr.Rotation(degr); } else ShowMessage("Необходимо ввести угол поворота"); } //---------------------------------------------------------------- void __fastcall TForm1::Button3Click(TObject *Sender){ if(((Edit8->Text).Length()!=0) && ((Edit9->Text).Length()!=0)){ m=StrToFloat(Edit8->Text); n=StrToFloat(Edit8->Text); Triangle tr(x1, y1, x2, y2, x3, y3); tr.Move(m, n); } else ShowMessage("Необходимо ввести координаты вектора"); } //----------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender){ if(ExistFigure==true) Form1->Image1->Canvas->FillRect(Rect(0,0, Form1->Image1->Width,Form1->Image1->Height)); }
|
какой проект нужно создавать в Microsoft Visual Studio 2008, для работы с таким примером? И прокомментируйте, кто знает, полностью код, пожалуйста.
--------------------
Don't let the system get you down.
|