2011年软件设计师考试考前密卷(六)-下午试题

0
收藏   分享
  • 卷面总分:75分
  • 试卷类型:模拟考试
  • 测试费用:免费
  • 答案解析:是
  • 练习次数:20次
  • 作答时间:150分钟
试卷简介
2011年软件设计师考试考前密卷(六)-下午试题:1.2011年软件设计师考试全真模拟试卷-下午试题,考前复习的好帮手!2. 每道题都配有答案解析,强化复习效
试卷预览
1

●试题五

阅读下列程序说明,将应填入(n)处的字句写在答卷纸的对应栏内。

【程序说明】

对于一个公司的雇员来说,无非有3种:普通雇员、管理人员和主管。这些雇员有共同的数据:名字、每小时的工资,也有一些共同的操作:数据成员初始化、读雇员的数据成员及计算雇员的工资。但是,他们也有不同。例如,管理人员除有这些共同的特征外,有可能付固定薪水,主管除有管理人员的共同特征外,还有其他物质奖励等。3种雇员中,管理人员可以看作普通雇员的一种,而主管又可以看作管理人员的一种。我们很容易想到使用类继承来实现这个问题:普通雇员作为基类,管理人员类从普通雇员类中派生,而主管人员类又从管理人员类中派生。

下面的程序1完成上述各个类的定义,并建立了3个雇员(一个普通雇员、一个管理人员和一个主管)的档案,并打印出各自的工资表。将"程序1"中的成员函数定义为内联函数,pay成员函数定义为虚函数,重新完成上述要求。

【程序1】

//普通雇员类

class Employee

{

public:

Employee(char*theName,float thePayRate);

char*getName()const;

float getPayRate()const;

float pay(float hoursWorked)const;

protected:

char*name;//雇员名称

float payRate;//薪水等级

};

Employee::Employee(char*theName,float thePayRate)

{

name=theName;

payRate=thePayRate;

}

char*Employee::getName() const

{

return name;

}

float Employee::getPayRate()const

{

return payRate;

}

float Employee::pay(float hoursWorked)const

{

return hoursWorked*payRate;

}

//管理人员类

class Manager∶public Employee

{

public:

//isSalaried付薪方式:true付薪固定工资,false按小时付薪

Manager(char*theName,float thePayRate,bool isSalaried);

bool getSalaried()const;

float pay(float hoursWorked)const;

protected:

bool salaried;

};

Manager::Manager(char*theName,float thePayRate,bool isSalaried)

∶Employee(theName,thePayRate)

{

salaried=isSalaried;

}

bool Manager::getSalaried() const

{

return salaried;

}

float Manager::pay(float hoursWorked)const

{

if(salaried)

return payRate;

/*else*/

return Employee::pay(hoursWorked);

}

//主管人员类

class Supervisor:public Employee

{

public:

Supervisor(char*theName,float thePayRate,float theBouns):

Employee(theName,thePayRate, (1) ),bouns(theBouns){}

float getBouns()const{return bouns;}

float pay(float hoursWorked)const

return (2) ;

}

protected:

float bouns;

}

#include"iostream.h"

void main()

{

Employee e("Jack",50.00);

Manager m("Tom",8000.00,true);

Supervior s("Tanya",8000.00,8000.00);

cout<<"Name:"<

cout<<"Pay:"<

cout<<"Name:"<

cout<<"Pay:"<

cout<<"Name:"<

cout<<"Pay:"<

}

【程序2】

 #include"employee.h"

 //普通雇员类

 class Employee

 {

 public:

//构造函数

Employee(string theName,float thePayRate):

name(theName),payRate(thePayRate){}

//取雇员姓名

string getName() const{returnname;}

//取雇员薪水等级

float getPayRate()const{return payRate;}

//计算雇员薪水

virtual float pay(float hoursWorked)const{return (3) ;}

protected:

string name;//雇员名称

float payRate;//薪水等级

};

//管理人员类

//继承普通雇员类

class Manager:public Employee

{

public:

 //构造函数

 //isSalaried标识管理人员类的付薪方式

 //true 按阶段付薪(固定工资)

 //false按小时付薪

Manager(string theName,float thePayRate,bool isSalaried):

Employee(theName,thePayRate),salaried(isSalaried){}

 //取付薪方式

bool getSalaried()const{return salaried;}

 //计算薪水

virtual float pay(float (4) )const;

protected:

bool salaried;

};

float Manager::pay(float hoursWorked)const

{

if(salaried)//固定付薪方式

return payRate;

else//按小时付薪

return (5)  ; }

//主管人员类

class Supervisor: (6) 

{

public:

//构造函数

Supervisor(string theName,float thePayRate,float theBouns):

Manager(theName,thePayRate,true),bouns(theBouns){}

 //取奖金数额

float getBouns()const{return bouns;}

 //计算薪水

virtual float pay(float hoursWorked)const

{

retum payRate+bouns;

}

 (7) 

float bouns;

}

#include"employee.h"

#include"iostream.h"

void main()

{

 (8) *ep[3];ep[0]=new Employee("Jack","50.00");

ep[1]=new Manager("Tom","8000.00",true);

ep[2]=new Supervior("Tanya","8000.00","8000.00");

for(int i=0;i<3;i++){

cout<<"Name:"<< (9) <

cout<<"Pay:"<< (10) <

 }

}

1

●试题四

阅读下列程序说明,将在空缺处填入正确的内容。

【程序说明】

定义一个多边形结构:struct polygon实现以下内容: (1) 建立该结构的链表:create函数是创建链表,每输入一个结点的数据,就把该结点加入到链表当中,它返回创建的链表的头指针。 (2) 显示链表的各个结点数据:结点数据包括:多边形顶点数、各顶点的纵横坐标、当多边形顶点数为0时,链表创建结束。 (3) 编写一个函数disp,删除链表中的所有结点。需要注意的是:要先释放结点数据内存,再删除结点,如果在释放结点数据内存单元之前删除结点,则无法找到结点数据内存单元的地址,也就无法释放数据的内存单元。

【程序】

#include"iostream.h"

#include"iomanip.h"

struct polygon

{

int n;

int *x;

int *y;

polygon *next;

};

void Push(polygon*& head,int n)

{

polygon*newNode=new polygon;

newNode=new polygon;

newNode->next= (1) ;

newNode->x=new int[n];newNode->y=new int[n];newNode->n= (2) ;

for(int i=0;i<= (3) ;i++){

cout<<"请输入多边形各顶点x、y坐标,坐标值之间用空格分隔:";

cin>>newNode->x[i]>>newNode->y[i];}

 (4) =head;//在head前不需要额外的*

head=newNode;

}

polygon *create()

{

polygon*head=NULL;

polygon*tail;

int n;

cout<<"请输入多边形顶点的个数(顶点个数为0时结束):";

cin>>n;

if(n==0)return (5) ;

Push(head, (6) ;

tail=head;

cout<<"请输入多边形顶点的个数(顶点个数为0时结束):";

cin>>n;

while(n!=0)

{

Push(tail->next, (7) ;//在tail->next增加结点

tail=tail->next;//advance tail to point to last node

cout<<"请输入多边形顶点的个数(顶点个数为0时结束):";

cin>>n;

}

return head;

}

void disp(polygon*head)

{

int i,No=1;

cout<

while(head!=NULL)

{

cout<<"第"<

for(i=0;i<=head->n-1;i++)

cout<x[i]<y[i]<

 (8) ;

head= (9) ;

}//Match while statement

}

void del(polygon*head)

{

polygon*p;

while(head!=NULL)

{

p= (10) ;

head=head->next;

delete p->x;

delete P->y;

deletep;

}//Match while statement

 }

 void main()

 {

polygon*head;

head=create();

disp(head);

del(head);

}