最近2018中文字幕在日韩欧美国产成人片_国产日韩精品一区二区在线_在线观看成年美女黄网色视频_国产精品一区三区五区_国产精彩刺激乱对白_看黄色黄大色黄片免费_人人超碰自拍cao_国产高清av在线_亚洲精品电影av_日韩美女尤物视频网站

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
數(shù)據(jù)結(jié)構(gòu)(C語言描述)——復(fù)數(shù)-創(chuàng)新互聯(lián)

我們先創(chuàng)建一個有利于后續(xù)操作的頭文件,把預(yù)處理命令和一些常用的的宏(之后會用到)封裝在頭文件"StdFile.h"里面。

讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價值的長期合作伙伴,公司提供的服務(wù)項目有:域名與空間、虛擬主機、營銷軟件、網(wǎng)站建設(shè)、丘北網(wǎng)站維護、網(wǎng)站推廣。

以下為"StdFile.h"里面的信息:

#include#include#include#include#define _USE_MATH_DEFINES
#include#includeusing namespace std;
#define OK 1
#define ERROR 0
#define TRUE 1
#define FALSE 0
typedef long long ElemType;
typedef int Index;
typedef int Num;
typedef int Step;

之后對復(fù)數(shù)的基本定義:

typedef struct
{
?Real real;
?Imag imag;
}Complex;

再創(chuàng)建一個頭文件"Complex.h",里面存放關(guān)于復(fù)數(shù)的一些基本方法。

以下為"Complex.h"里面的信息:

#include "StdFile.h"
typedef long double Real, Imag;
typedef long double RealNum;

typedef struct
{
	Real real;
	Imag imag;
}Complex;

//創(chuàng)建復(fù)數(shù)
Complex CreateComplex(Real x = 0, Imag y = 0)
{
	Complex z = { 0,0 };
	z.real = x;
	z.imag = y;
	return z;
}

//打印復(fù)數(shù)
void PrintComplex(Complex z)
{
	if (z.real == 0)
		printf("j%.2llf\n", z.imag);
	else
		printf("%.2llf+j%.2llf\n", z.real, z.imag);
}

//獲取實部
RealNum RealComplex(Complex z)
{
	return z.real;
}

//獲取虛部
RealNum ImagComplex(Complex z)
{
	return z.imag;
}

//共軛復(fù)數(shù)
Complex ConjugateComplex(Complex z)
{
	Complex _z;
	_z.real = z.real;
	_z.imag = -z.imag;
	return _z;
}

//復(fù)數(shù)的模
RealNum AbsComplex(Complex z)
{
	RealNum r = 0;
	r = sqrt(z.real * z.real + z.imag * z.imag);
	return r;
}

//復(fù)數(shù)加法
Complex AddComplex(Complex z1, Complex z2)
{
	Complex z3 = { 0,0 };
	z3.real = z1.real + z2.real;
	z3.imag = z1.imag + z2.imag;
	return z3;
}

//復(fù)數(shù)減法
Complex SubComplex(Complex z1, Complex z2)
{
	Complex z3 = { 0,0 };
	z3.real = z1.real - z2.real;
	z3.imag = z1.imag - z1.imag;
	return z3;
}

//復(fù)數(shù)乘法
Complex MulComplex(Complex z1, Complex z2)
{
	Complex z3 = { 0,0 };
	z3.real = z1.real * z2.real - z1.imag * z2.imag;
	z3.imag = z1.real * z2.imag + z1.imag * z2.real;
	return z3;
}

//復(fù)數(shù)除法
Complex DivComplex(Complex z1, Complex z2)
{
	Complex z3 = { 0,0 };
	z3.real = (z1.real * z2.real + z1.imag * z2.imag) / (z2.real * z2.real + z2.imag * z2.imag);
	z3.imag = (z1.imag * z2.real - z1.real * z2.imag) / (z2.real * z2.real + z2.imag * z2.imag);
	return z3;
}

//復(fù)數(shù)的輻角
RealNum ArgComplex(Complex z)
{
	RealNum r;
	if (z.real >= 0 && z.imag == 0)
		r = 0;
	else if (z.real< 0 && z.imag == 0)
		r = M_PI;
	else if (z.real >= 0)
		r = atan(z.imag / z.real);
	else if (z.real< 0 && z.imag>0)
		r = atan(z.imag / z.real) + M_PI;
	else
		r = atan(z.imag / z.real) - M_PI;
	return r;
}

此方法不全,讀者可添加更多方法(比如復(fù)數(shù)的三角式,復(fù)數(shù)的指數(shù)式,復(fù)數(shù)的冪,復(fù)數(shù)的對數(shù),指數(shù)……)

以下為效果展示:

#include "Complex.h"
int main()
{
	Complex Z1, Z2, Z;
	Z = { 6,8 };
	Z1 = { 1,0 };
	Z2 = CreateComplex(2, 4);
	PrintComplex(Z1);
	PrintComplex(Z2);
	PrintComplex(AddComplex(Z1, Z2));
	cout<< "Z1+Z2的模 "<< AbsComplex(AddComplex(Z1, Z2))<< endl;
	cout<< "Z的實部 "<< RealComplex(Z)<< ' '<< "Z的虛部"<< ImagComplex(Z)<< endl;
	cout<< "打印Z/(Z1+Z2) ";
	PrintComplex(DivComplex(Z, AddComplex(Z1, Z2)));
	cout<< "Z的輻角主值 "<< ArgComplex(Z)<< endl;
}

顯示結(jié)果:

輻角主值以弧度制顯示,可能很難看出角度,優(yōu)化后可以把弧度轉(zhuǎn)化為角度:

//復(fù)數(shù)的輻角
RealNum ArgComplex(Complex z)
{
	RealNum r;
	if (z.real >= 0 && z.imag == 0)
		r = 0;
	else if (z.real< 0 && z.imag == 0)
		r = M_PI;
	else if (z.real >= 0)
		r = atan(z.imag / z.real);
	else if (z.real< 0 && z.imag>0)
		r = atan(z.imag / z.real) + M_PI;
	else
		r = atan(z.imag / z.real) - M_PI;
	return r/M_PI*180;
}

只需修改返回值即可。

修改后主函數(shù)的運行結(jié)果:

arctan(8/6)剛好就是53.1°,輻角顯示無誤。

以下是資源文件里面的文本文件"Help.Complex.txt"的內(nèi)容,為方法的使用大綱:

typedef struct
{
	Real real;
	Imag imag;
}Complex;

//創(chuàng)建復(fù)數(shù)
Complex CreateComplex(Real x = 0, Imag y = 0)

//打印復(fù)數(shù)
void PrintComplex(Complex z)

//獲取實部
RealNum RealComplex(Complex z)

//獲取虛部
RealNum ImagComplex(Complex z)

//共軛復(fù)數(shù)
Complex ConjugateComplex(Complex z)

//復(fù)數(shù)的模
RealNum AbsComplex(Complex z)

//復(fù)數(shù)加法
Complex AddComplex(Complex z1, Complex z2)

//復(fù)數(shù)減法
Complex SubComplex(Complex z1, Complex z2)

//復(fù)數(shù)乘法
Complex MulComplex(Complex z1, Complex z2)

//復(fù)數(shù)除法
Complex DivComplex(Complex z1, Complex z2)

//復(fù)數(shù)的輻角
RealNum ArgComplex(Complex z)

之后繼續(xù)更新關(guān)于順序表的相關(guān)方法。

你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機房具備T級流量清洗系統(tǒng)配攻擊溯源,準確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級服務(wù)器適合批量采購,新人活動首月15元起,快前往官網(wǎng)查看詳情吧


當(dāng)前文章:數(shù)據(jù)結(jié)構(gòu)(C語言描述)——復(fù)數(shù)-創(chuàng)新互聯(lián)
文章起源:http://fisionsoft.com.cn/article/ddedis.html