
complex类可以表示
并控制几个复数操作。我们来看一下如何表示和控制
显示复数。
imag()成员函数
如前所述,复数由实部和虚部两部分组成。
显示实部我们使用real()函数,使用imag()函数来显示 给定复数的虚部。在下一个例子中,我们取一个复数 number object, 初始化它,然后显示数字的实部和虚部 分别。语法
//displaying the imaginary part only complexc; cout << imag(c) << endl;
算法
拿一个新的复数对象。
使用'a. + ib'表示法为对象赋值。
-
使用imag()函数显示复数值的虚部。
立即学习“C++免费学习笔记(深入)”;
WeWedding婚纱影楼小程序下载婚纱影楼小程序提供了一个连接用户与影楼的平台,相当于影楼在微信的官网。它能帮助影楼展示拍摄实力,记录访客数据,宣传优惠活动。使用频率高,方便传播,是影楼在微信端宣传营销的得力助手。功能特点:样片页是影楼展示优秀摄影样片提供给用户欣赏并且吸引客户的。套系页是影楼根据市场需求推出的不同套餐,用户可以按照自己的喜好预定套系。个人中心可以查看用户预约的拍摄计划,也可以获取到影楼的联系方式。
示例
#include#include using namespace std; //displays the imaginary part of the complex number void display(complex c){ cout << "The imaginary part of the complex number is: "; cout << imag(c) << endl; } //initializing the complex number complex solve( double real, double img ){ complex cno(real, img); return cno; } int main(){ complex cno = 10.0 + 11i; //displaying the complex number cout << "The complex number is: " << real(cno) << '+' << imag(cno) << 'i' << endl; display(cno); return 0; }
输出
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++复数类,它是头文件










