/*plex,数据成员:实部real,虚部image。为该类
(a)重载运算符"+",实现两个复数相加,复数与实数相加,实数与复数相加。
(b)重载前置和后置运算符"++",实现实部和虚部同时加1。
(c)重载运算符'>',实现复数大小的比较(以复数的模作为比较标准)
(d)重载运算符"[ ]",实现以下标0引用实部,以下标1引用虚部。
(e)设计类型转换函数,plex转换为double型(取复数的模)。
设计主函数测试之。
*/
#include<iostream>
#include<cmath>
using namespace std;
plex
{
public:
Complex(int,int);
int getreal();
int getimage();
operator+(Complex &);
operator+(int );
operator++();
bool operator>(Complex &);
int operator[](const int &);
double change();
private:
int real;
int image;
};
Complex::Complex(int r,int i)
{
real=r;
image=i;
}
Complex::getreal()
{
return real;
}
Complex::getimage()
{
return image;
}
Complex::operator +(Complex &o)
{
real+=;
image+=;
}
Complex::operator +(int a)
{
real+=a;
}
Complex::operator ++()
{
real++;
image+
c++运算符重载-实例-plex 来自淘豆网www.taodocs.com转载请标明出处.