国产18禁黄网站免费观看,99爱在线精品免费观看,粉嫩metart人体欣赏,99久久99精品久久久久久,6080亚洲人久久精品

2016年計(jì)算機(jī)軟件設(shè)計(jì)師程序模擬練習(xí)題

時(shí)間:2016-06-27 16:30:00   來(lái)源:無(wú)憂考網(wǎng)     [字體: ]
●試題五

  閱讀下列程序說(shuō)明,將應(yīng)填入(n)處的字句寫(xiě)在答卷紙的對(duì)應(yīng)欄內(nèi)。

  【程序說(shuō)明】

  對(duì)于一個(gè)公司的雇員來(lái)說(shuō),無(wú)非有3種:普通雇員、管理人員和主管。這些雇員有共同的數(shù)據(jù):名字、每小時(shí)的工資,也有一些共同的操作:數(shù)據(jù)成員初始化、讀雇員的數(shù)據(jù)成員及計(jì)算雇員的工資。但是,他們也有不同。例如,管理人員除有這些共同的特征外,有可能付固定薪水,主管除有管理人員的共同特征外,還有其他物質(zhì)獎(jiǎng)勵(lì)等。3種雇員中,管理人員可以看作普通雇員的一種,而主管又可以看作管理人員的一種。我們很容易想到使用類繼承來(lái)實(shí)現(xiàn)這個(gè)問(wèn)題:普通雇員作為基類,管理人員類從普通雇員類中派生,而主管人員類又從管理人員類中派生。

  下面的程序1完成上述各個(gè)類的定義,并建立了3個(gè)雇員(一個(gè)普通雇員、一個(gè)管理人員和一個(gè)主管)的檔案,并打印出各自的工資表。將"程序1"中的成員函數(shù)定義為內(nèi)聯(lián)函數(shù),pay成員函數(shù)定義為虛函數(shù),重新完成上述要求。

  【程序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;//薪水等級(jí)

  };

  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按小時(shí)付薪

  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:

  //構(gòu)造函數(shù)

  Employee(string theName,float thePayRate):

  name(theName),payRate(thePayRate){}

  //取雇員姓名

  string getName() const{returnname;}

  //取雇員薪水等級(jí)

  float getPayRate()const{return payRate;}

  //計(jì)算雇員薪水

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

  protected:

  string name;//雇員名稱

  float payRate;//薪水等級(jí)

  };

  //管理人員類

  //繼承普通雇員類

  class Manager:public Employee

  {

  public:

  //構(gòu)造函數(shù)

  //isSalaried標(biāo)識(shí)管理人員類的付薪方式

  //true 按階段付薪(固定工資)

  //false按小時(shí)付薪

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

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

  //取付薪方式

  bool getSalaried()const{return salaried;}

  //計(jì)算薪水

  virtual float pay(float (4) )const;

  protected:

  bool salaried;

  };

  float Manager::pay(float hoursWorked)const

  {

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

  return payRate;

  else//按小時(shí)付薪

  return (5) ; }

  //主管人員類

  class Supervisor: (6)

  {

  public:

  //構(gòu)造函數(shù)

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

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

  //取獎(jiǎng)金數(shù)額

  float getBouns()const{return bouns;}

  //計(jì)算薪水

  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) <

  }

  }