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

            復(fù)數(shù)類(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;
            }



            不知道是人品問題還是其他什么因素,當(dāng)我把real和image放在私有成員里面時(shí)編譯居然會(huì)報(bào)錯(cuò)???我已經(jīng)將>>和<<重載為友元函數(shù)了丫?
            我試了下網(wǎng)上和我寫的差不多的程序,結(jié)果是他的能過(guò)我的 就是不行,而出問題的<<,>>部分居然還是一樣的。我...無(wú)語(yǔ)了...究竟是怎么回事?

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

            評(píng)論

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

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

            很明顯返回丟失了 &
            成了另外一個(gè)函數(shù)的友元聲明了

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


              回復(fù)  更多評(píng)論   

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

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

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

            @zhaoyg
            按照你的方法 終于過(guò)編譯了 謝謝:-)  回復(fù)  更多評(píng)論   


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


            国产99精品久久| 久久香蕉超碰97国产精品| 久久人人爽人人爽人人片AV东京热| 久久婷婷国产麻豆91天堂| 久久精品视频网| 狠狠精品久久久无码中文字幕 | 久久综合亚洲色HEZYO社区| 午夜精品久久久久| 久久久久亚洲av成人网人人软件| 亚洲va中文字幕无码久久不卡| 老色鬼久久亚洲AV综合| 久久最新精品国产| 久久久久久久国产免费看| 99久久这里只精品国产免费| 久久精品国产网红主播| 久久美女网站免费| 久久综合久久性久99毛片| 久久精品国产乱子伦| 成人国内精品久久久久一区 | 久久天天躁夜夜躁狠狠躁2022| 一本一本久久a久久综合精品蜜桃| 久久成人国产精品| 精品久久久久久无码国产| 人人妻久久人人澡人人爽人人精品| 狼狼综合久久久久综合网| 狠狠人妻久久久久久综合蜜桃| 久久精品日日躁夜夜躁欧美| 国产精品久久久久影院色| 开心久久婷婷综合中文字幕| 奇米影视7777久久精品| 国产999精品久久久久久| 国产精品久久久久蜜芽| 亚洲狠狠久久综合一区77777| 合区精品久久久中文字幕一区| 久久久精品国产sm调教网站| 久久久久18| 精品久久久久久无码中文字幕一区 | 97精品依人久久久大香线蕉97 | 热久久这里只有精品| 亚洲欧美一区二区三区久久| 精品久久久无码人妻中文字幕豆芽 |