I have 3 classes which are point 1DClass, Point 2DClass and Point 3DClass.
Point 1DClass contains data member x
Point 2DClass contains data member y and inherits data member x from point 1DCLass
Point 1DClass contains data member z and inherits the other two data members.
these co-ordinates are to offer methods for accessing, mutating and displaying the values of co-ordinates. then multiple constructors will be provided by function overloading. this is the function overloading i need to do.
A- Accepting no parameters and setting all co-ordinates to 0.
B- Accepting all co ordinates as arguments and setting data members to arguments.
C- Accepting an existing object of the same time as an argument, and duplicating the data members of this object into the current object.
D- Accepting an object of a point of lesser dimensionality, and copying only those data members that are able to be represented in the current object setting unrepresented dimensions to 0.
if anyone could put me on the right track for this i would really appreciate it. I am so confused.
Thanks
This is what i have done so far. I'm not sure if it is write though.
class point1DClass
{
private:
int x;
public:
point1DClass(); // constructor function
int getx(); //Accessor function
void setx(int newx); // Mutator function
~point1DClass(); //Destructor function
};
point1DClass::point1DClass()
{
x=0;
}
void point1DClass::setx(int newx)
{
x = newx;
}
int point1DClass::getx()
{
return x;
}
point1DClass::~point1DClass()
{
cout << "Object Going Out of Scope!" << endl;
}
class point2DClass:public point1DClass
{
private:
int y;
public:
point2DClass(); // constructor
void sety(int newy); // Mutator function
int gety(); //Accessor function
~point2DClass();
};
point2DClass::point2DClass()
{
y=0;
}
void point2DClass::sety(int newy)
{
y = newy;
}
int point2DClass::gety()
{
return y;
}
point2DClass::~point2DClass()
{
cout << "Object Going Out of Scope!" << endl;
}
class point3DClass:public point2DClass
{
private:
int y;
int z;
public:
point3DClass();
// void sety(int newy);
void setz(int newz); // Mutator function
// int gety();
int getz();
I seems okay, remember that if 3D extends 2D then it inherits the members y and x from it, although you can only access them though the public mutators methods.
I think you still need to add the second constructors though:
B- Accepting all co ordinates as arguments and setting data members to arguments.
Put your code between code tags. When you're making/editing a post, you should see a button with <> as its icon under "Format:". Just highlight all your code and push that button.