Professional Documents
Culture Documents
Глава 2 PDF
Глава 2 PDF
)
class
class
class
struct union.
C
CPoint.
-
-
[4]
class
private:
public:
protected:
};
25
private, public, protected,
private
public)
protected,
public.
CPoint
:
CPoint point1, points[10], &point2=point1, *pPoint;
pPoint=new CPoint[5];
CPoint
pPoint.
2.2.
(inline) inline-
::
CPoint method().
point1.method
method
27
2.1.
).
#include <iostream>
#include <iostream>
#include <windows.h>
using namespace std;
class CPoint
};
void main()
{
setlocale(0,"");
char tmp[80];
CharToOem tmp);
-
CPoint
int a, b;
\n ";
cin>>a>>b;
\n ";
cin>>a>>b;
28
- \n";
cout<<"("<<point1.GetX()<<","<<point1.GetY()<<")
("<<point2.GetX()<<","<<point2.GetY()<<")\n";
system("pause");
}
2.3.
SetX() SetY()
-
- -
29
void
CPoint point1;
CPoint::CPoint
CPoint::CPoint(){x=0; y
CPoint point1=CPoint();
.
30
CPoint
a b -
).
-
a b
point2
31
N):
N N) {}
CPoint
point1 point1(1,2);
CPoint point2(point1);
point1 point1
point2.
32
-
[8, c. 223]
-
const
- Cpoint
2.4.
~
CPoint
~CPoint();
delete
33
main().
delete
2.2.
CPoint
__________________________________________________________
#include <iostream>
#include <windows.h>
using namespace std;
class CPoint
{int x,y;
public:
CPoint() {x=0;y=0;cout
endl
CPoint (int a, int b): x(a), y(b) {cout
endl
34
void main(){
setlocale(0,"");
system("color F
char tmp[80];
CharToOem c
tmp);
SetConsoleTitle(tmp
CPoint.
35
SetX(), SetY()
GetX GetY().
delete,
2.5. this
this
:
const this
CPoint,
this
this
36
x Cpoint
:
CPoint & CPoint::maxX( CPoint & point)
{ if (point.x>x) return point;
else return *this;
}
this
[2, c. 125]
this.
2.6.
maxX() Cpoint
const
const
const
const:
const
const
37
const CPoint point00(0,0);
CPoint
x y,
2.3.
#include <iostream>
#include <windows.h>
using namespace std;
class CPoint
{int x,y;
public:
CPoint() {x=0;y=0; cout \n
~CPoint() {cout \n
38
int GetX() const {return x
x
int GetY() const {return y
y
void Print() const
};
{cout
cout<<"("<<x<<","<<y<<")\n";
}
const CPoint & CPoint::maxX( const CPoint & point) const
{if (point.x>x) return point;
else return *this;
}
void main()
{
setlocale(0,"");
system("color F
char tmp[80];
CharToOem c
tmp);
SetConsoleTitle(tmp
maxX()
(0,0)
pp->Print()
CPoint point_max(point1.maxX(point2));
point1 maxX
point2
point_max.
maxX() point_max ,
(pp->maxX(point_max)).Print();
Print()
40
point_max
maxX()
main()
system("pause");
delete
41
main().
2.7
st tic.
CPoint.
2.4.
#include <iostream>
#include <windows.h>
using namespace std;
class CPoint
{int x,y;
public:
42
static int count_point;// -
CPoint() {x=0;y=0; count_point
};
char tmp[80];
CharToOem c static", tmp);
SetConsoleTitle(tmp
cout<<" :\n";
point1.Print();
point2.Print();
pp->Print();
43
.4
-
count_point
main()
this.
CPoint
44
-
count_point.
2.5.
#include <iostream>
#include <windows.h>
using namespace std;
class CPoint
{ int x,y;
static int count_point -
public:
CPoint() {x=0;y
CPoint (int a, int b): x(a), y(b
};
char tmp[80];
CharToOem c static", tmp);
SetConsoleTitle(tmp
CPoint point -
cout \n";
point1.Print();
45
cout - point1.IncCount()<<endl;
CPoint point -
\n";
point2.Print();
cout - point2.IncCount()<<endl;
// 2-
system("pause");
}
__________________________________________________________
.5
[9, c. 413].
[11, c. 61].
2.8.
[7]
46
friend
friend
this;
CPoint
this -
Distance()
CPoint.
2.6.
#include <iostream>
#include <windows.h>
#include <iomanip>
47
using namespace std;
class CPoint
{int x,y;
public:
CPoint() {x=0;y
CPoint (int a, int b): x(a), y(b) {
void main()
{
setlocale(0,"");
system("color F0"); //
char tmp[80];
CharToOem c
tmp);
SetConsoleTitle(tmp
48
.6
[4, c. 491].
2.7.
#include <iostream>
#include <windows.h>
using namespace std;
class CLine
class CPoint
{int x,y;
public:
CPoint(int a=0,int b=0) {x=a;y=b
49
int GetX() const {return x
x
int GetY() const {return y
y
{int k,b;
public:
CLine(int kk=0,int bb=0) {k=kk;b=bb
","<<p.
"x+" << l.GetB() << endl;
endl;
}
void main()
{
setlocale(0,"");
system("color F0"); //
char tmp[80];
CharToOem c
tmp);
SetConsoleTitle(tmp
Print(point1, line1);
Print(point2, line1);
50
Print(point2, line2);
system("pause");
}
__________________________________________________________
.7
CPoint
CLine.
Print()
Is_Belongs() ,
CLine).
CPoint
CLine,
51
friend
friend class
class
[12, c. 807].
class CFirst
F
...
};
class CSecond
{ friend CFirst :: F
...
};
CFirst CSecond.
public, private,
protected?
52
struct
class?
class CPoint
{int x,y;
public:
CPoint();
CPoint (int a, int b);
CPoint (const CPoint &point);
int _CPoint();
CPoint (int a);
~CPoint();
void CPointInit(int a,int b);
};
this
A B B
A?
53