.


:




:

































 

 

 

 


. : ++, ,




3

 

: ++, , .

 

 

, .

++ - . , , , , . ++ .

, , .

. , , , - .

, ++, int double, , . - -, .

- : . , , , . . ++ : (private), (public) (protected).

- private , , . , .

public - , . .

, :

Ø ;

Ø , ;

Ø ;

Ø ;

Ø .

 

protected 5, .

struct. class, ( ). :

 

class < >

{

private:

< >

protected:

< >

public:

< >

 

} [ ];

 

. , . , Sphere :

 

class Sphere

{ public:

float r; //

float x, y, z; //

};

 

Sphere x, y, z r. Sphere , , . Sphere, .

 

 

lass Sphere

{ public:

float r;

float x, y, z;

// _I math. h, pi

float Volume ()

{ return (r*r*r*4*M_PI/3);}

float Surface _area ()

{ return (r*r*4*M_PI);}

};

 

Sphere :

- , ;

- , .

, . , , . . . Sphere, , .

lass Sphere

{ public:

float r;

float x, y, z;

float Volume (); //

float Surface _area (); //

};

float Sphere:: Volume () //

{ return (r*r*r*4*M_PI/3);}

float Sphere:: Surface _area () //

{ return (r*r*4*M_PI);}

 

, , . , . :

Sphere s; // s -

 

, . , , .

. (.). ++ , , . , , .

:

s.x = 1.5; s.y = 2.3; s.z = 4.2; s.r = 2.0;

cout << \n <<s.x<<, <<s.y<<, <<s.z;

cout << \n <<s.r;

cout << \n - <<s. Volume ();

cout << \n <<s. Surface _area ();

 

Sphere ( public). - , , . , .

, .

 

lass Sphere

{ float r;

float x, y, z;

float SQR();

public:

void SetX (float xcoord);

void SetY (float ycoord);

void SetZ (float zcoord);

void SetR (float radius);

float Volume ();

float Surface _area ();

};

float Sphere:: SQR()

{return (r * r);

void Sphere:: SetX (float xcoord)

{ x= xcoord;}

void Sphere:: SetY (float ycoord)

{ y= ycoord;}

void Sphere:: SetZ (float zcoord)

{ z = zcoord;}

void Sphere:: SetR (float radius)

{ r= radius;}

float Sphere:: Volume ()

{ return (SQR() * r * 4 * M_PI/3);}

float Sphere:: Surface _area ()

{ return (SQR() * 4 * M_PI);}

 

SQR(), . , , . private , .

main(). :

main()

{

Sphere s;

s.SetX(1.0); s.SetY(2.0); s.SetZ(3.0); s.SetR(4.0);

cout << \n - <<s. Volume ();

cout << \n <<s. Surface _area ();

return(0);

}

 

, . , . main() .

 

main()

{

Sphere s[2];

//

s[0].SetX(1.0); s[0].SetY(2.0); s[0].SetZ(3.0); s[0].SetR(4.0);

cout << \n 1 - <<s[0]. Volume ();

cout << \n 1 <<s[0]. Surface _area ();

//

s[1].SetX(1.0); s[1].SetY(2.0); s[1].SetZ(3.0); s[1].SetR(4.0);

cout << \n 2 - <<s[1]. Volume ();

cout << \n 2 <<s[1]. Surface _area ();

return(0);

}

, . . , .

 

main()

{

Sphere * ptr;

ptr = new Sphere;

ptr -> SetX(1.0); ptr -> SetY(2.0); ptr -> SetZ(3.0); ptr -> SetR(4.0);

cout << \n - <<ptr -> Volume ();

cout << \n <<ptr ->Surface _area ();

return(0);

}

 

 

1. .

2. . - : . - . :

- ;

- , ;

- , ;

- , .

, .

3. . - , . - .

4.

 

 

 

1. ? ?

2. ++ ?

3. ?

4. . ?

5. ?

6. ? .

7. ?

8. ? .

9. ?

 

 

4





:


: 2017-03-12; !; : 544 |


:

:

, .
==> ...

1540 - | 1394 -


© 2015-2024 lektsii.org - -

: 0.031 .