标签:des blog io os sp div log amp bs
2 3 3 5 10
5+8i 12+3i 12+3i
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
class Complex
{
    private:
      int real, imag;
    public:
      Complex()
      {
          real=0; imag=0;
      }
      Complex(double r, double i)
      {
          real=r; imag=i;
      }
      friend Complex operator +(Complex &c1, Complex &c2 )
      {
          return Complex(c1.real+c2.real, c1.imag+c2.imag );
      }
      friend Complex operator +(int &i, Complex &c2)
      {
          return Complex(i+c2.real, c2.imag );
      }
      friend Complex operator +(Complex &c1, int &i )
      {
          return Complex(i+c1.real, c1.imag );
      }
      void sett();
      void disp();
}c1,c2;
void Complex::sett()
{
    cin>>real>>imag;
}
void Complex::disp()
{
    if(imag<0)
    {
        cout<<real<<imag<<‘i‘<<endl;
    }
    else
    cout<<real<<‘+‘<<imag<<‘i‘<<endl;
}
int main()
{
    int ii;
    Complex a, b, c;
    c1.sett();
    c2.sett();
    cin>>ii;
    a=c1+c2;
    a.disp();
    b=c1+ii;
    b.disp();
    c=ii+c1;
    c.disp();
    return 0;
}
标签:des blog io os sp div log amp bs
原文地址:http://www.cnblogs.com/yspworld/p/4014226.html