色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

asp.net(c#)復(fù)數(shù)類(復(fù)數(shù)加減乘除四則運(yùn)算)

我的一個Java作業(yè),把它改寫成ASP.NET(c#)了
復(fù)制代碼 代碼如下:
protected void Page_Load(object sender, EventArgs e)
    {
        complex complex_a = new complex(1.0, 1.0);
        complex complex_b = new complex(2.0, 2.0);
        Response.Write("加法運(yùn)算結(jié)果:" + complex_a.complex_add(complex_b).ToString() + "<br />");
        Response.Write("減法運(yùn)算結(jié)果:" + complex_a.complex_minus(complex_b).ToString() + "<br />");
        Response.Write("乘法運(yùn)算結(jié)果:" + complex_a.complex_multi(complex_b).ToString() + "<br />");
        Response.Write("除法運(yùn)算結(jié)果:" + complex_a.complex_divide(complex_b).ToString());
    }
    //design by 阿會楠 來自:搜索吧 sosuo8.com
    public class complex
    {
        //復(fù)數(shù)中的實(shí)部
        private double complex_real;
        //復(fù)數(shù)中的虛部
        private double complex_imagin;

        //構(gòu)造函數(shù)
        public complex(double r, double i)
        {
            complex_real = r;
            complex_imagin = i;
        }

        //重寫ToString()方法 
        public override string ToString()
        {
            return this.complex_real + "+" + this.complex_imagin + "i";
        }

        //復(fù)數(shù)加法運(yùn)算
        public complex complex_add(complex c)
        {
            //取得加法運(yùn)算后的實(shí)部
            double complex_real = this.complex_real + c.complex_real;

            //取得加法運(yùn)算后的虛部
            double complex_imagin = this.complex_imagin + c.complex_imagin;

            //返回一個復(fù)數(shù)類
             return new complex(complex_real,complex_imagin);
        }

        //復(fù)數(shù)減法運(yùn)算
        public complex complex_minus(complex c)
        {
            //取得減法運(yùn)算后的實(shí)部
            double complex_real = this.complex_real - c.complex_real;

            //取得減法運(yùn)算后的虛部
            double complex_imagin = this.complex_imagin - c.complex_imagin;

            //返回一個復(fù)數(shù)類
            return new complex(complex_real, complex_imagin);
        }

        //乘法運(yùn)算
        public complex complex_multi(complex c)
        {
            //取得乘法運(yùn)算后的實(shí)部
            double complex_real = this.complex_real * c.complex_real - this.complex_imagin * c.complex_imagin;

            //取得乘法運(yùn)算后的虛部
            double complex_imagin = this.complex_real * c.complex_imagin + this.complex_imagin * c.complex_real;

            //返回一個復(fù)數(shù)類
            return new complex(complex_real, complex_imagin);
        }

        //除法運(yùn)算結(jié)果 (a+bi)/(c+di)=(a+bi)(c-di)/(c+di)(c-di)
        public complex complex_divide(complex c)
        {
            //取得(c+di)(c-di)的值
            double d = c.complex_real * c.complex_real + c.complex_imagin * c.complex_imagin;

            //取得除法運(yùn)算后的實(shí)部
            double complex_real = (this.complex_real * c.complex_real + this.complex_imagin * c.complex_imagin) / d;

            //取得除法運(yùn)算后的虛部
            double complex_imagin = (this.complex_real * (-c.complex_imagin) + this.complex_imagin * c.complex_real) / d;

            //返回一個復(fù)數(shù)類
            return new complex(complex_real, complex_imagin);
        }
    }


運(yùn)行結(jié)果:

復(fù)制代碼 代碼如下:
加法運(yùn)算結(jié)果:3+3i  
減法運(yùn)算結(jié)果:-1+-1i  
乘法運(yùn)算結(jié)果:0+4i  
除法運(yùn)算結(jié)果:0.5+0i 

AspNet技術(shù)asp.net(c#)復(fù)數(shù)類(復(fù)數(shù)加減乘除四則運(yùn)算),轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 云梦县| 南乐县| 成武县| 大洼县| 久治县| 中山市| 定州市| 河间市| 威信县| 志丹县| 博湖县| 海门市| 徐水县| 龙南县| 新巴尔虎右旗| 上饶县| 隆尧县| 枣庄市| 廉江市| 陈巴尔虎旗| 绍兴县| 海门市| 陇西县| 宁夏| 宁乡县| 绵阳市| 如皋市| 嘉峪关市| 连山| 文化| 达州市| 乐平市| 灵丘县| 昭觉县| 扬中市| 福建省| 新津县| 堆龙德庆县| 泌阳县| 潢川县| 平凉市|