题目内容 (请给出正确答案)
[主观题]

设有复数类COMPLEX,在复数类中重载乘法运算符。 下列哪项是运算符重载的正确的声明格式?

A、COMPLEX *(COMPLEX c1, COMPLEX c2);

B、COMPLEX * (COMPLEX c2);

C、COMPLEX operator * (COMPLEX c1, COMPLEX c2);

D、COMPLEX operator * (COMPLEX c2);

提问人:网友keny1104 发布时间:2022-01-06
参考答案
查看官方参考答案
如搜索结果不匹配,请 联系老师 获取答案
更多“设有复数类COMPLEX,在复数类中重载乘法运算符。 下列哪…”相关的问题
第1题
阅读以下程序说明和C++程序,将程序段中(1)~(5)空缺处的语句填写完整。

【说明】

以下【C++程序】实现一个简单的小型复数类MiniComplex,该复数类能进行输入、输出、复数的加法、减法、乘法和除法运算,还可以进行复数的相等比较。

【C++程序】

ifndef H_MiniComplex

define H_MiniComplex

include <iostream>

using namespace std;

class MiniComplex{

public: //重载流插入和提取运算符

(1) ostream&operator<<(ostream &osObject,const MiniComplex&complex){

osObject<<"("<<complex.realPart<<"+"<<complex.imagPart<<"i"<<")";

return osObject;

}

(2) istream&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&otherComplex)const; //重载运算符*

MiniComplex operator/(const MiniComplex&otherComplex)const; //重载运算符/

bool perator==(const MiniComplex&otherComplex)const; //重载运算符==

private :

double (3);

double imagPart;

};

end if

include "MiniComplex.h"

bool MiniComplex::operator==(const MiniComplex&otherComplex)const{

return(realPart==otherComplex.realPart&&imagPart==ortherComplex.imagPart);

}

MiniComplex::MiniComplex(double real,double imag){

realPart== real; imagPart==imagPart;

}

MiniComplex MiniComplex::operator+(const MiniComplex&otherComplex)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 MiniComplex&otherComplex)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 MiniComplex&otherComplex)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

点击查看答案
第2题
【简答题】定义一个复数类,重载“-=”运算符,使这个运算符能直接完成复数的“-=”运算。⑴分别用成员函数与友元函数编写运算符重载函数;⑵在主函数中定义复数对象 c1(10,20)、c2(15,30),进行 c2-=c1 的复数运算,并输出 c1、c2 的复数值。
点击查看答案
第3题
关于基类中的虚函数与一般成员函数,正确的是( )。

A、虚函数与一般成员函数在基类中没什么区别

B、虚函数不能被调用,而一般成员函数可以

C、虚函数不能定义函数体,而一般成员函数可以

D、虚函数只能定义一个,而一般成员函数可以多个

点击查看答案
第4题
虚函数不得声明为______函数。

A、其他三项均正确

B、构造

C、友元

D、静态

点击查看答案
第5题
如果一个类至少有一个__________,那么就称该类为抽象类。

A、纯虚函数

B、友元函数

C、成员函数

D、构造函数

点击查看答案
第6题
只有使用虚函数机制,才能_____________

A、使用基类指针调用派生类的成员函数

B、使用派生类指针调用基类的成员函数

C、使基类指针指向派生类对象

D、使派生类指针指向基类对象

点击查看答案
第7题
基类中的虚函数如果在派生类中未重新定义,则会出现( )的情况。

A、使用派生类的对象调用的仍然是基类的这个函数

B、无法使用派生类的对象调用这个函数

C、无法使用基类的对象调用这个函数

D、不允许定义派生类的对象

点击查看答案
第8题
基类中的运算符重载函数不能定义为纯虚函数。
点击查看答案
第9题
基类中允许定义____个虚函数?

A、任意多个

B、一个

C、两个

D、和成员变量的个数有关

点击查看答案
账号:
你好,尊敬的用户
复制账号
发送账号至手机
密码将被重置
获取验证码
发送
温馨提示
该问题答案仅针对搜题卡用户开放,请点击购买搜题卡。
马上购买搜题卡
我已购买搜题卡, 登录账号 继续查看答案
重置密码
确认修改
欢迎分享答案

为鼓励登录用户提交答案,简答题每个月将会抽取一批参与作答的用户给予奖励,具体奖励活动请关注官方微信公众号:简答题

简答题官方微信公众号

警告:系统检测到您的账号存在安全风险

为了保护您的账号安全,请在“简答题”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!

微信搜一搜
简答题
点击打开微信
警告:系统检测到您的账号存在安全风险
抱歉,您的账号因涉嫌违反简答题购买须知被冻结。您可在“简答题”微信公众号中的“官网服务”-“账号解封申请”申请解封,或联系客服
微信搜一搜
简答题
点击打开微信