1. .
2. . :
- ;
- ;
- .
. , , .
3. , .
4.
1. .
2. .
3. , 1.
4. , 2.
5.
1. ?
2. ?
3. ?
4. , ?
5. ? ?
6. . ?
7. ?
8. , ?
9. ?
10. explicit?
5
: , .
. .
, . ++. ++ ( ) ( ). . :
class < >: [< >] < >
{ };
: public, private protected. , : , . , public protected, , , public protected private. , .
|
|
. , x, y z. , .
class Shape
{ protected:
float x, y, z; //
public:
void SetX(float xcoord) //
{ x = xcoord;}
void SetY(float ycoord) // y
{ y = ycoord;}
void SetZ(float zcoord) // z
{ z = zcoord;}
float GetX () //,
{ return x;}
float GetY () //, y
{ return y;}
float GetZ () //, z
{ return z;}
};
Shape protected - . , , , - .
Sphere.
class Sphere: public Shape
{
float r;
public:
void SetR (float radius)
{r = radius;}
float GetR()
{ return r;}
float Surface_area ()
{ return r*r*4*3.14159;}
};
Sphere , . , Sphere Shape , , , y, z . , . , . , . , , , , ..
, , . . , , , .
::
.
, , . , .
: . , , . .
, . , . , , . , :
|
|
< > (< >):
< - >(< >)
{
//
}
, Shape , , y, z, :
Sphere (float _x, float _ y, float _ z, float _ r): Shape ( _x, _y, _z)
{r = _r;}
4 , . , .
. .
, . , .
.1. .
. .1 , B C, D . , D . .
#include <iostream.h>
class A
{ int a;
public:
A (int a1) { a = a1; }
int Geta () { return a; }
};
//
class C: public A
{ int c;
public:
C (int a1, int c1): A (a1)
{ c = c1; }
int Getc () { return c; }
};
//
//
class D: public C
{ int d;
public:
D (int a1, int c1, int d1): C (a1, c1)
{ d = d1; }
void Print ()
{
cout << Geta () << << Getc () << << d << \n;
}
};
main ()
{
D ob (1, 2, 3);
ob. Print ();
// Geta () Getc ()
cout << ob.Geta () << << ob.Getc () << \n;
return 0;
}
, , . .
, . . .
.2.
2. , .
:
class < >: < >< 1>,
< >< 2>,
, < >< N>
{
//
}
, .
, , , . , .
|
|
, , , :
< > (< >):
< 1>(< >),
< 2>(< >),
, < N>(< >)
{
//
}
. , Move. . Sphere Shape Move.
class Sphere: public Shape, public Move
{
//
};
:
Sphere (float _x, float _ y, float _ z, float _ r, float mov_x,
float mov_y, float mov_z): Shape ( _x, _y, z), Move (mov_x, mov_y, mov_z)
{r = _r;}
, .