{/* */}
C : public ( ), private, protected. public, public protected public protected . private, public protected private . protected, public, protected protected .
, , . :
__():base()
{/* */}
. , . , .
. : , (late binding). virtual. , , vmtbl (virtual method table), . .
, . , . .
: , . , . , .
, . . , .
. : MyPoint ( ), MyEllipse ( MyPoint ) MyCylinder ( MyEllipse ). MyClass.h. : Button1 ( Image1), Button2 MyPoint , Button3 MyEllipce , Button4 MyCylinder , SpinEdit1 SpinEdit4 , .
|
|
Myclass.h
//***************** class MyPoint **************************
class MyPoint {
int x,y;
public:
int GetX(){return x;}
int GetY(){return y;}
void SetX(int x1){x=x1;}
void SetY(int y1){y=y1;}
MyPoint(int xx=0,int yy=0){x=xx;y=yy;}
virtual void Show();
virtual bool Checking();
// , ?
virtual void MoveTo(int x1,int y1);
};
//**************classs MyEllipse **************************
class MyEllipse:public MyPoint {
int xa,yb;
public:
int GetXA(){return xa;}
int GetYB(){return yb;}
void SetXA(int xa1){xa=xa1;}
void SetYB(int yb1){yb=yb1;}
MyEllipse(int a=0,int b=0,int c=0,int d=0):MyPoint(a,b)
{xa=c;yb=d;}
virtual void Show();
virtual bool Checking();
// , ?
};
//**************** class MyCylinder ************************
class MyCylinder:public MyEllipse {
int h;
public:
int GetH(){return h;}
void SetH(int h1){h=h1;}
MyCylinder(int X=0,int Y=0,int R=0,int H=0):MyEllipse(X,Y,R,R/2)
{h=H;}
void Show();
bool Checking();
// , ?
};
//****************** class MyCylinder ********************
bool ExistFigure=false;// ExistFigure==false,
MyPoint *Figure;//- MyPoint.
Unit1.Cpp
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Myclass.h"
#pragma package(smart_init)
#pragma link "CSPIN"
#pragma resource "*.dfm"
TForm1 *Form1;
__fastcall TForm1::TForm1(TComponent* Owner): TForm(Owner)
{ }
//********** MyPoint ************************
void MyPoint::Show()
(Form1->Image1->Canvas->Pixels[x][y]=clRed;}
bool MyPoint::Checking(){
//- , ?
if((x>=0)&&(x<=Form1->Image1->Width)&&(y>=0)&&
(y<=Form1->Image1->Height))
return true; else return false;
}
void MyPoint::MoveTo(int x1,int y1)
{ // , .
int a=x,b=y;
x=x1;y=y1;
if(!Checking()){x=a;y=b;}
}
//*********** MyEllipse **********************
void MyEllipse::Show()
{
Form1->Image1->Canvas->Ellipse(GetX()-xa,GetY()-yb,GetX()+xa,GetY()+yb);
}
// , ?
bool MyEllipse::Checking()
{
int rabx=GetX(),raby=GetY();
SetX(GetX()-xa);SetY(GetY()-yb);
if(MyPoint::Checking())
{
SetX(GetX()+2*xa);SetY(GetY()+2*yb);
if(MyPoint::Checking())
{
SetX(rabx);SetY(raby); // c x,y.
return true;
}
}
SetX(rabx);SetY(raby); // c x,y.
|
|
return false;
}
//********** MyCylinder ************************
void MyCylinder::Show()
{
MyEllipse::Show();
Form1->Image1->Canvas->MoveTo(GetX()-GetXA(),GetY());
Form1->Image1->Canvas->LineTo(GetX()-GetXA(),GetY()-h);
Form1->Image1->Canvas->MoveTo(GetX()+GetXA(),GetY());
Form1->Image1->Canvas->LineTo(GetX()+GetXA(),GetY()-h);
SetY(GetY()-h);
MyEllipse::Show();
SetY(GetY()+h);
}
bool MyCylinder::Checking()
{
if(MyEllipse::Checking())
{
SetY(GetY()-h);
if(MyEllipse::Checking()){SetY(GetY()+h);return true;}
}
return false;
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{ // ""
Image1->Canvas->FillRect(Rect(0,0,Image1->Width,Image1->Height));
ExistFigure=false;
}
void __fastcall TForm1::Button2Click(TObject *Sender)
{
if(ExistFigure==true)delete Figure;
Image1->Canvas->FillRect(Rect(0,0,Image1->Width,Image1->Height));
// ,
Figure=new MyPoint(CSpinEdit1->Value,CSpinEdit2->Value);
ExistFigure=true;
if(Figure->Checking()) Figure->Show();
else ShowMessage(" !");
}
void __fastcall TForm1::Button3Click(TObject *Sender)
{
if(ExistFigure==true) delete Figure;
Image1->Canvas->FillRect(Rect(0,0,Image1->Width,Image1->Height));
// ,
Figure=new MyEllipse(CSpinEdit1->Value,CSpinEdit2->Value,
CSpinEdit3->Value,CSpinEdit3->Value);
ExistFigure=true;
if(Figure->Checking())Figure->Show();
else ShowMessage(" !");
}
void __fastcall TForm1::Button4Click(TObject *Sender)
{
if(ExistFigure==true) delete Figure;
Image1->Canvas->FillRect(Rect(0,0,Image1->Width,Image1->Height));
// ,
Figure=new MyCylinder(CSpinEdit1->Value,CSpinEdit2->Value,
CSpinEdit3->Value,CSpinEdit4->Value);
ExistFigure=true;
if(Figure->Checking())Figure->Show();
else ShowMessage(" !");
}
void __fastcall TForm1::CSpinEdit1Change(TObject *Sender)
{
if(ExistFigure==true){
Image1->Canvas->FillRect(Rect(0,0,Image1->Width,Image1->Height));
Figure->MoveTo(CSpinEdit1->Value,CSpinEdit2->Value);
Figure->Show();
}
}
void __fastcall TForm1::CSpinEdit2Change(TObject *Sender)
{
if(ExistFigure==true){
Image1->Canvas->FillRect(Rect(0,0,Image1->Width,Image1->Height));
Figure->MoveTo(CSpinEdit1->Value,CSpinEdit2->Value);
Figure->Show();
}
}
. ; ; .
( ) show (), get (), set () , . , .
. . .
show () .
.
1. , , . .
2. , , . .
|
|
3. , , . .
4. 13, . .
5. . . .
6. , , . . , .
7. ( , ; ). , , , . , , . , .
8. , , .
9. , , . .
10. , , . . .
1. Item ( ), -: invNumber taken , :
virtual void Show(); //
bool isAvailable(); // ?
int GetinvNumber(); //
void Take(); //
void Return(); //
Book Magazin. Book -: author, title, publisher, year : Author();
Title(); Publisher(); YearOf Publishing(); Show().
Magazin -: volume; number; year; title : Volume(); Title(); Number(); Year(); Show().
2. Polygon (). , , . Triangle (), , , , , .
3. Shape . Square (, ), Circle ( ), Ellipse ( ), , .
4. CPoint CcoloredPoint CLine. CcoloredPoint CLine - CcoloredLine. , .
5. Stroka. - : char ; int .
|
|
: ; , C- ( ); ; ; ( ); .
_ ( 0 1). , , _ . . .
: ; , C-; ; ; ( ).
( ): ; (+); (==).
6. 10 ( ) ( ).
: ; , C-; ; ; , , int; , , ; , (int); , .
: (+); ( ) (>); (<); (=).
7. л (BoolVector) Vector. {0,1}.
: ; , ( , 0 1, ) ; ; ; , ; , .
: (&); (|); (~); (^); (=).
8. л Vector. {0,1,2}.
: ; , ; ; ; ( , , 0, 1); , , 2.
: (=); () (&): 0&0=0, 1&1=1, 2&2=2, 0&2=0, 2&0=0, 1&2=1, 2&1=1; ([]).
9. .
: ; , , , n m; ; ; ; , a- ( ; , ).
: (&); (|); (^); A=[aij] B=[ bjk], i= , j= , k= (*). , ; (=).
10. л n´m. (. . 2, 4).
11. Time, : , . .
12. Date, : , . .
13. Annotation, .
14. Dictionary, .
15. File, .
|
|
16. Stack, .
17. , - : ; ; ; . , : ; .