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

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

            復數類(Comlex Class)

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


            /////////////////////////////Complex Class///////////////////////////////////////
            class Complex
            {
            private:
                
            //double real;
                
            //double image;
                
            //void show();
            public:
                
            void show();
                
            double real;
                
            double image;
                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 iostream 
            operator<<(iostream &os,Complex &other);
                friend iostream 
            operator>>(iostream &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 &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 &cout,Complex &other)
            {
                other.show();
                
            return cout;
            }


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

            /////////////////////////////END_COMPLEX_CLASS///////////////////////////////















            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;
            }



            不知道是人品問題還是其他什么因素,當我把real和image放在私有成員里面時編譯居然會報錯???我已經將>>和<<重載為友元函數了丫?
            我試了下網上和我寫的差不多的程序,結果是他的能過我的 就是不行,而出問題的<<,>>部分居然還是一樣的。我...無語了...究竟是怎么回事?

            posted on 2009-05-29 20:46 abilitytao 閱讀(1887) 評論(3)  編輯 收藏 引用

            評論

            # re: 復數類(Comlex Class) 2009-05-29 21:09 Pterosaur

            friend iostream operator<<(iostream &os,Complex &other);
            friend iostream operator>>(iostream &is,Complex &other);

            很明顯返回丟失了 &
            成了另外一個函數的友元聲明了

            改成這樣:
            friend iostream& operator<<(iostream &os,Complex &other);
            friend iostream& operator>>(iostream &is,Complex &other);


              回復  更多評論   

            # re: 復數類(Comlex Class) 2009-05-29 21:38 zhaoyg

            VC6下,我記得,
            <iostream.h> 且去掉using編譯
            這樣才能使用友元  回復  更多評論   

            # re: 復數類(Comlex Class) 2009-05-29 21:50 abilitytao

            @zhaoyg
            按照你的方法 終于過編譯了 謝謝:-)  回復  更多評論   

            久久久久高潮综合影院| 色综合久久最新中文字幕| 久久久久国产一区二区 | 久久男人中文字幕资源站| 久久超乳爆乳中文字幕| 亚洲精品无码久久久久久| 久久久久亚洲AV无码专区首JN| 久久精品国产亚洲一区二区三区 | 97久久婷婷五月综合色d啪蜜芽 | 国产成人久久精品麻豆一区| av无码久久久久不卡免费网站| 狠狠综合久久AV一区二区三区| 欧美麻豆久久久久久中文| 色天使久久综合网天天| 久久亚洲国产成人影院网站| 久久综合成人网| 亚洲国产成人精品无码久久久久久综合 | 亚洲а∨天堂久久精品9966| 亚洲国产日韩欧美久久| 久久婷婷午色综合夜啪| 无码AV波多野结衣久久| 久久婷婷五月综合97色| 国产日产久久高清欧美一区| 国产精品美女久久久久AV福利| 久久精品国产亚洲Aⅴ香蕉| 思思久久99热只有频精品66| 中文字幕热久久久久久久| 久久天天躁狠狠躁夜夜avapp| 精品999久久久久久中文字幕 | 欧美伊香蕉久久综合类网站| 亚洲一区二区三区日本久久九| 久久久久亚洲av成人无码电影| 久久久亚洲欧洲日产国码是AV| 国产精品女同久久久久电影院| 99久久国产综合精品成人影院| 久久久久亚洲精品天堂久久久久久 | 蜜臀av性久久久久蜜臀aⅴ麻豆 | 久久99精品国产麻豆宅宅| 18岁日韩内射颜射午夜久久成人 | 狠狠色丁香久久婷婷综合_中| 欧美亚洲色综久久精品国产|