I have an assignment where I'm supposed to "implement a class, Point that represents a point in a three-dimensional space." and im supposed to "carefully design the interface for this class and include functions that appear to be useful for operating on points." I'm not fully sure what this is asking me to do. I'm trying to create a queue and this is one of the classes which I need to use inside the queue.

Any help clarifying what this is telling me to do would be appreciated. I can figure out the coding its just confusing me on what to actually create.

What is a point?
What are it's parameters?
What can you do with a point?
Where can they exist?

Basically, you need to create a class that can fully(?) defines what a point is, and decide what a point can be used for and create functions that can make the point class useful -- like making lines, planes, etc.

Would something along the lines of this satisfy that?

class Point{
 public:

  Point(double x = 0.0, double y = 0.0, double z = 0.0);

  double getX();
  double getY();
  double getZ();

  double dist( Point );

  Point add( Point );
  Point sub( Point );

  void move( double, double, double );
  void print( );

 private:
  double xval, yval, zval;
};

Not a bad start. Now move on to implementing the class methods one at a time, and creating a driver program to test the implementations.

You might want to add some setX() stuff so you can change the values of the coordinates after you have constructed a Point without having to use move().

Can you really add/sub points? if you can implement those functions, go for it.

How about overloading << and >> for the class. And maybe the == operator as well.

If you want full points for the project you might want to consider implementing your own copy constructor, assignment operator, destructor and default constructor so you don't have to rely on the default versions that may, or may not in some cases, be provided by the compiler.

I suppose that's a good start. I'm assuming that "carefully design the interface for this class and include functions that appear to be useful for operating on points" does not mean defining a class in five minutes but a well thought-out design. Only you know the instructor and what he's likely to want.

I'm pretty happy with what I got, I'll use it in my queue which is the overall goal of this program

Point::Point( double x = 0.0, double y = 0.0, double z = 0.0 ){
  xval = x;
  yval = y;
  zval = z;
}

double Point::getX(){
  return xval;
}

double Point::getY(){
  return yval;
}

double Point::getZ(){
  return zval;
}

double Point::dist( Point other ){
  double xd = xval - other.xval;
  double yd = yval - other.yval;
  double zd = zval - other.zval;

  return( sqrt( xd*xd + yd*yd + zd*zd ) );
}

Point Point::add( Point b ){

  return Point( xval + b.xval, yval + b.yval, zval + b.zval );
}

Point Point::sub( Point b ){

  return Point( xval - b.xval, yval - b.yval, zval - b.zval );
}

void Point::move( double a, double b, double c ){

  xval += a;
  yval += b;
  zval += c;
}

void Point::print(){

  cout << "(" << xval << "," << yval << "," << zval << ")" << endl;
}

You know, this is just a suggestion so you don't have to listen.
These methods :

double dist( Point );
void move( double, double, double );

I wouldn't make put them into the Point interface. Because I feel that
they would be better of decoupled from the interface.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.