1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
#include <iostream>
class Punct3D {
public:
Punct3D( double = 0.0, double = 0.0, double = 0.0 );
double getX() const;
void setX(double);
double getY() const;
void setY(double);
double getZ() const;
void setZ(double);
private:
double x;
double y;
double z;
//friend:
friend std::ostream& operator<< ( std::ostream&, const Punct3D& );
};
Punct3D::Punct3D( double x_arg, double y_arg, double z_arg )
: x { x_arg }
, y { y_arg }
, z { z_arg }
{
}
double Punct3D::getX() const { return x; }
void Punct3D::setX( double x_arg ) { x = x_arg; }
double Punct3D::getY() const { return y; }
void Punct3D::setY( double y_arg ) { y = y_arg; }
double Punct3D::getZ() const { return z; }
void Punct3D::setZ( double z_arg ) { z = z_arg; }
std::ostream& operator<< (std::ostream& o, const Punct3D& rhs)
{
o << '{' << rhs.x << "; " << rhs.y << "; " << rhs.z << '}';
return o;
}
class Sfera {
public:
Punct3D center;
Sfera(Punct3D = {}, double = 0.0);
double getR() const;
void setR(double);
double volume() const;
private:
double radius;
};
Sfera::Sfera(Punct3D center_arg, double radius_arg)
: center { center_arg }
, radius { radius_arg }
{
}
double Sfera::getR() const { return radius; }
void Sfera::setR(double radius_arg) { radius = radius_arg; }
// Thanks to Repeater:
double Sfera::volume() const
{
return ( 4.0 * 3.14159 * radius * radius * radius / 3.0);
}
std::ostream& operator<< (std::ostream& o, const Sfera& s)
{
o << "\n center: " << s.center
<< "\n radius: " << s.getR()
<< "\n volume: " << s.volume();
return o;
}
int main()
{
Punct3D pct( -1.1, 2.2, 3.3 );
Sfera sfr(pct, 4.1);
std::cout << "Punct3D: " << pct << '\n'
<< "Sfera: " << sfr << '\n';
return 0;
}
|