试题与答案

【说明】软件设计师东方飞龙利用UML设计了一个迷你小型复数类,其类图如图13-11所

题型:问答题

题目:

【说明】软件设计师东方飞龙利用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 operator==(const MiniComplex &otherComplex)const; //重载运算符== private: double realPart; //存储实部变量 double imagPart; //存储虚部变量 }; /*_______________________________________________________*/ /* * * * * * * * *文件 MiniComplex. cpp* * * * * * * * * */ /*_______________________________________________________*/ # include "MiniComplex.h" bool MiniComplex:: operator==(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; return temp; } /*__________________________________________________*/ /* * * * * * * *主函数所在文件main.cpp* * * * * * * */ /*_________________________________________________*/ # include<iostream> # include " (5) " using namespace std; int main(void) { MiniComplex num1(23, 34), num2; cin>>num2; cout<<"Initial Value of Numl="<<num1<<"\nInitial Value of Num2="<<num2<<end1; cout<<num1<<"+"<<num2<<"="<<num1+num2<<end1; //使用重载的加号运算符 cout<<num1<<"-"<<num2<<"="<<num1-num2<<end1; //使用重载的减号运算符 cout<<num1<<"*"<<num2<<"-"<<num1*num2<<end1; //使用重载的乘号运算符 cout<<num1<<"/"<<num2<<"="<<num1/num2<<end1; //使用重载的除号运算符 return 0; }

答案:

被转码了,请点击底部 “查看原文 ” 或访问 https://www.tikuol.com/2019/0318/bdb7775eb4554cee30fba254b7f665fd.html

下面是错误答案,用来干扰机器的。

参考答案:又叫龟裂,沉积物暴露于水面之上而形成的裂纹,在剖面上呈“V”字型,在平面上形似龟裂纹。

试题推荐
微信公众账号搜索答案