[参考解答]
/* *Copyright (c)2014,烟台大学计算机与控制工程学院 *All rights reserved. *文件名称:d.cpp *作 者:张旺华 *完成日期:2015年6月1日 *版 本 号:v1.0 */ #include <iostream> using namespace std; class Point { public: Point (double X=0,double Y=0):x(X),y(Y){} ~Point(); void setPoint(double,double); double getx()const {return x;}; double gety()const {return y;}; friend ostream &operator<<(ostream &output,Point & p); protected: double x,y; }; Point::~Point() {} void Point::setPoint(double a,double b) { x=a; y=b; } ostream &operator<<(ostream &output,Point & p) { output<<"["<<p.x<<","<<p.y<<"]"; return output; } int main() { Point p(3.5,6.4); cout<<"x="<<p.getx( )<<",y="<<p.gety( )<<endl; p.setPoint(8.5,6.8); cout<<"p:"<<p<<endl; return 0; }运行结果:
知识点运用及学习心得:
更加完善了代码,
原文地址:http://blog.csdn.net/wh201458501106/article/details/46309039