麻烦各位谁能帮我编一下下面的这道试题,是C++语言程序设计(第4版)的,不要恨全面,只要普通,谢谢

2024-12-20 07:17:41
推荐回答(1个)
回答1:

下面的程序是个相似的程序,你自己对照着修改一下吧:
#include
#include
#include
#include
typedef enum grade{specProf, respProf,norProf,resProf}Grade;
//声明枚举类型,包括特聘教授,责任教授,教学人员,研究人员
class Teacher //声明抽象基类
{
protected:
int nNo; //编号
char*eName; //姓名
int age; //年龄
grade eGrade; //级别
double basicSalary; //工资
static int nCount; //教工总数
public:
Teacher();
~ Teacher();
virtual void setGrade(Grade egrade=norProf){}
virtual void getSalary()=0; //纯虚函数,计算工资总数
virtual void disp()=0; //纯虚函数,显示教工基本信息
};
class NorProf: virtual public Teacher //声明教学人员派生类
{
protected:
double ClassHour; //每月授课课时数
double HourPay; //每课时补助
public:
NorProf();
void setGrade(Grade);
void getSalary();
void disp();
};
class ResProf:virtual public Teacher //声明研究人员派生类
{
protected:
double ResMoney; //每月承担科研经费总数
double RateRes; //提成
public:
ResProf();
void setGrade(Grade);
void getSalary();
void disp();
};
class SpecProf:public NorProf,public ResProf //声明特聘教授派生类,它从教学人员,研究人员派生
{

private:
double MonSalary; //特聘教授的每月固定津贴
public:

SpecProf();
void setGrade(Grade);
void getSalary();
void disp();
};
class RespProf:public NorProf,public ResProf //声明责任教授派生类,它从教学人员,研究人员派生
{
private:
double MonSalary;
public:
RespProf();
void setGrade(Grade);
void getSalary();
void disp();
};
//类的实现.cpp
int Teacher::nCount=12000; //用类名限定初始化
Teacher::Teacher():basicSalary(800.0),eGrade(norProf) //基类构造函数
{
char name[30];
cout<>name;
cout<>age;
eName=new char[strlen(name)+1];
strcpy(eName,name);
nCount++;
nNo=nCount;
}
Teacher::~Teacher() //基类析构函数
{
delete eName;
}
SpecProf::SpecProf():MonSalary(10000.0) //特聘教授构造函数
{
HourPay=8.0;
RateRes=0.01;
}
void SpecProf::setGrade(Grade) //特聘教授级别设定
{
Teacher::setGrade(specProf);
}
void SpecProf::getSalary() //特聘教授工资计算函数
{
cout<<"Please input the classHours of one month for"< cout<>ClassHour;
cout< cout<<"Please input the research money of one month for"< cout<>ResMoney;
cout< //特聘教授工资由基本工资,津贴,课时补助,科研经费提成组成
basicSalary=basicSalary+MonSalary+HourPay*ClassHour+RateRes*ResMoney;
cout<}
void SpecProf::disp() //特聘教授有关信息显示函数
{
cout<<"Special Prof."< cout<<"This is the basic message of "<}
RespProf::RespProf():MonSalary(5000.0) //责任教授构造函数
{
HourPay=8.0;
RateRes=0.01;
}
void RespProf::setGrade(Grade) //责任教授级别设定函数
{
Teacher::setGrade(respProf);
}
void RespProf::getSalary() //责任教授工资计算函数
{
cout<<"Please input the classhours of one month for"< cout<>ClassHour;
cout< cout<<"Please input the reseach money of one month for" < cout<>ResMoney;
cout< //责任教授工资由基本工资,津贴,课时补助,科研经费提成组成
basicSalary=basicSalary+MonSalary+HourPay*ClassHour+RateRes*ResMoney;
cout<}
void RespProf::disp() //责任教授有关信息显示函数
{
cout<<"Responsible Prof."< cout<<"This is the basic message of "<}
NorProf::NorProf():HourPay(8.0) // 教学人员构造函数
{}

void NorProf::setGrade(Grade) //教学人员级别设定函数
{
Teacher::setGrade(norProf);
}
void NorProf::getSalary() //教学人员工资计算函数
{
cout<<"Please input the classhours of one month for"< cout<>ClassHour;
//教学人员工资由基本工资,课时补助组成
basicSalary=basicSalary+ClassHour*HourPay;
cout<}
void NorProf::disp() //教学人员有关信息显示函数
{
cout<<"Normal Prof."< cout<<"This is the basic message of"<}
ResProf::ResProf():RateRes(0.01) // 科研人员构造函数
{}
void ResProf::setGrade(Grade) // 科研人员级别设定函数
{
Teacher::setGrade(resProf);
}
void ResProf::getSalary() //科研人员工资计算函数
{
cout<<"Please input the reseach money of one month for" < cout<>ResMoney;
//研究人员工资由基本工资,科研经费提成组成
basicSalary=basicSalary+ RateRes*ResMoney;
cout<}
void ResProf::disp() //科研人员有关信息显示函数
{
cout<<"Research Prof."< cout<<"This is the basic message of "< ptrTeacher->getSalary();
ptrTeacher->disp();
ptrTeacher=&teacher2;
ptrTeacher->setGrade();
ptrTeacher->getSalary();
ptrTeacher->disp();
ptrTeacher=&teacher3;
ptrTeacher->setGrade();
ptrTeacher->getSalary();
ptrTeacher->disp();
ptrTeacher=&teacher4;
ptrTeacher->setGrade();
ptrTeacher->getSalary();
ptrTeacher->disp();
}