• <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

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

            Complex Class (Beta 2.0)

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


            //本模板在VS2005下可正常運(yùn)行
            /*//////////////////////////////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) 評(píng)論(5)  編輯 收藏 引用

            評(píng)論

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

            STL中不是有complex類么,為什么要自己搞個(gè)。歡迎加入QQ群 36071431 討論C++問(wèn)題。  回復(fù)  更多評(píng)論   

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

            @playcpp
            為了練習(xí)運(yùn)算符重載 呵呵 這個(gè)理由怎么樣  回復(fù)  更多評(píng)論   

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

            練運(yùn)算符重載應(yīng)該寫(xiě)高精度計(jì)算。  回復(fù)  更多評(píng)論   

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

            @WindyWinter
            那個(gè)有點(diǎn)麻煩呢 呵呵 你知道高精度浮點(diǎn)類要怎么寫(xiě)嗎?  回復(fù)  更多評(píng)論   

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

            有些可以內(nèi)聯(lián)調(diào)用,需要考慮除零問(wèn)題,高精度浮點(diǎn)類搜索bcd  回復(fù)  更多評(píng)論   


            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


            91精品国产高清久久久久久io| 久久人爽人人爽人人片AV| 国内精品久久国产| 久久人妻无码中文字幕| 天堂久久天堂AV色综合 | 伊人久久大香线蕉综合网站| 亚洲欧美久久久久9999| 久久精品国产亚洲av高清漫画| 无码日韩人妻精品久久蜜桃| 久久精品成人国产午夜| 国产女人aaa级久久久级| 中文字幕热久久久久久久| 久久精品国产亚洲av高清漫画 | 国产精品欧美亚洲韩国日本久久| 久久国产精品成人免费| 日韩亚洲国产综合久久久| 久久精品国产清高在天天线| 久久久久亚洲AV成人网人人网站| 思思久久99热只有频精品66| 国产精品久久久久久搜索| 久久亚洲高清综合| 国产成人精品免费久久久久| 久久无码专区国产精品发布| 91久久国产视频| 久久av无码专区亚洲av桃花岛| 亚洲精品乱码久久久久久蜜桃| 国产精品美女久久久久| 国产精品久久久久蜜芽| 久久精品国产半推半就| 久久久久久国产精品无码超碰| 色天使久久综合网天天| 女同久久| 久久久久久毛片免费看| 88久久精品无码一区二区毛片 | 模特私拍国产精品久久| 91久久香蕉国产熟女线看| 亚洲国产精品无码久久98| 日韩欧美亚洲综合久久影院Ds | 2021最新久久久视精品爱| 久久一区二区三区免费| 久久综合九色综合欧美就去吻|