• <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 (Beta 2.0)

            #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:37 abilitytao 閱讀(1243) 評論(5)  編輯 收藏 引用

            評論

            # re: Complex Class (Beta 2.0) 2009-05-29 23:01 playcpp

            STL中不是有complex類么,為什么要自己搞個。歡迎加入QQ群 36071431 討論C++問題。  回復  更多評論   

            # re: Complex Class (Beta 2.0)[未登錄] 2009-05-30 02:00 abilitytao

            @playcpp
            為了練習運算符重載 呵呵 這個理由怎么樣  回復  更多評論   

            # re: Complex Class (Beta 2.0) 2009-05-30 15:47 WindyWinter

            練運算符重載應該寫高精度計算。  回復  更多評論   

            # re: Complex Class (Beta 2.0)[未登錄] 2009-05-30 15:56 abilitytao

            @WindyWinter
            那個有點麻煩呢 呵呵 你知道高精度浮點類要怎么寫嗎?  回復  更多評論   

            # re: Complex Class (Beta 2.0) 2009-06-04 11:26 MC

            有些可以內聯調用,需要考慮除零問題,高精度浮點類搜索bcd  回復  更多評論   

            一本一本久久A久久综合精品| 久久99亚洲综合精品首页| 久久精品99无色码中文字幕| 久久99精品久久久久子伦| 久久人人爽人人人人爽AV| 日本亚洲色大成网站WWW久久| 激情久久久久久久久久| 国产福利电影一区二区三区久久老子无码午夜伦不 | 久久精品国产99国产精偷 | 久久久一本精品99久久精品88| 人妻无码精品久久亚瑟影视| 久久免费视频1| 国产亚洲精品久久久久秋霞 | 久久综合香蕉国产蜜臀AV| 亚洲AV无码久久精品蜜桃| 色偷偷88888欧美精品久久久| 97精品国产91久久久久久| 人人狠狠综合久久亚洲婷婷| 久久av免费天堂小草播放| 久久精品亚洲男人的天堂| 亚洲国产精品成人AV无码久久综合影院 | 亚洲精品无码久久久久AV麻豆| 中文精品99久久国产 | 精品久久久无码人妻中文字幕豆芽| 久久精品亚洲一区二区三区浴池| 色综合久久天天综合| 欧美精品一区二区久久| 亚洲精品蜜桃久久久久久| 色成年激情久久综合| 久久婷婷是五月综合色狠狠| 99热成人精品热久久669| 久久综合亚洲色HEZYO国产| 香蕉久久av一区二区三区| 亚洲国产精品久久久久网站| 欧美日韩精品久久久久| 国产精品久久国产精品99盘| 亚洲欧美国产精品专区久久| 久久国产免费观看精品| 久久久久免费精品国产| 久久99国产精品成人欧美| 精品久久久久久无码专区|