18周 oj 矩形类中运算符重载
来源:互联网 发布:ally mac tyana磁力 编辑:程序博客网 时间:2024/06/05 05:38
/*定义一个矩形类,数据成员包括左下角和右上角坐标,定义的成员函数包括必要的构造函数、输入坐标的函数,实现矩形加法,以及计算并输出矩形面积的函数。要求使用提示中给出的测试函数并不得改动。 两个矩形相加的规则是:决定矩形的对应坐标分别相加,如 左下角(1,2),右上角(3,4)的矩形,与 左下角(2,3),右上角(4,5)的矩形相加,得到的矩形是 左下角(3,5),右上角(7,9)的矩形。 这个规则没有几何意义,就这么定义好了。 输出面积的功能通过重载"<<"运算完成。*/#include <iostream>using namespace std;class Rectangle{public: Rectangle() { x1=0; y1=0; x2=0; y2=0; } Rectangle(double a,double b,double c,double d) :x1(a),y1(b),x2(c),y2(d){} Rectangle operator + (Rectangle &p); friend ostream&operator << (ostream &,Rectangle &); void input();private: double x1,y1,x2,y2;};void Rectangle::input(){ cin>>x1>>y1>>x2>>y2;}Rectangle Rectangle::operator + (Rectangle &p){ Rectangle r; r.x1=x1+p.x1; r.y1=y1+p.y1; r.x2=x2+p.x2; r.y2=y2+p.y2; return r;}ostream&operator << (ostream &output,Rectangle &r){ output<<(r.x2-r.x1)*(r.y2-r.y1); return output;}int main(){ Rectangle p1(1,1,6,3),p2,p3; p2.input(); p3=p1+p2; cout<<p3; return 0;}
0 0
- 18周 oj 矩形类中运算符重载
- 【OJ】(二)---B---矩形类中运算符重载
- YTU-OJ- 矩形类中运算符重载
- 第十五周oj刷题—— Problem C: 矩形类中运算符重载【C++】
- OJ矩形类中的运算符重载(C++)
- 矩形类中运算符重载【C++】
- 矩形类中运算符重载【C++】
- 矩形类中运算符重载
- YTUOJ-矩形类中运算符重载
- 矩形类中运算符重载【C++】
- 矩形类中运算符重载【C++】
- 期中考试2--矩形类中运算符重载
- [YTU]_2384( 矩形类中运算符重载【C++】)
- [YTU]_2384 ( 矩形类中运算符重载【C++】)
- 矩形类中的运算符重载
- 矩形类中的运算符重载
- 16 oj 复数类 重载运算符+
- 【OJ】---R---复数类--重载运算符+
- C# 委托使用示例
- JSP入门知识之page,include,taglib----在滚滚代码中进修
- win7 密码破解
- Database 维护脚本
- StringBuilder和String的区别
- 18周 oj 矩形类中运算符重载
- websphere如何产生javacore和heapdump
- nes 游戏引擎 原理分析
- Coursera2014 Machine Learning -Andrew Ng Week 1 程序实现(Matlab or Octave)
- 使用sprintf() sscanf()转换字符串
- Raw-OS源码分析之消息系统-Queue_Size
- autolayout
- openssl中aes、rsa算法的使用
- (十二)动态内存与智能指针