重载运算符学习
来源:互联网 发布:阿里云dns解析负载均衡 编辑:程序博客网 时间:2024/06/08 09:43
<pre name="code" class="cpp">/***************************************/重载运算符的学习2015年8月/**************************************/#include <iostream>using namespace std;class ApRect{public://ApRect(){}ApRect(double ht,double wid){height=ht;width=wid;}//double Area(){return height*width;}double Width(){return width;}double Height(){return height;}//friend istream& operator >>(istream& in,ApRect& cls);//friend ostream& operator <<(ostream& out,ApRect& cls);//double operator + (const ApRect rect);//double operator [] (const int index);//friend bool operator > (ApRect rect_1, ApRect rect_2_);bool operator < (ApRect rect);//~ApRect(){}private:double height;double width;};istream& operator >> (istream& in, ApRect& cls){cout<<"input height and width:";in>>cls.height>>cls.width;return in;}ostream& operator <<(ostream& out, ApRect& cls){out<<"height:"<<cls.height<<";width:"<<cls.width;return out;}double ApRect::operator +(ApRect rect){return Area()-rect.Area();}double ApRect::operator [](int a){switch(a){case 0:return Height();break;case 1:return Width();break;case 2:return Area();break;default:return 0.0;break;}}bool operator >(ApRect rect_1,ApRect rect_2){return (rect_1.Area()>rect_2.Area()) ? true:false;}bool ApRect::operator <(ApRect rect){return (Area()<rect.Area()) ? true:false;}int main(){ApRect rect_1;ApRect rect_2(10,20);cin>>rect_1;cout<<endl<<"rect_1"<<rect_1<<endl;cout<<"rect_2:"<<rect_2<<endl<<endl;
//addcout<<"+:"<<rect_1+rect_2<<endl;return 0;}
0 0
- 运算重载符学习
- 重载运算符学习
- C#学习:运算符重载
- Python运算符重载学习
- 运算符重载 学习笔记
- 运算符重载学习小记
- C++学习-运算符重载
- 运算符重载学习笔记
- C++学习-运算符重载
- C++学习:运算符重载
- 【C#学习】运算符重载
- [C++学习]矩阵运算符重载
- c#学习笔记(七)运算符重载
- 再次学习c++运算符重载(一)
- C#运算符重载学习总结
- C++学习笔记之运算符重载
- C++学习笔记十四-运算符重载
- c++学习笔记(运算符重载)
- Kibana User Guide [4.2] » Settings » Setting Advanced Options
- 第13周实践项目-Floyd算法验证
- 第十三周项目3--Dijkstra算法的验证
- 第十三周--从一个顶点到其余各顶点的最短路径
- Problem-Solving Strategies
- 重载运算符学习
- 第十一周 项目二-用二叉树求解代数表达式
- 13周-拓扑排序算法验证
- 遍历 cookies
- 第十二周项目五迷宫问题之图深度优先遍历解法
- gcc 基本参数表
- 第6周项目4--数制转换
- 第十三周--项目2Kruskal算法的验证
- Android开发笔记(四)字符串格式化