#pragma once
#ifndef ff_H_
#define ff_H_
class Move {
private:
double x;
double y;
public:
Move(double a = 0,double b = 0);//初始化x,y
void showmove()const;
Move add(const Move & m);//把m對象的數據與調用對象的值相加,並返回這個對象
void reset(double a = 0, double b = 0);//設置新的值給調用對象
double rex()const;
double rey()const;
};
#endif
#include "ff.h"
#include <iostream>
Move::Move(double a, double b)
{
x = a;
y = b;
}
void Move::showmove() const
{
std::cout << "x = " << x
<< "y = " << y << std::endl;
}
Move Move::add(const Move & m)
{
double s,d;
s = (*this).rex() + m.rex();
d = (*this).rey() + m.rey();
(*this).reset(s,d);
return *this;
}
void Move::reset(double a, double b)
{
x = a;
y = b;
}
double Move::rex()const
{
return x;
}
double Move::rey() const
{
return y;
}
#include <iostream>
#include "ff.h"
#include <cstdlib>
using namespace std;
int main()
{
Move mo;
mo.reset(1.1, 1.2);
cout << "mo :";
mo.showmove();
Move so;
so.add(mo.add(so));
cout << "so :";
so.showmove();
system("pause");
return 0;
}