
complex类可以表示
并控制几个复数操作。我们来看一下如何表示和控制
显示复数。
imag()成员函数
如前所述,复数由实部和虚部两部分组成。
显示实部我们使用real()函数,使用imag()函数来显示 给定复数的虚部。在下一个例子中,我们取一个复数 number object, 初始化它,然后显示数字的实部和虚部 分别。语法
//displaying the imaginary part only
complex<double> c;
cout
<h3>算法</h3>
<ul class="list">
<li><p>拿一个新的复数对象。</p></li>
<li><p>使用'a. + ib'表示法为对象赋值。</p></li>
<li><p>使用imag()函数显示复数值的虚部。</p><div class="aritcle_card flexRow artxards">
<div class="artcardd flexRow">
<a class="aritcle_card_img" rel="nofollow" href="/ai/1856" title="稿定抠图"><img
src="https://img.php.cn/upload/ai_manual/000/000/000/175680148791985.png" alt="稿定抠图" onerror="this.onerror='';this.src='/static/lhimages/moren/morentu.png'" ></a>
<div class="aritcle_card_info flexColumn">
<a rel="nofollow" href="/ai/1856" title="稿定抠图" class="overflowclass">稿定抠图</a>
<p class="overflowclass">一款基于AI自动识别主体并移除图片背景的在线抠图工具,可快速制作透明背景素材和进行后续图片设计。</p>
</div>
<a rel="nofollow" href="/ai/1856" title="稿定抠图" class="aritcle_card_btn flexRow flexcenter"><b></b><span>下载</span>
</a>
</div>
</div></li>
</ul>
<h3>示例</h3>
<pre class="brush:cpp;toolbar:false;">#include <iostream>
#include <complex>
using namespace std;
//displays the imaginary part of the complex number
void display(complex <double> c){
cout solve( double real, double img ){
complex<double> cno(real, img);
return cno;
}
int main(){
complex<double> cno = 10.0 + 11i;
//displaying the complex number
cout
<h3>输出</h3>
<pre class="brush:php;toolbar:false;">The complex number is: 10+11i
The imaginary part of the complex number is: 11
需要注意的是,imag()函数只接受复数作为输入,并且
返回所提供复数的虚部。输出值为
复数对象的模板参数。
结论
对于科学领域广泛的许多不同操作,复杂的
numbers are required. An interface for representing complex numbers is provided by the C++复数类,它是头文件C++免费学习笔记(深入):立即使用
在学习笔记中,你将探索 C++ 的入门与实战技巧!










