选择题:阅读以下程序说明和C++程序,将程序段中(1)~(5)空缺处的语句填写完整。【说明】 以下【C++程序】实现一

  • 题目分类:软考初级
  • 题目类型:选择题
  • 查看权限:VIP
题目内容:
阅读以下程序说明和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




参考答案:

公司需要将计算机网络划分成虚拟网络,选用了相互之间均支持VLAN划分的3COM交换机,不同部门可能分

公司需要将计算机网络划分成虚拟网络,选用了相互之间均支持VLAN划分的3COM交换机,不同部门可能分

查看答案

阅读下列函数说明和C函数,将应填入(n)处的字句写在对应栏内。【函数2.1说明】 函数palindrome(char

阅读下列函数说明和C函数,将应填入(n)处的字句写在对应栏内。【函数2.1说明】 函数palindrome(char

查看答案

在峰值时间,可能使用单独的CPU无法保证在规定的时间内完成各种应用。为了解决这个问题,需要增加CP

在峰值时间,可能使用单独的CPU无法保证在规定的时间内完成各种应用。为了解决这个问题,需要增加CP

查看答案

当选用三层交换机作为VLAN间的交换设备,三层交换机是什么设备?目前实现三层交换技术有哪些?

当选用三层交换机作为VLAN间的交换设备,三层交换机是什么设备?目前实现三层交换技术有哪些?

查看答案

● 对同一段音乐可以选用 MIDI 格式或 WAV格式来记录存储。 以下叙述中, (13) 是不正确的。 (13)A.W

● 对同一段音乐可以选用 MIDI 格式或 WAV格式来记录存储。 以下叙述中, (13) 是不正确的。 (13)A.W

查看答案