In C++ I am trying to create a class Point2D that contains two double values. All data members and functions should be public.
For Public Members there should be
- double x
- double y
For Constructors
the default constructor should initialize x and y to 0.0
Point2D(double in_x, double in_y)
- sets x and y to in_x and in_y
For non-member Functions
void GetResult(Point2D p1, Point2D p2)
- Prints x and y values for both
This is the code I have so far, can somebody please point out my errors?
Point2D.h
#ifndef POINT2D_H
#define POINT2D_H
class Point2D
{
public:
double x;
double y;
Point2D();
Point2D(double,double);
};
void GetResult(Point2D, Point2D);
#endif
Point2D.cpp
#include "Point2D.h"
#include <iostream>
using namespace std;
Point2D::Point2D()
{
x = 0.0;
y = 0.0;
}
Point2D::P1(double in_x, double in_y)
{
x = in_x;
y = in_y;
}
Point2D::P2(double in_x, double in_y)
{
x = in_x;
y = in_y;
}
void GetResult(Point2D P1, Point2D P2)
{
cout << P1.x << " " << P1.y << endl;
cout << P2.x << " " << P2.y << endl;
}
TestCheckPoint1.cpp
#include <iostream>
#include "Point2D.h"
using namespace std;
int main()
{
Point2D Point1;
Point1.x = 1.0;
Point1.y= 2.0;
Point2D Point2;
Point2.x= 1.0;
Point1.y= 2.0;
GetResult(Point1, Point2);
}