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

            日本精品一区二区久久久| 久久午夜无码鲁丝片| 国产精品无码久久综合网| 国产精品丝袜久久久久久不卡| 综合久久一区二区三区 | 国产精品久久久久久福利漫画| 久久国产精品99久久久久久老狼 | 亚洲精品国产综合久久一线| 亚洲欧美日韩中文久久 | 91精品国产色综合久久| 青青久久精品国产免费看| 97久久超碰国产精品旧版| 少妇久久久久久被弄高潮| 91久久精品91久久性色| 亚洲伊人久久综合影院| 久久精品国产99国产精品澳门| 久久综合亚洲色HEZYO社区| 国产成人综合久久综合| 狠狠色丁香久久婷婷综合_中 | 午夜精品久久久久久影视riav| 韩国免费A级毛片久久| 欧美精品乱码99久久蜜桃| 国产激情久久久久影院小草| 久久精品天天中文字幕人妻| 无码国内精品久久综合88| 久久精品成人一区二区三区| 女人香蕉久久**毛片精品| 国产精品一区二区久久不卡| 思思久久99热只有频精品66| 亚洲乱码日产精品a级毛片久久| 青青草国产成人久久91网| 97精品伊人久久大香线蕉app| 中文字幕无码精品亚洲资源网久久| 久久综合九色综合欧美就去吻 | 国产精品免费看久久久香蕉| 久久国产高清字幕中文| 国产69精品久久久久9999| 久久久久四虎国产精品| 久久综合中文字幕| 99久久精品免费看国产| 办公室久久精品|