asp.net(c#)復(fù)數(shù)類(復(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;
}
//重寫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ù)類
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ù)類
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ù)類
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ù)類
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)文章
DataTable轉(zhuǎn)成字符串復(fù)制到txt文本的小例子
DataTable轉(zhuǎn)成字符串復(fù)制到txt文本的小例子,需要的朋友可以參考一下2013-03-03asp.net fileupload 實(shí)現(xiàn)上傳
在vs的視圖模式下,添加上傳組件,以及添加一個(gè)按鈕button,隨后在后置代碼中加入如下信息2009-05-05asp.net Linq to Xml學(xué)習(xí)筆記
之前都沒(méi)有學(xué)習(xí)過(guò)關(guān)于XML文件的操作,由于最近開(kāi)發(fā)的項(xiàng)目需要用到,開(kāi)始時(shí)學(xué)習(xí)了原始的XML文件操作方法,看了半天,也看的頭暈眼花,沒(méi)學(xué)習(xí)到真正的用法,后來(lái)在同事的推薦下學(xué)習(xí)了Linq to Xml2010-03-03Asp.net 基于Cookie簡(jiǎn)易的權(quán)限判斷
基于Cookie簡(jiǎn)易的權(quán)限判斷代碼,需要的朋友可以參考下。2010-01-01.NET/ASP.NET Routing路由(深入解析路由系統(tǒng)架構(gòu)原理)
這篇文章主要介紹了.NET/ASP.NET Routing路由(深入解析路由系統(tǒng)架構(gòu)原理),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-07-07ASP.NET中將聲音文件添加到資源中并進(jìn)行播放的方法
這篇文章主要介紹了ASP.NET中將聲音文件添加到資源中并進(jìn)行播放的方法,實(shí)例分析了聲音文件的添加及播放實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-07-07Asp.net(C#)讀取數(shù)據(jù)庫(kù)并生成JS文件制作首頁(yè)圖片切換效果(附demo源碼下載)
這篇文章主要介紹了Asp.net(C#)讀取數(shù)據(jù)庫(kù)并生成JS文件制作首頁(yè)圖片切換效果的方法,涉及asp.net數(shù)據(jù)庫(kù)操作及JavaScript幻燈片生成的相關(guān)技巧,并附帶demo源碼供讀者下載參考,需要的朋友可以參考下2016-04-04使用FreeHost SQL2000網(wǎng)頁(yè)管理器出錯(cuò)解決辦法
在您登陸FreeHost SQL2000網(wǎng)頁(yè)管理器時(shí),如果提示以下信息: 發(fā)生類型為 System.Web.HttpUnhandledException 的異常2012-01-01在dropDownList中實(shí)現(xiàn)既能輸入一個(gè)新值又能實(shí)現(xiàn)下拉選的代碼
在dropDownList中實(shí)現(xiàn)既能輸入一個(gè)新值,又能實(shí)現(xiàn)下拉選項(xiàng),想必很多的朋友已經(jīng)為此功能按耐不住了吧,接下來(lái)與大家分享下如何實(shí)現(xiàn),感興趣的朋友可以參考下哈2013-04-04