首页 > 软考
题目内容 (请给出正确答案)
[主观题]

阅读下列说明和c++代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】某软件公司现欲开发一款

阅读下列说明和c++代码,将应填入(n)处的字句写在答题纸的对应栏内。

【说明】

某软件公司现欲开发一款飞机飞行模拟系统,该系统主要模拟不同种类飞机的飞行特征与起飞特征。需要模拟的飞机种类及其特征如表5-l所示。

阅读下列说明和c++代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】某软件公司现欲开发一款

为支持将来模拟更多种类的飞机,采用策略设计模式(Strategy)设计的类图如图5—1所示。

图5-l中,AirCraft为抽象类,描述了抽象的飞机,而类Helicopter、AirPlane、Fighter和Harrier分别描述具体的飞机种类,方法fly()和takeOff()分别表示不同飞机都具有飞行特征和起飞特征;类FlyBehavior与TakeOffBehavior为抽象类,分别用于表示抽象的飞行行为与起飞行为;类SubSonicFly与SuperSonicFly分别捕述亚音速飞行和超音速飞行的行为;类Verti calTakeOff与LongDistanceTakeoff分别描述垂直起飞与长距离起飞的行为。

阅读下列说明和c++代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】某软件公司现欲开发一款

【C++代码】

include

using namespace std;

class FlyBehavior{

public:virtual void fly()=0;

};

class SubSonicFly:public FlyBehavior{

public: void fly(){cout<<"亚音速飞行! "<

查看答案
答案
收藏
如果结果不匹配,请 联系老师 获取答案
您可能会需要:
您的账号:,可能还需要:
您的账号:
发送账号密码至手机
发送
安装优题宝APP,拍照搜题省时又省心!
更多“阅读下列说明和c++代码,将应填入(n)处的字句写在答题纸的…”相关的问题
第1题
●试题一 阅读下列函数说明和C代码,把应填入其中n处的字句写在答卷的对应栏内。 【函数1.1说明】

●试题一

阅读下列函数说明和C代码,把应填入其中n处的字句写在答卷的对应栏内。

【函数1.1说明】

函数strcpy(char*to,char*from)将字符串from复制到字符串to。

【函数1.1】

void strcpy(char*to,char*from)

{while((1 ) );}

【函数1.2说明】

函数merge(int a[ ],int n,int b[ ],int m,int *c)是将两个从小到大有序数组a和b复制合并出一个有序整数序列c,其中形参n和m分别是数组a和b的元素个数。

【函数1.2】

void merge(int a[ ],int n,int b[ ],int m,int *c)

{ int i,j;

for(i=j=0;i<n && j<m;)

*c++=a[i]<b[j]? a[i++]:b[j++];

while((2) )*c++=a[i++];

while((3) )*c++=b[j++];

}

【函数1.3说明】

递归函数sum(int a[ ],int n)的返回值是数组a[ ]的前n个元素之和。

【函数1.3】

int sum(int a[ ],int n)

{ if(n>0)return (4) ;

else (5) ;

}

点击查看答案
第2题
阅读下列说明和c++代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】现欲构造一文件/目录树,

阅读下列说明和c++代码,将应填入 (n) 处的字句写在答题纸的对应栏内。

【说明】

现欲构造一文件/目录树,采用组合(Composite)设计模式来设计,得到的类图如6—7所示:

阅读下列说明和c++代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】现欲构造一文件/目录树

【c++代码】

include<1ist>

include

include

using namespace std;

class AbstractFile{

protected:

string name;//文件或目录名称

public:

void printName(){cout<*getChildren()=0; //获得一个目录的子目录或文件

};

class File:public AbstractFile{

public:

File(string name){ (1) =name;)

void addChild(AbstractFile*file){return ;)

void removeChiid(AbstractFile*file){return;}(2) getChildren(){return (3 ) ;}

};

class Folder:public AbstractFile{

private:

listchildList; //存储子目录或文件

public:

Folder(string name){ (4) =name;}

void addChild(AbstractFile*file){childList.push back(file);}

void removeChiid(AbstractFile*file)(chiidList.remove(file);}

list*getChildren(){return (5) ;)

};

voidmain(){

//构造一个树形的文件/目录结构

AbstractFile*rootFolder=new Folder(“C:\\”);

AbstractFile*compositeFolder=flew Folder(”composite”);

AbstractFile*windowsFolder=new Folder(”windows”);

AbstractFile*file=new File(”TestComposite.java”);

rootFolder->addChild(compositeFolder);

rootFolder->addChild (windowsFolder);

compositeFolder->addChiid(file);

)

点击查看答案
第3题
阅读下列说明、c++代码和运行结果,填补代码中的空缺(1)~(6),将解答填入答题纸的对应栏内。【说明】很

阅读下列说明、c++代码和运行结果,填补代码中的空缺(1)~(6),将解答填入

答题纸的对应栏内。

【说明】

很多依托扑克牌进行的游戏都要先洗牌。下面的c++程序运行时先生成一副扑克牌,

洗牌后再按顺序打印每张牌的点数和花色。

【c++代码】

inciude <iostream>

4Finclude <stdlib. h>

include <ctime>

inciude <aigorithm>

include <string>

Using namespace std

Const string Rank[13]={”A”,”2”,”3”,”4“,“5”,”6,”’“7”8“,9”,”10,”J”,

”Q”,”K”}j//扑克牌点数

阅读下列说明、c++代码和运行结果,填补代码中的空缺(1)~(6),将解答填入答题纸的对应栏内。【说

阅读下列说明、c++代码和运行结果,填补代码中的空缺(1)~(6),将解答填入答题纸的对应栏内。【说

阅读下列说明、c++代码和运行结果,填补代码中的空缺(1)~(6),将解答填入答题纸的对应栏内。【说

阅读下列说明、c++代码和运行结果,填补代码中的空缺(1)~(6),将解答填入答题纸的对应栏内。【说

点击查看答案
第4题
阅读下列说明和 C++代码,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 某快餐厅主要制作

阅读下列说明和 C++代码,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 某快餐厅主要制作井出售儿童套餐,一般包括主餐(各类比萨)、饮料和玩具,其餐品种类可能不同,但其制作过程相同。前台服务员(Waiter)调度厨师制作套餐。现采用生成器(Builder) 模式实现制作过程,得到如图 5-1 所示的类图。阅读下列说明和 C++代码,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 某快餐厅主要制作图5-1 类图 【C++代码】 include<iostream> include <string> using namespace std; class Pizza { private: string parts; public: void setParts(string parts) { this->parts=parts; } string getParts() { return parts; } }; class PizzaBuilder { protected:Pizza* pizza; public: Pizza* getPizza() { retum pizza; } void createNewPizza() { pizza = new Pizza(); } (1 ); } class HawaiianPizzaBuilder :public PizzaBuilder { public: void buildParts() { pizza->setParts("cross +mild + ham&pineapple"); } }; class SpicyPizzaBuider: public PizzaBuilder { public: void buildParts() { pizza->setParts("pan baked +hot + ham&pineapple"); } } Class Waiter{ Private: PizzaBuilder* pizzaBuilder; public: void setPizzaBuilder(PizzaBuilder* pizzaBuilder) { /*设置构建器*/ (2 ) } Pizza* getPizza() { return pizzaBuilder->getPizza(); } void construct() { /*构建*/ pizzaBuilder->createNewPizza(); (3 ) } }; int main(){ Waiter*waiter=new Waiter(); PizzaBuilder*hawaiian pizzabuilder=new HawaiianPizzaBuilder() (4 ); (5 ); cout<< "pizza: "<< waiter->getPizza()->getParts()<< endl; } 程序的输出结果为: pizza: cross + mild + ham&pineapple

点击查看答案
第5题
阅读以下说明,以及用C++在开发过程中所编写的程序代码,将应填入(n)处的字句写在对应栏内。【说明】

阅读以下说明,以及用C++在开发过程中所编写的程序代码,将应填入(n)处的字句写在对应栏内。

【说明】

在下面函数横线处填上适当的字句,使其输出结果为:

构造函数.

构造函数.

1,2

5,6

析构函数

析构函数.

【C++代码】

include "iostream.h"

class AA

{ public;

AA(int i,int j)

{A=i; B=j;

cout<<"构造函数.\n";

}

~AA(){(1);}

void print();

private:

int A, B;

};

void AA∷print()

{cout<<A<<","<<B<<endl;}

void main()

{

AA *a1, *a2;

(2)=new AA(1, 2);

a2=new AA(5, 6);

(3);

a2->print();

(4) a1;

(5) a2;

}

点击查看答案
第6题
试题六(共 15 分) 阅读以下说明和 C++代码,将应填入 (n) 处的字句写在答题纸的对应栏内。 [说明]

试题六(共 15 分)

阅读以下说明和 C++代码,将应填入 (n) 处的字句写在答题纸的对应栏内。

[说明]

C++标准模板库中提供了 vector 模板类,可作为动态数组使用,并可容纳任意数据类型,其所属的命名空间为 std。vector模板类的部分方法说明如下表所示:

试题六(共 15 分) 阅读以下说明和 C++代码,将应填入 (n) 处的字句写在答题纸的对应栏内。

[C++代码]

include <iostream>

include <vector>

using namespace (1) ;

typedef vector< (2) > INTVECTOR;

const int ARRAY_SIZE = 6;

void ShowVector(INTVECTOR &theVector);

int main(){

INTVECTOR theVector;

// 初始化 theVector,将 theVector的元素依次设置为 0 至 5

for (int cEachItem = 0; cEachItem < ARRAY_SIZE; cEachItem++)

theVector.push_back((3) );

ShowVector(theVector); // 依次输出 theVector中的元素

theVector.erase(theVector.begin() + 3);

ShowVector(theVector);

}

void ShowVector(INTVECTOR &theVector) {

if (theVector.empty()) {

cout << "theVector is empty." << endl; return;

}

INTVECTOR::iterator (4) ;

for (theIterator = theVector.begin(); theIterator != theVector.end(); theIterator++){

cout << *theIterator;

if (theIterator != theVector.end()-1) cout << ", ";

}

cout << endl;

}

该程序运行后的输出结果为:

0, 1, 2, 3, 4, 5

(5)

点击查看答案
第7题
试题五(共15分)阅读下列说明和C++-代码,将应填入 (n) 处的字句写在答题纸的对应栏内。【说明】某发

试题五(共15分)

阅读下列说明和C++-代码,将应填入 (n) 处的字句写在答题纸的对应栏内。

【说明】

某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰(Decorator)模式实现打印发票的功能,得到如图5-1所示的类图。

试题五(共15分)阅读下列说明和C++-代码,将应填入 (n) 处的字句写在答题纸的对应栏内。【说明

【C++代码】

include <iostream>

using namespace std;

class invoice{

public:

(1) {

cout《 "This is the content of the invoice!"《 endl;

}

};

class Decorator : public invoice {

Invoice *ticket;

public:

Decorator(lnvoice *t) { ticket = t; }

void printinvoice(){

if(ticket != NULL)

(2);

}

};

class HeadDecorator : public Decorator{

public:

HeadDecorator(lnvoice*t): Decorator(t) { }

void printinvoice0 {

cout《 "This is the header of the invoice! "<< endl;

(3) ;

}

};

class FootDecorator : public Decorator{

public:

FootDecorator(invoice *t): Decorator(t) { }

void printlnvoice() {

(4) ;

cout《 "This is the footnote of the invoice!"《 endl;

}

};

int main(void) {

Invoice t;

FootDecorator f(&t);

HeadDecorator h(&f);

H.printlnvoice();

cout< < “_____”< < endl;

FootDecorator a(NULL);

HeadDecorator b((5) );

B.printinvoice();

return 0;

}

程序的输出结果为:

This is the header of the invoice!

This is the content of the invoice!

This is the footnote of the invoice!

----------------------------

This is the header of the invoice!

This is the footnote of the invoice!

点击查看答案
第8题
阅读下列说明和C++代码,将应填入(n)处的字句写在答题纸的对应栏内. 【说明】 某实验室欲建立

阅读下列说明和C++代码,将应填入 (n)处的字句写在答题纸的对应栏内. 【说明】 某实验室欲建立一个实验室环境监测系统,能够显示实验室的温度、湿度以及洁净度等环境数据。当获取到最新的环境测量数据时,显示的环境数据能够更新。 现在采用观察者(Observer)模式来开发该系统。观察者模式的类图如图5-1所示。阅读下列说明和C++代码,将应填入(n)处的字句写在答题纸的对应栏内. 【说明】 某实验室欲建立阅读

【C++代码】 include <iostream> include <vector> using namespace std; class Observer { public: virtual void update(float temp, float humidity, float cleanness)=0; }; class Subject { public: virtual void registerObserver(Observer* o) = 0; //注册对主题感兴趣的观察者 virtual void removeObserver(Observer* o) = 0; //删除观察者 virtual void notifyObservers() = 0;//当主题发生变化时通知观察者 }; class EnvironmentData : public (1) { private: vector<Observer*> observers; float temperature, humidity, cleanness; public: void registerObserver(Observer* o) { observers.push_back(o); } void removeObserver(Observer* o) { /* 代码省略 */ } void notifyObservers() { for(vector<Observer*>::const_iterator it = observers.begin(); it != observers.end(); it++) { (2) ; } } Void measurementsChanged() { (3) ; } void setMeasurements(float temperature, float humidity, float cleanness) { this->temperature = temperature; this->humidity = humidity; this->cleanness = cleanness; (4) ; } }; class CurrentConditionsDisplay : public (5) { private: float temperature, humidity, cleanness; Subject* envData; public: CurrentConditionsDisplay(Subject* envData) { this->envData = envData; (6) ; } void update(float temperature, float humidity, float cleanness) {this->temperature = temperature; this->humidity = humidity; this->cleanness = cleanness; display(); } void display() { /* 代码省略 */ } }; int main() { EnvironmentData* envData = new EnvironmentData(); CurrentConditionsDisplay* currentDisplay = new CurrentConditionsDisplay(envData); envData->setMeasurements(80, 65, 30.4f); return 0; }

点击查看答案
第9题
试题五(共 15 分) 阅读下列说明、图和C++代码,将应填入 (n) 处的字句写在答题纸的对应栏内。[说明]

试题五(共 15 分)

阅读下列说明、图和C++代码,将应填入 (n) 处的字句写在答题纸的对应栏内。

[说明]

已知对某载客车辆(Car)进行类建模,如图 5-1所示,其中类 Engine 表示发动机引擎,类 Wheel 表示车轮,类 Body 表示车身,类 Driver 表示司机,类 Passenger 表示乘客。

试题五(共 15 分) 阅读下列说明、图和C++代码,将应填入 (n) 处的字句写在答题纸的对应栏内

[C++代码]

const int (1) = 7; //定义最多载客数

const int MAX_WHEELS = 5; //定义最多轮胎数

class Body{ //此处代码省略 }; //车身类

class Passenger{ //此处代码省略 }; //乘客类

class Wheel{ //此处代码省略 }; //车轮类

class Driver{ //司机类

public:

string name; //表示第几路公交车司机

Driver(string driverName):name((2) ){}; //构造函数

};

class Engine{ //引擎类

public:

string engineNo; //引擎编号

Engine(string engineNo){ (3) ->engineNo = engineNo; } //构造函数

};

class Car{ //汽车类

protected:

Engine * engine; Driver * driver; Body body;

Wheel * wheels[MAX_WHEELS]; Passenger * passengers[MAX_PASSENGERS];

public:

Car(Driver *driver){ //构造函数

this->driver = driver;

engine = new Engine("TX6536 型号引擎");

for (int index = 0; index < MAX_WHEELS; index++){

wheels[index] = new Wheel();

}

for (int index = 0; index < MAX_PASSENGERS; index++){

passengers[index] = NULL;

}

}

virtual ~Car(){ //析构函数

for (int index=0; index < MAX_WHEELS; index++)

delete wheels[index];

delete (4) ;

}

int getPassengerNumber(){ //获取车上乘客数量

//此处代码省略

}

void getOnPassenger(Passenger * aPassenger ){ //乘客上车

//此处代码省略

}

void run(){ //开车

if(driver == NULL){ cout << "司机尚未上车!"; return; }

//此处代码省略

}

};

void main(){

Driver driver("第五路公交车司机");

Car car((5) );

Passenger passengers[MAX_PASSENGERS];

for (int index = 0 ; index < MAX_PASSENGERS; index ++) //乘客上车处理

car.getOnPassenger(&passengers[index]);

car.run();

}

点击查看答案
第10题
试题五(共 15分) 阅读以下说明和C++代码,将应填入 (n) 处的字句写在答题纸的对应栏内。 【说明】

试题五(共 15分)

阅读以下说明和C++代码,将应填入 (n) 处的字句写在答题纸的对应栏内。

【说明】

已知类 LinkedList 表示列表类,该类具有四个方法:addElement()、lastElement()、umberOfElement()以及removeLastElement()。四个方法的含义分别为:

void addElement(Object): 在列表尾部添加一个对象;

Object lastElement(): 返回列表尾部对象;

int numberOfElement(): 返回列表中对象个数;

void removeLastElement(): 删除列表尾部的对象。

现需要借助LinkedList来实现一个Stack栈类,C++代码1和C++代码2分别采用继承和组合的方式实现。

【C++代码 1】

class Stack :public LinkedList{

public:

void push(Object o){ addElement(o); }; //压栈

Object peek(){ return (1) ; }; //获取栈顶元素

bool isEmpty(){ //判断栈是否为空

return numberOfElement() == 0;

};

Object pop(){ //弹栈

Object o = lastElement();

(2) ;

return o;

};

};

【C++代码 2】

class Stack {

private:

(3) ;

public:

void push(Object o){ //压栈

list.addElement(o);

};

Object peek(){ //获取栈顶元素

return list. (4) ;

};

bool isEmpty(){ //判断栈是否为空

return list.numberOfElement() == 0;

};

Object pop(){//弹栈

Object o = list.lastElement();

list.removeLastElement();

return o;

};

};

【问题】

若类LinkedList新增加了一个公有的方法removeElement(int index),用于删除列表中第index个元素,则在用继承和组合两种实现栈类Stack的方式中,哪种方式下Stack对象可访问方法removeElement(int index)? (5) (A. 继承 B. 组合)

点击查看答案
退出 登录/注册
发送账号至手机
密码将被重置
获取验证码
发送
温馨提示
该问题答案仅针对搜题卡用户开放,请点击购买搜题卡。
马上购买搜题卡
我已购买搜题卡, 登录账号 继续查看答案
重置密码
确认修改