欢迎来到天天文库
浏览记录
ID:6598067
大小:27.00 KB
页数:2页
时间:2018-01-19
《运算符重载练习题》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、C++与面向对象程序设计盛建瓴2006华北科技学院运算符重载练习题设计一个直角坐标类,重载+,-,=,++,<<运算符,以适应该类选择合理的返回值,以便写链式表达式classpoint{private:intx;inty;public:friendpointoperator+(pointp1,pointp2);pointoperator–(pointp);pointoperator=(pointp);pointoperator++();//前缀pointoperator++(intx);//后缀friendostream&operator<<(ostream&os,po
2、intp);};pointoperator+(pointp1,pointp2){pointtemp;temp.x=p1.x+p2.x;temp.y=p1.y+p2.y;returntemp;}pointpoint::operator–(pointp);{x=x-p.x;y=y-p.y;return*this;}pointpoint::operator++(){x++;y++;C++与面向对象程序设计盛建瓴2006华北科技学院return*this;}pointpoint::operator++(intx){pointtemp;temp.x=x++;temp.y=y++;
3、returntemp;}ostream&operator<<(ostream&os,pointp){os<<”p.x:”<
此文档下载收益归作者所有