Mar 26, 2020 at 9:52pm UTC
After writing the program it shows me Punct3D: [-1.1;2.2;3.3]
Sfera: [[0;0;0];4.1], instead of showing me instead of Punct3D: [-1.1;2.2;3.3] Sfera: [[-1.1;2.2;3.3];4.1], can you explain me where i did wrong?
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
#include <iostream>
using namespace std;
class Punct3D
{
public :
Punct3D(double x = 0, double y = 0, double z = 0) {
setX(x);
setY(y);
setZ(z);
}
double getX() { return x; }
void setX(double x) { this ->x = x; }
double getY() { return y; }
void setY(double y) { this ->y = y; }
double getZ() { return z; }
void setZ(double z) { this ->z = z; }
friend ostream& operator <<(ostream& o, Punct3D& p);
private :
double x;
double y;
double z;
};
ostream& operator <<(ostream& o, Punct3D& p)
{
Punct3D pct;
o <<"[" << p.getX() << ";" << p.getY() << ";" << p.getZ() << "]" ;
return o;
}
class Sfera
{
public :
Punct3D c;
Sfera(Punct3D, double r=0){
setR(r);
}
double getR() { return r; }
void setR(double r) { this ->r = r; }
private :
double r;
};
ostream& operator <<(ostream& o, Sfera& s)
{
Punct3D pct;
Sfera sfr();
o <<"[" << pct <<";" << s.getR() << "]" ;
return o;
}
int main() {
Punct3D pct(-1.1, 2.2, 3.3);
Sfera sfr(pct, 4.1);
cout << "Punct3D: " << pct << endl
<< "Sfera: " << sfr << endl;
return 0;
}
Last edited on Mar 26, 2020 at 9:52pm UTC
Mar 26, 2020 at 10:27pm UTC
Your constructor for Sfera doesn't do anything with the Punct3D object you pass in by value.