阅读以下程序说明和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
第1题:
请认真阅读以下关于某传输系统的技术说明、状态转换图及C++代码,根据要求回答问题1~问题2。
[说明]
传输门是传输系统中的重要装置。传输门具有Open(打开)、Closed(关闭)、Opening(正在打开)、 StayOpen(保持打开)和Closing(正在关闭)5种状态。触发状态的转换事件有click、complete和timeout3种。事件与其相应的状态转换如图7-15所示。

下面的[C++代码1]与[C++代码2]分别用两种不同的设计思路对传输门进行状态模拟,请填补代码段中的空缺语句。
[C++代码1]

请将以上[C++代码1]与[C++代码2]程序段中的(1)~(7)空缺处的语句填写完整。
第2题:
阅读以下说明和C++代码。
[说明]
已知类SubClass的getSum方法返回其父类成员与类SubClass成员j的和,类 SuperClass中的getSum为纯虚拟函数。程序中的第23行有错误,请修改该错误并给出修改后的完整结果,然后完善程序中的空缺,分析程序运行到第15行且尚未执行第15行的语句时成员变量j的值,最后给出程序运行后的输出结果。
[C++代码]

第3题:
1、以下说法中正确的是________。
A.C/C++程序总是从源文件中第一个定义的函数开始执行
B.在C/C++程序中,函数的定义必须写在调用该函数的语句之前
C.C/C++程序总是从main()函数开始执行
D.C/C++程序中的main()函数必须放在程序的开始部分
第4题:
阅读下列程序说明和C++程序,把应填入其中(n)处的字句,写在对应栏内。
【说明】
阅读下面几段C++程序回答相应问题。
比较下面两段程序的优缺点。
①for (i=0; i<N; i++ )
{
if (condition)
//DoSomething
…
else
//DoOtherthing
…
}
②if (condition) {
for (i =0; i<N; i++ )
//DoSomething
}else {
for (i=0; i <N; i++ )
//DoOtherthing
…
}
第5题:
阅读以下关于某订单管理系统的技术说明、部分UML类图及C++代码,将C++程序中(1)~(5)空缺处的语句填写完整。
[说明]
某订单管理系统的部分UML类图如图5-15所示。

图5-15中,Product表示产品,ProductList表示产品目录,Order表示产品订单,Orderltem表示产品订单中的一个条目,OrderList表示订单列表,SalesSystem提供订单管理系统的操作接口。
请完善类Order的成员函数getOrderedAmount()和类SalesSystem的statistic()方法,各个类的属性及部分方法定义参见下面的C++代码。
[C++代码]

对于每个订单项显然需要取出对应产品的识别号。从getOrderedAmount(string tid)定义代码中变量k用于遍历并索引一份订单中的每个订单项(items[k])。由于OrderItem类提供的成员函数getProductpt()可获取指向被订购产品的指针因此可通过(1)空缺处所填写的“items[k].getProductptr()->getProductId()”获取被订购产品的识别号。若指定的产品识别号等于该订单项的产品识别号就通过(2)空缺处所填写的“items[k].getQuantity()”返回该产品被订购的数量。
类SalesSystem的成员函数statistic()用于统计产品目录中每个产品的订购总量并打印输出每个产品的识别码、描述、订购总量和订购金额。若要统计产品目录中每个产品的订购总量需要对3个对象集合进行遍历:产品目录(ProductList)、订单列表(OrdeList)及Order(需要对订单中的所有订单项进行查询统计每个订单上所订购的产品的数量)。由此可以得出实现该方法的基本流程如下。
①从产品目录中取出一个产品。对应语句“for(k=0;kcatalog.getProductAmount();k++)”用于遍历产品目录中的每件产品。由于存放产品目录(产品列表)的数据成员catalog的类型为ProductList要取得某产品的相关信息需要通过ProductList类提供的成员函数getProductByIndex(int I)获得产品目录中的第 i件产品因此(3)空缺处所填写的内容是“catalog.getProductByIndex(k)”。
②查询给定产品在每份订单中的订购情况。对应的语句“for(it=sales.Begin(); (4) ;it++”用于遍历所有的订单根据产品识别码获得给定产品在当前订单中被订购的数量。对于给定产品和订单可调用订单类Order的成员函数getOrderedAmount(tid)获得识别码为tid的产品在当前订单中被订购的数量。因此(5)空缺处所填写的内容是“it->getOrderedAmount”。
由于类OrderList提供的方法Begin()、End()分别指向订单列表的第一个元素和最后一个元素之后而迭代器变量it实际是指向订单列表(向量sales)中某订单的指针因此(4)空缺处所填写的内容是“it!= sales.End()”或“itsales.End()”。
对于每个订单项,显然需要取出对应产品的识别号。从getOrderedAmount(string tid)定义代码中,变量k用于遍历并索引一份订单中的每个订单项(items[k])。由于OrderItem类提供的成员函数getProductpt()可获取指向被订购产品的指针,因此可通过(1)空缺处所填写的“items[k].getProductptr()->getProductId()”获取被订购产品的识别号。若指定的产品识别号等于该订单项的产品识别号,就通过(2)空缺处所填写的“items[k].getQuantity()”返回该产品被订购的数量。
类SalesSystem的成员函数statistic()用于统计产品目录中每个产品的订购总量,并打印输出每个产品的识别码、描述、订购总量和订购金额。若要统计产品目录中每个产品的订购总量,需要对3个对象集合进行遍历:产品目录(ProductList)、订单列表(OrdeList)及Order(需要对订单中的所有订单项进行查询,统计每个订单上所订购的产品的数量)。由此可以得出实现该方法的基本流程如下。
①从产品目录中取出一个产品。对应语句“for(k=0;kcatalog.getProductAmount();k++)”用于遍历产品目录中的每件产品。由于存放产品目录(产品列表)的数据成员catalog的类型为ProductList,要取得某产品的相关信息,需要通过ProductList类提供的成员函数getProductByIndex(int I)获得产品目录中的第 i件产品,因此(3)空缺处所填写的内容是“catalog.getProductByIndex(k)”。
②查询给定产品在每份订单中的订购情况。对应的语句“for(it=sales.Begin(); (4) ;it++”用于遍历所有的订单,根据产品识别码获得给定产品在当前订单中被订购的数量。对于给定产品和订单,可调用订单类Order的成员函数getOrderedAmount(tid)获得识别码为tid的产品在当前订单中被订购的数量。因此(5)空缺处所填写的内容是“it->getOrderedAmount”。
由于类OrderList提供的方法Begin()、End()分别指向订单列表的第一个元素和最后一个元素之后,而迭代器变量it实际是指向订单列表(向量sales)中某订单的指针,因此(4)空缺处所填写的内容是“it!= sales.End()”或“itsales.End()”。
第6题:
以下叙述正确的是()。
A.一个C/C++程序可由一个或多个函数组成
B.一个C/C++程序必须包含一个而且只能包含一个主函数
C.C/C++程序从主函数开始执行,并在主函数结束时结束。
D.在C/C++程序中,注释说明的内容不参与程序执行