• <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 閱讀(1885) 評論(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
            按照你的方法 終于過編譯了 謝謝:-)  回復  更多評論   

            久久AAAA片一区二区| 热久久国产精品| 一本久久免费视频| 久久久久亚洲AV无码专区网站| 99热成人精品热久久669| 精品久久久久久亚洲精品 | 精品久久久久久无码人妻蜜桃| avtt天堂网久久精品| 国内精品久久九九国产精品| 99久久99久久| 久久精品人妻一区二区三区| 久久精品国产一区二区电影| 久久久WWW成人免费毛片| 国内精品久久国产| 久久国产亚洲精品无码| 精品午夜久久福利大片| 狠狠精品干练久久久无码中文字幕 | 欧美激情精品久久久久久| 午夜精品久久久久久久无码| 漂亮人妻被中出中文字幕久久| 熟妇人妻久久中文字幕| 精品久久一区二区| 久久久午夜精品| 精品久久久噜噜噜久久久| 久久久久亚洲?V成人无码| 久久久久亚洲av综合波多野结衣| 性欧美丰满熟妇XXXX性久久久 | 久久精品国产2020| 亚洲综合久久综合激情久久| 久久99精品免费一区二区| 色狠狠久久AV五月综合| 国产99久久久久久免费看| 亚洲va久久久噜噜噜久久狠狠| 97精品伊人久久久大香线蕉 | 性做久久久久久久| 久久久WWW成人免费毛片| 国产精品久久午夜夜伦鲁鲁| 无夜精品久久久久久| 91麻精品国产91久久久久| 久久精品国产亚洲AV无码麻豆 | 国产亚洲欧美成人久久片|