I'm having trouble getting this working. Here are the errors I get while compiling. Can someone please help me with these errors?
LineSegment.cpp: In constructor ‘LineSegment::LineSegment()’:
LineSegment.cpp:13: error: no matching function for call to ‘LineSegment::setEnd1(int)’
LineSegment.hpp:14: note: candidates are: void LineSegment::setEnd1(Point)
LineSegment.cpp:14: error: no matching function for call to ‘LineSegment::setEnd2(int)’
LineSegment.hpp:16: note: candidates are: void LineSegment::setEnd2(Point)
LineSegment.cpp: In member function ‘void LineSegment::setEnd1(Point)’:
LineSegment.cpp:19: error: no matching function for call to ‘Point::setXCoord()’
Point.hpp:12: note: candidates are: void Point::setXCoord(double)
LineSegment.cpp:20: error: no matching function for call to ‘Point::setYCoord()’
Point.hpp:14: note: candidates are: void Point::setYCoord(double)
LineSegment.cpp: In member function ‘double LineSegment::getEnd1()’:
LineSegment.cpp:25: error: cannot convert ‘Point’ to ‘double’ in return
LineSegment.cpp: In member function ‘void LineSegment::setEnd2(Point)’:
LineSegment.cpp:30: error: no matching function for call to ‘Point::setXCoord()’
Point.hpp:12: note: candidates are: void Point::setXCoord(double)
LineSegment.cpp:31: error: no matching function for call to ‘Point::setYCoord()’
Point.hpp:14: note: candidates are: void Point::setYCoord(double)
LineSegment.cpp: In member function ‘double LineSegment::getEnd2()’:
LineSegment.cpp:36: error: cannot convert ‘Point’ to ‘double’ in return
Point.hpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
#ifndef POINT_HPP
#define POINT_HPP
class Point
{
private:
double XCoord;
double YCoord;
public:
Point();
Point(double xVal, double yVal);
void setXCoord(double);
double getXCoord();
void setYCoord(double);
double getYCoord();
double distanceTo(const Point&);
};
#endif
|
Point.cpp
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
|
#include <iostream>
#include <cmath>
#include "Point.hpp"
Point::Point()
{
setXCoord(0);
setYCoord(0);
}
Point::Point(double xVal, double yVal)
{
setXCoord(xVal);
setYCoord(yVal);
}
void Point::setXCoord(double xVal)
{
XCoord = xVal;
}
void Point::setYCoord(double yVal)
{
YCoord = yVal;
}
double Point::getXCoord()
{
return XCoord;
}
double Point::getYCoord()
{
return YCoord;
}
double Point::distanceTo(const Point &otherpoint)
{
double xVal1,
xVal2,
yVal1,
yVal2;
double distanceX,
distanceY,
distanceSq,
distance;
xVal1 = XCoord;
xVal2 = otherpoint.XCoord;
yVal1 = YCoord;
yVal2 = otherpoint.YCoord;
distanceX = xVal1 - xVal2;
distanceY = yVal1 - yVal2;
distanceSq = pow(distanceX, 2) + pow(distanceY, 2);
distance = sqrt(distanceSq);
return distance;
}
|
LineSegment.hpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#ifndef LINESEGMENT_HPP
#define LINESEGMENT_HPP
#include "Point.hpp"
class LineSegment
{
private:
Point p1;
Point p2;
public:
LineSegment();
LineSegment(Point, Point);
void setEnd1(Point);
double getEnd1();
void setEnd2(Point);
double getEnd2();
double length();
double slope();
};
#endif
|
LineSegment.cpp
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
|
#include <iostream>
#include "LineSegment.hpp"
LineSegment::LineSegment(Point p1, Point p2)
{
setEnd1(p1);
setEnd2(p2);
}
LineSegment::LineSegment()
{
setEnd1(0);
setEnd2(0);
}
void LineSegment::setEnd1(Point p1)
{
p1.setXCoord();
p1.setYCoord();
}
double LineSegment::getEnd1()
{
return p1;
}
void LineSegment::setEnd2(Point p2)
{
p2.setXCoord();
p2.setYCoord();
}
double LineSegment::getEnd2()
{
return p2;
}
double LineSegment::length()
{
return p1.distanceTo(p2);
}
double LineSegment::slope()
{
if (p2.getXCoord() - p1.getXCoord() == 0)
{
return -55555;
}
else
{
return(p2.getYCoord() - p1.getYCoord()) / (p2.getXCoord() - p1.getXCoord());
}
}
|
geomMain.cpp
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
|
#include <iostream>
#include "Point.hpp"
#include "LineSegment.hpp"
using namespace std;
int main()
{
Point p3, p4;
LineSegment linecheck1;
double userXCoord1 = 0;
double userYCoord1 = 0;
double userXCoord2 = 0;
double userYCoord2 = 0;
cout << "Please enter your X coordindate of Point 1: " << endl;
cin >> userXCoord1;
p3.setXCoord(userXCoord1);
cout << "Please enter your Y coordinate of Point 1: " << endl;
cin >> userYCoord1;
p3.setYCoord(userYCoord1);
cout << "Please enter your X coordinate of Point 2: " << endl;
cin >> userXCoord2;
p4.setXCoord(userXCoord2);
cout << "Please enter your Y coordinate of Point 2: " << endl;
cin >> userYCoord2;
p4.setYCoord(userYCoord2);
cout << "Point 1: " << p3.getXCoord() << "," << p3.getYCoord() << endl;
cout << "Point 2: " << p4.getXCoord() << "," << p4.getYCoord() << endl;
Point p1(p3.getXCoord(), p3.getYCoord());
Point p2(p4.getXCoord(), p4.getYCoord());
double dist = p1.distanceTo(p2);
cout << "The distance between Point 1 and Point 2 is: " << dist << endl;
cout << "The length between endpoints is: " << linecheck1.length() << endl;
return 0;
}
|