Coordinates problem with classes

Create a class named Coord
Class has 4 private data items
int xPoint;
int yPoint;
int zPoint;
float deg;

write the setters and getters. They should be inline functions

write a member function named void display() that displays the data items in the following format
blank line
xCoord is ????????
yCoord is ????????
zCoord is ????????
degrees are ???.??
distance to origin ???
Blank line

Write a member function named
int distance2origin()
that calculates the distance from the (x, y, z) point to the origin (0, 0, 0)

Write a member function named
int distBetweenPoints(const Coord &obj)
that calculates the distance from the calling object to the x, y, z points of the Coord object passed to your function


It won't compile im having issue at the member functions


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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/***************************
*     libraries
****************************/
#include <iostream>
#include <iomanip>
#include <math.h>

using namespace std;

/****************************************
*     class definitions
****************************************/
class Coord
{
    private:
       int  xPoint;
       int  yPoint;
       int  zPoint;
       float deg;
  
    public:
       // setters
        void setxPoint(int x) {xPoint = x;}
        void setyPoint(int y) {yPoint = y;}
        void setzPoint(int z) {zPoint = z;}
        void setDeg(int d) {deg = d;}
        
        // getter
        int getxPoint() const {return xPoint;}
        int getyPoint() const {return yPoint;}
        int getzPoint() const {return zPoint;}
        int getDeg() const {return deg;}
        
       // 'member' functions 
        int distance2origin();
        int distBetweenPoints();
        void display();
                 
};
/****************************************
*     member functions for above class
****************************************/
int Coord ::distance2origin() // error here
{
    return sqrt(pow(float)(getxPoint(),2) + //error here
        (pow(float)(getyPoint(),2)) + //error here
        (pow(float)(getzPoint(),2))); //error here

}

int Coord :: distBetweenPoints(const Coord obj) //and error here
{
    return sqrt((pow(((float)getxPoint() - obj.getxPoint()), 2)) +
    (pow(((float)getyPoint() - obj.getyPoint()), 2)) +
    (pow(((float)getzPoint() - obj.getxPoint()), 2)));


}

void Coord :: display()
{
   cout << "\n\nxCoord is " << getxPoint() << endl;
   cout << "yCoord is " << getyPoint() << endl;
   cout << "zCoord is " << getzPoint() << endl;
   cout << "degrees are" << getDeg() << endl;
   cout << "distance to origin" << distance2origin() << endl;
   cout << "\n" << endl;
}

/*************************************
*     function prototype
*************************************/

void coordTesting01();

/************************************
*      global variables
*************************************/

int main()
{
 //test program here   
}

/************************************
*      non-member functions
*************************************/


 void coordTesting01()
{
        Coord c1;
        c1.setxPoint(12);
        c1.setyPoint(17);
        c1.setzPoint(3);
        c1.setDeg(6.51);
        c1.distance2origin();
        c1.display();
        
        Coord c2;
        c2.getxPoint();
        c2.getyPoint();
        c2.getzPoint();
        c2.getDeg();
        c2.distance2origin();
        c2.display();
        c2.distBetweenPoints(&c1);
        


}    
Last edited on
You set the parentheses wrong:
1
2
3
    return sqrt(pow((float)(getxPoint(),2) +
        (pow((float)(getyPoint(),2)) +
        (pow((float)(getzPoint(),2)));
Note that you do not need to cast at all (it is implicitly done)

The signature of the function on line 51 does not match the prototype on line 36. They must be the same (i.e. add the paraometer on line 36).
Topic archived. No new replies allowed.