asp.net(c#)復(fù)數(shù)類(lèi)(復(fù)數(shù)加減乘除四則運(yùn)算)
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 阿會(huì)楠 來(lái)自:搜索吧 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;
}
//重寫(xiě)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;
//返回一個(gè)復(fù)數(shù)類(lèi)
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;
//返回一個(gè)復(fù)數(shù)類(lèi)
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;
//返回一個(gè)復(fù)數(shù)類(lèi)
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;
//返回一個(gè)復(fù)數(shù)類(lèi)
return new complex(complex_real, complex_imagin);
}
}
運(yùn)行結(jié)果:
加法運(yùn)算結(jié)果:3+3i
減法運(yùn)算結(jié)果:-1+-1i
乘法運(yùn)算結(jié)果:0+4i
除法運(yùn)算結(jié)果:0.5+0i
相關(guān)文章
Visual Studio Debugger七個(gè)鮮為人知的小功能
這篇文章主要為大家詳細(xì)介紹了Visual Studio Debugger七個(gè)鮮為人知的小功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06
ASP.NET?MVC使用jQuery的Load方法加載靜態(tài)頁(yè)面及注意事項(xiàng)
這篇文章介紹了ASP.NET?MVC使用jQuery加載靜態(tài)頁(yè)面的方法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-09-09
.NET Core 實(shí)現(xiàn)微信小程序支付功能(統(tǒng)一下單)
最近公司研發(fā)了幾個(gè)電商小程序,還有一個(gè)核心的電商直播,只要是電商一般都會(huì)涉及到交易信息,離不開(kāi)支付系統(tǒng),這里我們統(tǒng)一實(shí)現(xiàn)小程序的支付流程。感興趣的朋友跟隨小編一起看看吧2019-09-09
asp.net實(shí)現(xiàn)生成縮略圖及給原始圖加水印的方法示例
這篇文章主要介紹了asp.net實(shí)現(xiàn)生成縮略圖及給原始圖加水印的方法,結(jié)合具體實(shí)例形式分析了asp.net圖片的縮略圖與水印操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2017-10-10
ASP.NET MVC分頁(yè)的實(shí)現(xiàn)方法
這篇文章主要為大家詳細(xì)介紹了ASP.NET MVC分頁(yè)的實(shí)現(xiàn)方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-03-03
asp.net 操作XML 按指定格式寫(xiě)入XML數(shù)據(jù) WriteXml
從SQL下載數(shù)據(jù)到本地為XML文件2009-07-07
asp.net 讀取并修改config文件實(shí)現(xiàn)代碼
讀取并修改 config 文件的asp.net代碼,方便我們用asp.net修改配置文件。2009-11-11
.net?core?刪除字符串最后一個(gè)字符的七大類(lèi)N種實(shí)現(xiàn)方式(總結(jié)篇)
本文詳細(xì)介紹了七大類(lèi)、N種不同的方法來(lái)刪除字符串的最后一個(gè)字符,涵蓋了從簡(jiǎn)單的字符串方法到使用StringBuilder、數(shù)組操作、Linq以及正則表達(dá)式等多種技術(shù)手段,本文給大家介紹.net?core刪除字符串最后一個(gè)字符,感興趣的朋友一起看看吧2024-10-10

