在C ++中,我试图创建一个包含两个双精度值的Point2D类。所有数据成员和功能都应公开。
对于公众成员应该有
- 双倍x
- 双y
对于构造函数
-
默认构造函数应将x和y初始化为0.0
-
Point2D(double in_x,double in_y)
- 将x和y设置为in_x和in_y
对于非成员函数
-
void GetResult(Point2D p1,Point2D p2)
- 同时输出x和y值
这是我到目前为止的代码,有人可以指出我的错误吗?
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);
}