Point and Line Class

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#ifndef POINT_H
#define POINT_H
#include <iostream>

using namespace std;

class Point
{
public:
    //Default constructor
    Point();
    Point(double new_x, double new_y);
    /*******Member Fucntions*******/
    //Accessors
    double GetX();
    double GetY();
    //Mutators
    void SetX(double x);
    void SetY(double Y);
private:
    double xCOORD, yCOORD;
};

#endif // POINT_H 






1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#ifndef LINE_H
#define LINE_H
#include <iostream>
#include "point.h"

using namespace std;

class Line
{
public:
    Line();
    Line(Point P1, Point P2);
    double GetA();
    double GetB();
private:
    Point p1, p2;
    double A,B;
};

#endif // LINE_H 







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
#include "line.h"
#include "point.h"
#include <iostream>
#include <cmath>

using namespace std;

//Default constructor
Line::Line():A(0),B(0)
{
    //left blank intentionally
}
//Point1_Object & Point2_Object were suppose to get
//Passed into here
Line::Line(Point P1, Point P2)
{
    p1 = P1;
    p2 = P2;
    double x1,x2,y1,y2;
    x1 = P1.GetX();
    x2 = P2.GetX();
    y1 = P1.GetY();
    y2 = P2.GetY();

    //derived from slope(m) intercept(b) form
    double m,b;
    m = (y2 - y1)/(x2-x1);
    b = y1 - ((y2-y1))/(x2-x1)*x1;

    B = -1/b;
    A = -B*m;
}

//ACCESSORS
double Line::GetA()
{
    return A;
}
double Line::GetB()
{
    return B;
}




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include "point.h"
#include "line.h"

using namespace std;

int main()
{

    Point Point1_Object(5,5);
    cout<<"Point1 (x,y) is: ("<<Point1_Object.GetX()<<","<<Point1_Object.GetY()<<")"<<endl;
    cout<<endl;
    Point Point2_Object(4,4);
    cout<<"Point2 (x,y) is: ("<<Point2_Object.GetX()<<","<<Point2_Object.GetY()<<")"<<endl;
    cout<<endl;

    Line THE_Line(Point1_Object, Point2_Object);
//    cout<<"Resulting line: "<<MyLine.GetA()<<"x"<<"+"<<MyLine.GetB()<<"y"<<" = 0"<<endl;


    cout <<endl<<endl<<endl<< "END!!!" << endl;
    return 0;
}




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
#include "point.h"
#include <iostream>

using namespace std;
              //INITIALIZES
Point::Point():xCOORD(0), yCOORD(0)
{
   //default constructor
   //does nothing
}

//Constructor acts as a mutator
//to get values

Point::Point(double new_x, double new_y)
{
    xCOORD = new_x;
    yCOORD = new_y;
}

//MUTATOR FUNCTIONS
void Point::SetX(double x)
{
    xCOORD = x;
}
void Point::SetY(double y)
{
    yCOORD = y;
}


//ACCESSOR FUNCTIONS
//This is how it is done
//In order to return a Private variable's value.
//In order to access a private variable's value.
double Point::GetX()
{
    return xCOORD;
}
double Point::GetY()
{
    return yCOORD;
}



Hi, so my question is I keep getting this error and it's been bugging me. I can't think of anyway to get around this. Any ideas what I'm doing wrong? Thank You.

The Error is: main.obj:-1: error: LNK2019: unresolved external symbol "public: __thiscall Line::Line(class Point,class Point)" (??0Line@@QAE@VPoint@@0@Z) referenced in function _main




Last edited on
unresolved external is linker error, check that line.cpp is compiled and linked.
Thank you for the reply that did the trick. I basically wasted 2hr thinking what I did wrong and in the end I didn't do anything wrong....gg hahaha but Thank you for the HELP! I appreciated it! :)
Topic archived. No new replies allowed.