We are starting "classes" now in our introductory programming class. I'm having a problem sending information from int main() to the point class here's my code. This is just a simple lab where one sets coordinates and then finds the distance between the coordinates using the distance formula.
Code:
#include <iostream>
#include <cmath>
class Point
{
public:
Point();
Point(int xval, int yval);
int getX();
int getY();
void setX(int xval);
void setY(int yval);
void setXY(int xval, int yval);
void printPoint(void);
private:
int x;
int y;
};
Point::Point()
{
x = 0;
y = 0;
}
Point::Point(int xval, int yval)
{
x = xval;
y = yval;
}
int Point::getX()
{
return x;
}
int Point::getY()
{
return y;
}
void Point::setX(int xval)
{
x = xval;
}
void Point::setY(int yval)
{
y = yval;
}
void Point::setXY(int xval, int yval)
{
x = xval;
y = yval;
}
void Point::printPoint()
{
cout << "(" << x << ",";
cout << y << ")";
}
//THIS IS WHERE IM CONFUSED. GO DOWN FOR THE OTHER COMMENT
float Point::distanceFrom(Point coordinate)
{
distance = sqrt(pow((coordinate.getX() - x1), 2) + pow
((coordinate.getY() - y1), 2);
return distance;
}
int main()
{
Point pt1, pt2, pt3, origin;
pt1.setX(5);
pt1.setY(7);
pt2.setXY(-2, -4);
pt3.setXY(-8, -9);
origin.setXY(0,0);
// THIS IS WHERE MY PROBLEM LIES AS WELL
cout << "The distance between pt1 and pt2 is " << pt1.distanceFrom(pt2) // HOW WOULD I SEND pt1??
<< endl;
cout << "The distance between pt2 and pt1 is " << pt2.distanceFrom(pt1) // HOW WOULD I SEND pt2??
<< endl;
}
I don't know how to send the coordinates from pt1 to my distance formula in class point...please help.