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

            国产精品久久久久久久| 99久久99久久精品国产片果冻| 亚洲国产精品成人久久| 久久国产免费观看精品3| 久久99精品九九九久久婷婷| 久久久午夜精品| 久久美女人爽女人爽| 久久99热这里只频精品6| 久久电影网一区| 日产精品久久久久久久性色| 久久99精品久久久久久野外 | 久久久精品久久久久久| 天天躁日日躁狠狠久久| 日韩欧美亚洲国产精品字幕久久久| 亚洲国产精品无码久久| 四虎久久影院| 国产99久久久国产精品~~牛| 亚洲va久久久噜噜噜久久狠狠| 欧美激情精品久久久久久| 久久久久久综合一区中文字幕| 无码AV波多野结衣久久| 国产偷久久久精品专区| 亚洲v国产v天堂a无码久久| 93精91精品国产综合久久香蕉| 久久精品中文无码资源站| 狠狠精品久久久无码中文字幕 | 国产精品九九久久精品女同亚洲欧美日韩综合区 | 精品久久久久久中文字幕大豆网| 精品综合久久久久久97超人| 欧美一区二区三区久久综合| 久久精品国产99国产精品导航| 人妻无码久久精品| 2021最新久久久视精品爱| 婷婷国产天堂久久综合五月| 亚洲午夜精品久久久久久浪潮| 欧美激情精品久久久久久久九九九| 26uuu久久五月天| 久久毛片免费看一区二区三区| 久久久精品久久久久特色影视| 久久久无码精品亚洲日韩软件| 亚洲欧洲久久久精品|