# Need help(3D point class)

• 10-09-2009
Fatima Rizwan
Need help(3D point class)
Hello ,, there is some error with member funtion distance can anyone help me with it.

Code:

```#include<iostream.h> #include<conio.h> #include<math.h> class point { int x; int y; int z; public: void setPoint() {         cin>>x>>y>>z; } void printPoint() {         cout<<"("<<x<<","<<y<<","<<z<<")"<<"\n"; } void negatePoint() {         cout<<"Negate of point is:("<<-x<<","<<-y<<","<<-z<<")\n"; } void distancePoint(float) { point dis;   dis=pow 1(x,2)+ pow(y,2) +pow(z,2);   dis=sqrt(dis); } }; int main() { point a; clrscr(); a.setPoint(); a.printPoint(); a.negatePoint(); a.distancePoint(); getch(); return 0; }```
• 10-09-2009
RockyMarrone
Code:

```include<iostream> #include<math.h> class point {   int x;   int y;   int z; public:   void setPoint()   {     std::cin>>x>>y>>z;   }   void printPoint()   {     std::cout<<"("<<x<<","<<y<<","<<z<<")"<<"\n";   }   void negatePoint()   {     std::cout<<"Negate of point is:("<<-x<<","<<-y<<","<<-z<<")\n";   } #if 0   // This peice of code is blocked coz i cant understand what                                                                                                                                                      // u want to do in distance point if u want to knw the distance                                                                                                                                                  // of two points and return the diff                                                                                                                                                                              void distancePoint(const float distance)   {     point dis;     dis.x = pow 1(x,2)+ pow(y,2) +pow(z,2);     dis.y = sqrt(dis.x);   } #else   point Distance(const point point_a,                 const point point_b) {     point result;     result.x = point_a.x - point_b.x;     result.y = point_a.y - point_b.y;     result.z = point_a.z - point_b.z;     return result;   } #endif }; int main() {   point a; #if 0   clrscr(); // Sorry i m compiling with g++                                                                                                                                                                      #endif   a.setPoint();   a.printPoint();   a.negatePoint(); #if 0   a.distancePoint(); // Changed the signature u can use however u want :)                                                                                                                                        #endif #if 0   getch(); // window's specific                                                                                                                                                                                  #endif   return 0; }```

Check this out......
And i compiled this with g++ 4.3.2 on linux kernel 2.6.2
so microsoft specific function has been commented and abt distancepoint i dont understand what u want to do with that
• 10-09-2009
gamer4life687
What error are you having?
• 10-09-2009
Fatima Rizwan
distance function calculates the distance from the origin, sqrt((x-0)^2,(y-0)^2,(z-0)^2)
• 10-09-2009
RockyMarrone
K then write the code and u will find any problem tell me, sorry i was not aware of that :)
• 10-09-2009
RockyMarrone
And by the way what is the origin in your sample code ?????
• 10-09-2009
RockyMarrone
Quote:

Originally Posted by Fatima Rizwan
distance function calculates the distance from the origin, sqrt((x-0)^2,(y-0)^2,(z-0)^2)

Why u are having the forumla like above that can be written like
sqrt((x)^2,(y)^2,(z)^2)
• 10-09-2009
Fatima Rizwan
origin is 0
• 10-09-2009
Fatima Rizwan
Code:

```#include<iostream.h> #include<conio.h> #include<math.h> class point { int x; int y; int z; public: void setPoint() {         cin>>x>>y>>z; } void printPoint() {         cout<<"("<<x<<","<<y<<","<<z<<")"<<"\n"; } void negatePoint() {         cout<<"Negate of point is:("<<-x<<","<<-y<<","<<-z<<")\n"; } void distancePoint() { double dis;   dis=sqrt(pow(x,2)+pow(y,2)+pow(z,2)); } }; int main() { point a; clrscr(); a.setPoint(); a.printPoint(); a.negatePoint(); a.distancePoint(); cout<<a.distancePoint();    //ILLEGAL STRUCTURE OPERATION getch(); return 0; }```
hOW TO PRINT IT??
• 10-09-2009
m37h0d
distancepoint returns void.
• 10-09-2009
anon
To answer the last question, the distance function should return the result.

Similarly it would more sense for negate to return a point with negated values, and for setPoint not to ask for input but to accept three values through arguments.
• 10-10-2009
RockyMarrone
Fatima is ur problem solved or not ??? or just stuck in distance caluclation ????
• 10-10-2009
Fatima Rizwan
ya its solved,,,=))