#ifndef POINT_H
#define POINT_H

class Point
{


public:
    Point();
    Point(int, int);
    int getx();
    int gety();
    void setx(int);
    void sety(int);
private:
    int x,y;
};

#endif

//POINT.CPP
#ifndef POINT_H
#define POINT_H

class Point
{


public:
    Point();
    Point(int, int);
    int getx();
    int gety();
    void setx(int);
    void sety(int);
private:
    int x,y;
};

#endif

#ifndef THREEDIMENSIONALPOINT_H
#define THREEDIMENSIONALPOINT_H

#include "point.h"

class ThreeDimensionalPoint:public Point
{
private:
    int z;
public:
    ThreeDimensionalPoint();
    ThreeDimensionalPoint(int, int, int);
    int getz();
    void setz(int );
    void addPoints(ThreeDimensionalPoint );

};

#endif 

//.cpp

#include "threedimensionalpoint.h"

ThreeDimensionalPoint::ThreeDimensionalPoint()
{
    setx(0);
    sety(0);
    setz(0);
}

ThreeDimensionalPoint::ThreeDimensionalPoint(int xin, int yin, int zin)
{
    //please implement this constructor to set the x, y and z values to the input parameter values
    setx(xin);
    sety(yin);
    setz(yin);
}
int ThreeDimensionalPoint::getz()
{
    return z;
    //please implement this function to get the z value
}
void ThreeDimensionalPoint::setz(int zin)
{
    z=zin;
    //please implement this function to set z value
}



void ThreeDimensionalPoint::addPoints(ThreeDimensionalPoint pointin)

{ int x1=getx(), y1=gety(), z1=getz();
x1 = getx() +   pointin.getx();
y1 = y1 +   pointin.gety();
z = z + pointin.z;

setx(x1);
sety(y1);
setz(z);
}   //please implement this function to add the x,y and z values of point1 to values of the calling instance of the object



//main.cpp

#include <iostream>

#include "point.h"
#include "threedimensionalpoint.h"

using namespace std;

int main(){
    ThreeDimensionalPoint point1(1,2,3);
    ThreeDimensionalPoint point2(4,5,6);
    point1.addPoints(point2);
    cout<<"\nThe value of the x value is: "<< point1.getx();
    cout<<"\nThe value of the y value is: "<< point1.gety();
    cout<<"\nThe value of the z value is: "<< point1.getz();
    cout<<"\n";
}

the program is not adding z. The output is (5,7,7). Can anyone tell me why its not adding the third value?

You have a typo on line 78, in your constructor, you have setz(yin); when it should be setz(zin);.

Thanks a lot.

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.