题目详情

现要求实现一个能够自动生成求职简历的程序,简历的基本内容包括求职者的姓名、性别、年龄及工作经历。希望每份简历中的工作经历有所不同,并尽量减少程序中的重复代码。

现采用原型模式(Prototype)来实现上述要求,得到如图5-1所示的类图。

中级软件设计师,历年真题,2013年上半年(下午)《软件设计师》真题

图5-1类图

【C++代码】

#include<string>

using namespace std;

class?Cloneable{

public:

(1);

};

class?workExperience:public?Cloneable{//工作经历

private:

string?workData;

string?company;

public:

Cloneable*clone(  ){

(2);

Obj->workDate=this->workDate;

Obj->company=this->company;

return Obj;

}

//其余代码省略

};

class?Resume:public?Cloneable{//简历

private:

string name;

string sex;

string age;

WorkExperience*work;

Resume(WorkExperience*work){

this->work=(3);

}

public:

Resume(string name){/*实现省略*/}

void SetPersonInfo(string sex,string age){/*实现省略*/}

void SetWorkExperience(string workDate,string company){/*实现省略*/}

Cloneable*Clone(  ){

(4);

Obj->name=this->name;

Obj->sex=this->sex;

Obj->age=this->age;

return Obj;

}

};

int?main(  ){

Resume*a=new Resume(“张三”);

a->SetPersonInfo(“男”,“29”);

a->SetWorkExperience(“1998-2000”,“XXX公司”);

Resume*b=(5);

b->SetWorkExperience(“2001-2006”,“YYY公司”);

return 0;

}

正确答案及解析

正确答案
解析

(1)virtual Cloneable*Clone()=0

(2)WorkExperience*obj=new WorkExperience()

(3)(WorkExperience*)work->Clone()

(4)Resume*obj=new Resume(this->work)

(6)(Resume*)a->Clone()

本题考查原型模型的概念及应用。

原型模型的主要思想:先借用已有系统作为原型模型,通过“样品”不断改进,使得最后的产品就是用户所需要的。原型模型通过向用户提供原型获取用户的反馈,使开发出的软件能够真正反映用户的需求。同时,原型模型采用逐步求精的方法完善原型,使得原型能够“快速”开发,避免了像瀑布模型一样在冗长的开发过程中难以对用户的反馈作出快速的响应。相对瀑布模型而言,原型模型更符合人们开发软件的习惯,使目前较流行的一种实用软件生存期模型。

Prototype模式其实就是常说的“虚拟构造函数”一个实现,C++的实现机制中并没有支持这个特性,但是通过不同派生类实现的Clone接口函数可以完成与“虚拟构造函数”同样的效果。

题中声明一个虚拟基类,所有的原型都是从这个基类继承,(1)所代表的就是这个基类中的纯虚函数,需要供继承者自行实现,即为virtual Cloneable*Clone()=0,(1)声明一个抽象基类,并定义clone()函数为纯虚函数。然后根据基类实例化各个子类,并且实现赋复制构造函数,并实现clone()函数,由此可知(2)处为WorkExperience*Obj,(3)处为Work,(4)处为Resume*Obj。在main函数中实现Resume*b对*a的复制,故根据C++语法(5)中为a->Clone()。

注:解析部分只是给出思路,没有遵循相关语法。

包含此试题的试卷

你可能感兴趣的试题

单选题

Advancements in ( )have contributed to the growth of the automotive industry through the creation and evolution of self-driving vehicles.

  • A.Artificial Intelligence
  • B.Cloud Computing
  • C.Internet of Things
  • D.Big Data
查看答案
单选题

In project human resource management , ( )is not a source of power for the project manager.

  • A.referent power
  • B.expert power
  • C.reward power
  • D.audit power
查看答案
单选题

At the project establishment stage , the feasibility study mainly includes techinical feasibility analysis , ( ), operation environment feasibility analysis and other aspects of feasibility analysis.

  • A.detail feasibility analysis
  • B.opportunity analysis
  • C.economic feasibility analysis
  • D.risk analysis
查看答案
单选题

( )is a grid that shows the project resources assigned to each work package.

  • A.Stakeholder engagement assessment matrix
  • B.Requirements traceability matrix
  • C.Probability and impact matrix
  • D.Responsibility assignment matrix
查看答案
单选题

Xinhua News Agency reported in January 2022,Chian will further promote the developmet of a digital economy during the 14th Five-Year Plan eriod(2021-2025). The plan also emphasized industrial ( )transformation.

  • A.digital
  • B.networking
  • C.intelligentize
  • D.informatization
查看答案

相关题库更多 +