此题目不能改main函数里面,只需要将函数的定义部分补全即可,我自己做了一下,但是知道有很多错误的地方,请大家指出我错处的地方,并请告诉我原因.以便小弟以后注意.
#include <iostream.h>
#include <string.h>
class Employee
{
public:
Employee(const char *);
void print();
~Employee();
private:
char *name
};
class HourlyWorker : public Employee
{
public:
HourlyWorker( const char*, double, double);
double getPay(); //计算并返回每周的薪水
void print(); //打印姓名和周薪
private:
double wage; //每小时的薪水
double hours; //每周工作的小时数
};
Employee::Employee(const char *t_name)
{
name = new char[strlen(t_name)+1];
name = t_name;
}
Employee::~Employee()
{
delete []name;
}
Employee::void print()
{
cout<<name;
}
HourlyWorker::HourlyWorker(const char* t_name, double x, double s)
{
t_name = //不知勒饫锏某A縯_name,是不是已经在基类里面赋值了,
wage = s;
hours = x;
}
HourlyWorker::double getPay()
{
return (wage*hours);
}
HourlyWorker::void print()
{
cout<<name;
cout<<"的周薪是:";
cout<<getPay();
}
HourlyWorker::~HourlyWorker()
{
//不知道该析构函数应该做什么?
}
int main()
{
HourlyWorker h("王大明", 40.0, 10.00);
h.print();
return 0;
}
[此贴子已经被作者于2005-5-20 10:08:12编辑过]