网友您好, 请在下方输入框内输入要搜索的题目:

题目内容 (请给出正确答案)

对Complex类进行运算符重载,支持复数之间,复数与double之间的计算,包括: (1) +,-, *, / (2) ==, != (3)+=,-=,*=,/= (4)double赋值给复数 (5)重载“~”运算符,获得共轭复数(实部相等,虚部符号相反) (6)+(正号)、-(负号) (7)重载“!”运算符,获得复数的模


参考答案和解析
AA。【解析】C++不仅可以对运算符进行重载,还可以重载类型转换符,函数声明的形式为:0perato
更多 “对Complex类进行运算符重载,支持复数之间,复数与double之间的计算,包括: (1) +,-, *, / (2) ==, != (3)+=,-=,*=,/= (4)double赋值给复数 (5)重载“~”运算符,获得共轭复数(实部相等,虚部符号相反) (6)+(正号)、-(负号) (7)重载“!”运算符,获得复数的模” 相关考题
考题 下面是复数类 complex 的定义 , 其中重载的运算符 “ + ” 的功能是返回一个新的复 数对象 , 其实部等于两个操作对象实部之和,其虚部等于两个操作对象虚部之和;请补充完整:class complex{double real; // 实部double imag; // 虚部public:complex(double r,double i):real(r),imag(i){}complex operator+(complex a){return complex( 【 14 】 );}};

考题 阅读以下程序说明和C++程序,将程序段中(1)~(5)空缺处的语句填写完整。【说明】以下【C++程序】实现一个简单的小型复数类MiniComplex,该复数类能进行输入、输出、复数的加法、减法、乘法和除法运算,还可以进行复数的相等比较。【C++程序】ifndef H_MiniComplexdefine H_MiniComplexinclude <iostream>using namespace std;class MiniComplex{public: //重载流插入和提取运算符(1) ostreamoperator<<(ostream osObject,const MiniComplexcomplex){osObject<<"("<<complex.realPart<<"+"<<complex.imagPart<<"i"<<")";return osObject;}(2) istreamoperator>>(istreamisObject, MiniComplexcomplex){char ch;isObject >>complex.realPart>>ch>>complex.imagPart>>ch;return isObject;}MiniComplex(double real=0,double imag=0); //构造函数MiniComplex operator+(const MiniComplexotherComplex)const; //重载运算符+MiniComplex operator-(const MiniComplexotherComplex)const; //重载运算符-MiniComplex operator*(const MiniComplexotherComplex)const; //重载运算符*MiniComplex operator/(const MiniComplexotherComplex)const; //重载运算符/bool perator==(const MiniComplexotherComplex)const; //重载运算符==private :double (3);double imagPart;};end ifinclude "MiniComplex.h"bool MiniComplex::operator==(const MiniComplexotherComplex)const{return(realPart==otherComplex.realPartimagPart==ortherComplex.imagPart);}MiniComplex::MiniComplex(double real,double imag){realPart== real; imagPart==imagPart;}MiniComplex MiniComplex::operator+(const MiniComplexotherComplex)const{MiniComplex temp;temp.realPart = realPart+ortherComplex. realPart;temp.imagPart = imagPart +ortherComplex. imagPart;return temp;}(4){ MiniComplex temp;temp.realPart= realPart-ortherComplex. realPart;temp.imagPart = imagPart-ortherComplex. imagPart;return temp;}MiniComplex MiniComplex::operator*(const MiniComplexotherComplex)const{MiniComplex temp;temp.realPart = (realPart*ortherComplex. realPart)-(imagPart *ortherComplex.imagPart);temp.imagPart = (realPart*ortherComplex. imagPart)+(imagPart *ortherComplex.realPart);return temp;}MiniComplex MiniComplex::operator/(const MiniComplexotherComplex)const{MiniComplex temp;float tt;tt=1/(ortherComplex.realPart*ortherComplex.realPart+ortherComplex.imagPart *ortherComplex. imagPart);temp.realPart=((realPart*ortherComplex, realPart)+(imagPart *ortherComplex. imagPart))*tt;temp.imagPart =((imagPart *ortherComplex. realPart)-(realPart*ortherComplex. imagPart))*tt;return temp;}include <iostream>include <MiniComplex.h>using namespace std;int main(){MiniComplex numl(23, 34),num2(56, 35);cout<<"Initial Value of num1="<<num1<<"\n Initial Value of num2="<<num2<<end1;cout<<num1<<"+"<<num2<<"="<<num1+num2<<end1; //使用重载的加号运算符cout<<num1<<"-"<<num2<<"="<<num

考题 下列关于运算符重载的描述中,正确的是A.运算符重载可以改变操作数的个数B.运算符重载可以改变运算符的优先级C.运算符重载可以改变运算符的结合性D.运算符重载可以使运算符实现特殊功能

考题 ( 13 )有如下复数类的声明,请补充完整。class complex{double real; // 实部double imag; // 虚部public:complex(double x , double y){real=x;imag=y;}perator+(complex c){// 重载加法运算符 “ + ”return complex(___________)}};

考题 ( 24 )下列关于运算符重载的描述中,错误的是A )可以通过运算符重载在 C++ 中创建新的运算符B )赋值运算符只能重载为成员函数C )运算符函数重载为类的成员函数时,第一操作数是该类对象D )重载类型转换运算符时不需要声明返回类型

考题 下列关于运算符重载不正确的是( )。A.运算符重载不能改变运算符的操作数个数B.运算符重载不能改变运算符的优先级C.运算符重载不能改变运算符的结合性D.运算符重载能改变对预定义类型数据的操作方式

考题 在重载一个运算符时,其参数表中没有任何参数,这表明该运算符是()。A、作为友元函数重载的1元运算符B、作为成员函数重载的1元运算符C、作为友元函数重载的2元运算符D、作为成员函数重载的2元运算符

考题 下面关于自定义类的运算符重载的说法中,正确的是()。 A.类友元形式重载的运算符,重载函数的参数个数与运算符的实际操作数个数相同B.类友元形式重载的运算符,重载函数中的this指针指向第一个运算数C.类友元形式重载的运算符,重载函数中可以直接访问类中的私有成员D.所有运算符都可以以类友元形式进行重载

考题 下列关于运算符重载的描述中,错误的是( )。A.可以通过运算符重载在C++中创建新的运算符 下列关于运算符重载的描述中,错误的是( )。A.可以通过运算符重载在C++中创建新的运算符B.赋值运算符只能重载为成员函数C.运算符函数重载为类的成员函数时,第一操作参数就是该类对象D.重载类型转换运算符时不需要声明返回类型

考题 阅读以下说明和Java 码,将应填入(n)处的字名写在的对应栏内。[说明] 编写一个完整的JavaApplet 程序使用复数类Complex 验证两个复数1+2i 和3+4i 相加产生一个新的复数4+6i。复数类Complex 必须满足如下要求:(1) 复数类Complex 的属性有:RealPart: int 型,代表复数的实数部分ImaginPart: int 型,代表复数的虚数部分(2) 复数类Complex 的方法有:Complex():构造函数,将复数的实部和虚部都置0Complex (intr,inti):构造函数,形参r为实部的初值,i为虚部的初值。ComplexeomplexAdd (Complexa):将当前复数对象与形参复数对象相加,所得的结果仍是一个复数值,返回给此方法的调用者String ToString():把当前复数对象的实部、虚部组合成s+ bi 的字符串形式,其中a和b分别为实部和虚部的数据。importjava. applet. * ;importjava. awt. * ;publicclassabcextends Applet{Complex a, b, c;publi cvoid init( ){a = newComplex(1,2);b = newComplex(3,4);c = newComplex();}publievoidpaint (Graphicsg){(1)g. drawstring( “第一个复数:” + a. toString(), 10,50);g. drawstring( “第二个复数:” + b. toString( ), 10,70 );g. drawstring( “两复之和:” + c. toString( ), 10,90);}}class Complex{int RealPart;int ImaginPart;Complex( ) { (2) }Complex( intr , inti){ (3) }ComplexeomplexAdd (Complexa){Complextemp = newComplex( );temp. BealPart = RealPart + a. BealPart;(4)returntemp;}public StringtoString( ){ return( RealPart + " + " + ImaginPart + " i "); }}

考题 多数运算符既能作为类的成员函数重载,也能作为类的非成员函数重载,但运算符[]只能作为类的______函数重载。

考题 为类Matrix重载下列运算符号时,只能作为Matrix类成员函数重载的运算符是( )。A.+B.=C.D.++

考题 下面是复数类complex的定义,其中作为友元函数重载的运算符“--”的功能是将参数对象的实部减1,然后返回对该对象的引用;请补充完整。class complex{private:int real;int imag;public:complex(int r=0,int i=0):real(r),imag(i){}void show (){cout<<real<<(imag<0?"-":"+")<<imag<<'i';}______;};complex operator -- (complex c){c.real --;return c;}

考题 阅读以下说明和C++代码(代码13-1),将应填入(n)处的字句写在对应栏内。【说明】软件设计师东方飞龙利用UML设计了一个迷你小型复数类,其类图如图13-11所示。【代码13-l】/*___________________________________*//********* 文件 MiniComplex. h*********//*___________________________________*/include<iostream>using namespace std;class MiniComplex{(1)://重载流插入和提取运算符(2) ostream operator <<(ostream osObject, const MiniComplex complex){ osObject <<"("<<complex. realPart<<"+"<<complex. imagPart <<"I"<<")";return osObject;}friend (3) operator >>(istream isObject, MiniComplex complex){ char ch;isObject >>complex. realPart >>ch>>complex. imagPart >>ch;return isObject;}MiniComplex(double real=0, double imag=0); //构造函数MiniComplex operator+(const MiniComplex otherComplex)const! //重载运算符+MiniComplex operator--(const MiniComplex otherComplex)const! //重载运算符-MiniComplex operator*(const MiniComplex othmComplex)const; //重载运算符*MiniComplex operator/(const MiniComplex otherComplex)const; //重载运算符/bool perator==(const MiniComplex otherComplex)const; //重载运算符==private:double realPart; //存储实部变量double imagPart; //存储虚部变量};/*_______________________________________________________*//* * * * * * * * *文件 MiniComplex. cpp* * * * * * * * * *//*_______________________________________________________*/include "MiniComplex.h"bool MiniComplex:: perator==(const MiniComplex otherComplex)const{ (1);}MiniComplex:: MiniComplex(double real, double imag){realPart=real;imagPart=imag!}MiniComplex MiniComplex:: operator+(const MiniComplex otherComplex)const{ MiniComplex temp;temp. realPart=realPart+ otherComplex. realPart;temp. imagPart=imagPart+ otherComplex. imagPart;return temp;}MiniComplex MiniComplex::operator--(const MiniComplex otherComplex)const{ MiniComplex temp;temp.realPart=realPart-otherComplex.realPart;temp. imagPart=imagPart-otherCompler.imagPart;return temp;}MiniComplex MiniComplex:: operator*(const MiniComplex otherComplex)const{ MiniComplex temp;temp.realPart=(realPart* otherComplex.realPart)-(imag-Part* otherComplex.imag-Part);temp imagPart=(realPart* otherComplex. imagPart)+(imag-Part *otherComplex.realPart);return temp,}MiniComplex MiniComplex:: operator/(const MiniComplex otherComplex)eonst{ MiniComplex temp;float tt;tt=1/(otherComplex. realPart *otherComplex. realPart+otherComplex. imagPart* other Complex.imagPart);temp. realPart=((realPart* otherComplex.realPart)+(imagPart* otherComplex.imagPart))*tt;temp. imagPart=((imagPart * otherComplex.realPart)-(realPart* otherComplex.imagPart))*tt;

考题 运算符重载是对已有的运算符赋予多重的含义,所以( )。A.能够对基本类型数据(如double),重新定义"+"运算符的含义B.只能重载C++中己经有的运算符,不能重新定义新运算符C.能够改变一个已有运算符的优先级和操作数个数D. C++中现有的所有运算符都可以重载

考题 有如下的运算符重载函数定义:double operator+(int i,int k){return double (i+ k);}但定义有错误,对这个错误最准确的描述是( )。A.“+”只能作为成员函数重载,而这里的“+”是作为非成员函数重载的B.两个int型参数的和也应该是int型,而这里将“+”的返回类型声明为doubleC.没有将运算符重载函数声明为某个类的友元D.C++已经提供了求两个int型数据之和的运算符+,不能再定义同样的运算符

考题 下列关于运算符重载的描述中,错误的是()。A、运算符重载不改变优先级B、运算符重载后,原来运算符操作不可再用C、运算符重载不改变结合性D、运算符重载函数的参数个数与重载方式有关

考题 下列关于运算符重载的描述中,()是正确的。A、运算符重载可以改变运算数的个数B、运算符重载可以改变优先级C、运算符重载可以改变结合性D、运算符重载不可以改变语法结构

考题 下列对运算符重载的描述中,正确的是()A、运算符重载可以改变结合性B、运算符重载可以改变优先级C、运算符重载可以改变操作数的个数D、运算符重载不改变优先级和结合性

考题 C++支持运算符重载,所有运算符都可以重载

考题 下列关于运算符重载的描述中,正确的是()。A、运算符重载可以改变操作数的个数B、运算符重载可以改变运算符的优先级C、运算符重载可以改变运算符的结合性D、运算符重载可以使运算符实现特殊功能

考题 单选题下列关于运算符重载的描述中,正确的是(  )。A 运算符重载为成员函数时,若参数表中无参数,重载的是一元运算符B 一元运算符号能作为成员函数重载C 二元运算符重载为非成员函数时,参数表中有一个参数D C++中可以重载所有的运算符

考题 单选题下列关于运算符重载的描述中,错误的是(  )。A 可以通过运算符重载在C++中创建新的运算符B 赋值运算符只能重载为成员函数C 运算符函数重载为类的成员函数时,第一操作数是该类对象D 重载类型转换运算符时不需要声明返回类型

考题 单选题下列关于运算符重载的描述中,正确的是(  )。A 运算符重载可以改变运算符的操作数的个数B 运算符重载可以改变优先级C 运算符重载可以改变结合性D 运算符重载不可以改变语法结构

考题 单选题在重载一个运算符时,其参数表中没有任何参数,这表明该运算符是()。A 作为友元函数重载的1元运算符B 作为成员函数重载的1元运算符C 作为友元函数重载的2元运算符D 作为成员函数重载的2元运算符

考题 单选题下列关于赋值运算符“=”重载的叙述中,正确的是(  )。A 赋值运算符只能作为类的成员函数重载B 默认的赋值运算符实现了“深层复制”功能C 重载的赋值运算符函数有两个本类对象作为形参D 如果已经定义了复制(拷贝)构造函数,就不能重载赋值运算符

考题 单选题下列关于运算符重载的叙述中,正确的是(  )。A 通过运算符重载机制可以为c++语言扩充新的运算符B 运算符重载的作用是使已有的运算符作用于类的对象C 重载运算符的操作数类型可以全部为基本类型D 所有运算符都可以被重载

考题 单选题下列关于运算符重载的描述中,错误的是()。A 运算符重载不改变优先级B 运算符重载后,原来运算符操作不可再用C 运算符重载不改变结合性D 运算符重载函数的参数个数与重载方式有关