C++primer plus第六版课后编程题答案10.6

MOVE.h

#ifndef MOVE_H_
#define MOVE_H_
using namespace std;
//为了方便,我就直接把实现代码写到头文件了
class Move{	
private:
	double x;
	double y;
public:
	Move(double a=0,double b=0):x(a),y(b){};
	void showmove()const{
		cout<<"x="<<x<<"  y="<<y<<endl;
	};
	Move add(const Move &m)const
	{
		double x1=x+m.x;
		double y1=y+m.y;
		return Move(x1,y1);
	}
	void reset(double a=0,double b=0){
		x=a;
		y=b;
	}
};
#endif

main106.cpp

#include <iostream>
#include "MOVE.h"
using namespace std;

void main106()
{
	Move m(1.5,2.3);
	Move m1(2.1,4.5);
	Move m3(1.6,2.5);
	m.reset(1,1);
	m.showmove();
	Move m4=m.add(m1);
	m4.showmove();



	system("pause");


}


posted @ 2014-04-14 18:30  天下纵横C++  阅读(314)  评论(0编辑  收藏  举报