movePoint.cxx#ifndef MOVEPOINT_H_
#define MOVEPOINT_H_
class Move
{
private:
double x;
double y;
public:
Move(double a = 0 , double b = 0);
~Move();
void show()const;
Move add(const Move& m)const;
void reset(double a = 0 , double b = 0);
};
#endif
main.cxx#include<iostream>
#include"movePoint.h"
Move::Move(double a , double b)
{
x = a;
y = b;
}
Move::~Move()
{
}
void Move::show()const
{
std::cout<<"当前坐标为: "<<x<<","<<y<<std::endl;
}
Move Move::add(const Move& m)const
{
double X = x + m.x;
double Y = y + m.y;
return Move(X,Y);
}
void Move::reset(double a , double b)
{
x = a;
y = b;
}
#include<iostream>
#include"movePoint.h"
int main()
{
Move testMove(1,2);
testMove.show();
Move midMove(10,12);
midMove.show();
Move addMove = testMove.add(midMove);
addMove.show();
addMove.reset(3,3);
addMove.show();
return 0;
}