• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            The Fourth Dimension Space

            枯葉北風寒,忽然年以殘,念往昔,語默心酸。二十光陰無一物,韶光賤,寐難安; 不畏形影單,道途阻且慢,哪曲折,如渡飛湍。斬浪劈波酬壯志,同把酒,共言歡! -如夢令

            復數類模板(Complex Class)

            #include<iostream>
            #include
            <cmath>
            using namespace std;


            //本模板在VS2005下可正常運行
            /**//*//////////////////////////////BEGIN_TEMPLATE_CALSS_COMPLEX_BY_ABILITYTAO////////////////////////////*/
            class Complex
            {
            private:

                
            void show();
                
            double real;
                
            double image;
            public:

                Complex()
            {real=0;image=0;}
                
            ~Complex(){}
                Complex(
            double a,double b){real=a;image=b;}
                
            double Getreal(){return real;}
                
            double Getimage(){return image;}
                
            double abs(){return sqrt(real*real+image*image);}
                Complex 
            operator +(Complex &other);
                Complex 
            operator +(const double &other);
                Complex 
            operator +(const int &other);

                Complex 
            operator -(Complex &other);
                Complex 
            operator -(const double &other);
                Complex 
            operator -(const int &other);

                Complex 
            operator *(Complex &other);
                Complex 
            operator *(const double &other);
                Complex 
            operator *(const int &other);

                Complex 
            operator /(Complex &other);
                Complex 
            operator /(const double &other);
                Complex 
            operator /(const int &other);

                
            void operator +=(Complex &other);
                
            void operator +=(const double &other);
                
            void operator +=(const int &other);

                
            void operator -=(Complex &other);
                
            void operator -=(const double &other);
                
            void operator -=(const int &other);

                
            void operator *=(Complex &other);
                
            void operator *=(const double &other);
                
            void operator *=(const int &other);

                
            void operator /=(Complex &other);
                
            void operator /=(const double &other);
                
            void operator /=(const int &other);

                Complex 
            operator =(Complex &other);
                Complex 
            operator =(const double &other);
                Complex 
            operator =(const int &other);

                
            bool operator ==(Complex &other);
                
            bool operator ==(const double &other);
                
            bool operator ==(const int &other);

                friend ostream
            & operator<<(ostream &os,Complex &other);
                friend istream
            & operator>>(istream &is,Complex &other);
            }
            ;


            void Complex::show()
            {

                
            if(real>0&&image<0)
                    printf(
            "%g%gj",real,image);
                
            else if(real>0&&image>0)
                    printf(
            "%g+%gj",real,image);
                
            else if(real<0&&image>0)
                    printf(
            "%g+%gj",real,image);
                
            else if(real<0&&image<0)
                    printf(
            "%g%gj",real,image);
                
            else if(real==0&&image!=0)
                    printf(
            "%gj",image);
                
            else if(real!=0&&image==0)
                    printf(
            "%g",real);
                
            else 
                    printf(
            "0");
            }


            Complex Complex::
            operator+(Complex &other)
            {
                Complex temp;
                temp.real
            =real+other.real;
                temp.image
            =image+other.image;
                
            return temp;
            }


            Complex Complex::
            operator +(const double &other)
            {

                Complex temp;
                temp.real
            =real+other;
                temp.image
            =image;
                
            return temp;
            }


            Complex Complex::
            operator +(const int &other)
            {
                Complex temp;
                temp.real
            =real+(double)other;
                temp.image
            =image;
                
            return temp;
            }



            Complex Complex::
            operator-(Complex &other)
            {

                Complex temp;
                temp.real
            =real-other.real;
                temp.image
            =image-other.image;
                
            return temp;
            }


            Complex Complex::
            operator -(const double &other)
            {

                Complex temp;
                temp.real
            =real-(double)other;
                temp.image
            =image;
                
            return temp;
            }


            Complex Complex::
            operator -(const int &other)
            {

                Complex temp;
                temp.real
            =real-(double)other;
                temp.image
            =image;
                
            return temp;
            }

            Complex Complex::
            operator*(Complex &other)
            {
                Complex temp;
                temp.real
            =(real*other.real-image*other.image);
                temp.image
            =(image*other.real+real*other.image);
                
            return temp;


            }


            Complex Complex::
            operator *(const double &other)
            {
                Complex temp;
                temp.real
            =real*other;
                temp.image
            =image*other;
                
            return temp;
            }


            Complex Complex::
            operator *(const int &other)
            {
                Complex temp;
                temp.real
            =real*(double)other;
                temp.image
            =image*(double)other;
                
            return temp;
            }


            Complex Complex::
            operator/(Complex &other)
            {

                Complex temp;
                temp.real
            =((real*other.real)+(image*other.image))/(other.real*other.real+other.image*other.image);
                temp.image
            =((image*other.real)-(real*other.image))/(other.real*other.real+other.image*other.image);
                
            return temp;

            }


            Complex Complex::
            operator /(const double &other)
            {
                Complex temp;
                temp.real
            =real/other;
                temp.image
            =image/other;
                
            return temp;

            }


            Complex Complex::
            operator /(const int &other)
            {
                Complex temp;
                temp.real
            =real/(double)other;
                temp.image
            =image/(double)other;
                
            return temp;
            }





            void Complex::operator+=(Complex &other)
            {
                
            this->real+=other.real;
                
            this->image+=other.image;
            }


            void Complex::operator +=(const double &other)
            {

                
            this->real+=other;
            }


            void Complex::operator +=(const int&other)
            {
                
            this->real+=(double)other;
            }






            void Complex::operator-=(Complex &other)
            {
                
            this->real-=other.real;
                
            this->image-=other.image;
            }


            void Complex::operator -=(const double &other)
            {

                
            this->real-=other;
            }


            void Complex::operator -=(const int &other)
            {
                
            this->real-=(double)other;
            }




            void Complex::operator*=(Complex &other)
            {
                
            this->real=(real*other.real-image*other.image);
                
            this->image=(image*other.real+real*other.image);;
            }


            void Complex::operator *=(const double &other)
            {

                
            this->real=real*other;
                
            this->image=image*other;
            }


            void Complex::operator *=(const int &other)
            {
                
            this->real=real*(double)other;
                
            this->image=image*(double)other;
            }



            void Complex::operator/=(Complex &other)
            {
                
            this->real=((real*other.real)+(image*other.image))/(other.real*other.real+other.image*other.image);
                
            this->image=((image*other.real)-(real*other.image))/(other.real*other.real+other.image*other.image);
            }


            void Complex::operator /=(const double &other)
            {

                
            this->real=real/other;
                
            this->image=image/other;
            }


            void Complex::operator /=(const int &other)
            {
                
            this->real=real/(double)other;
                
            this->image=image/(double)other;
            }


            Complex Complex::
            operator= (Complex &other)
            {

                
            this->real=other.real;
                
            this->image=other.image;
                
            return *this;

            }

            Complex Complex::
            operator =(const double &other)
            {
                
            this->real=other;
                
            this->image=image;
                
            return *this;


            }

            Complex Complex::
            operator =(const int &other)
            {
                
            this->real=(double)other;
                
            this->image=image;
                
            return *this;
            }



            bool Complex::operator ==(Complex &other)
            {

                
            if(this->real=other.real&&this->image==other.image)
                    
            return true;
                
            else return false;
            }

            bool Complex::operator ==(const double &other)
            {

                
            if(this->real==other&&this->image==0)
                    
            return true;
                
            else 
                    
            return false;
            }

            bool Complex::operator ==(const int &other)
            {
                
            if(this->real==(double)other&&this->image==0)
                    
            return true;
                
            else 
                    
            return false;
            }


            ostream
            & operator<<(ostream &os,Complex &other)
            {
                other.show();
                
            return cout;
            }


            istream
            & operator>>(istream &is,Complex &other)
            {
                
            is>>other.real;
                
            is>>other.image;
                
            return cin;
            }

            /**//**//**//////////////////////////////END_TEMPLATE_CLASS_COMPLEX///////////////////////////////









            int main()
            {
                Complex test1(
            10,6);
                Complex test2(
            5,3);
                cout
            <<test1*test2<<endl;
                cout
            <<test1+test2<<endl;
                cout
            <<test1/test2<<endl;
                cout
            <<test1-test2<<endl;
                
            return 0;
            }

            posted on 2009-05-29 21:39 abilitytao 閱讀(1745) 評論(0)  編輯 收藏 引用

            国产综合久久久久久鬼色| 国产一区二区精品久久凹凸| 久久国产精品无码一区二区三区| 国内精品久久久久影院一蜜桃| 情人伊人久久综合亚洲| 亚洲精品tv久久久久| 丁香狠狠色婷婷久久综合| 久久亚洲国产成人精品无码区| 久久夜色精品国产欧美乱| 深夜久久AAAAA级毛片免费看 | 精品久久香蕉国产线看观看亚洲| 国内精品久久久久久久久电影网| 精品国产99久久久久久麻豆| 国产成人精品久久一区二区三区av | 国产精品久久久久免费a∨| 香蕉久久夜色精品国产尤物| 精品久久久久久国产| 日本人妻丰满熟妇久久久久久| 亚洲国产精品无码久久九九| 精品久久久久久无码国产| AV无码久久久久不卡蜜桃| 综合网日日天干夜夜久久 | 天堂无码久久综合东京热| 久久久国产精品网站| 老色鬼久久亚洲AV综合| 久久久久久亚洲精品影院| 久久久久国产精品麻豆AR影院| 青草影院天堂男人久久| 久久99国产乱子伦精品免费| 国产精品久久久久久久app | 欧美熟妇另类久久久久久不卡| 国产一区二区久久久| 国内精品久久久久影院老司| 久久这里有精品视频| 久久久久这里只有精品| 国产精品99久久久久久猫咪| 青青青伊人色综合久久| 91麻精品国产91久久久久| 91久久精品国产成人久久| 午夜不卡888久久| 久久久久国产视频电影|