一个c++作业,求高手解答
来源:百度知道 编辑:UC知道 时间:2024/05/30 10:23:36
#include <iostream.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
//定义头文件。
class Employee{ //定义class employee。其中包括构造函数,析构函数,和两个返回char *的函数等。
public:
Employee(const char*,const char*);
~Employee();
const char *getfirstName()const;
const char *getlastName()const;
virtual float earning()const=0;//定义虚函数,这儿是纯虚函数。下同。
virtual void print()const=0;
private:
char *firstname; //两个私有的数据成员。
char *lastname;
};
Employee::Employee(const char *first,const char *last){
firstname=new char[strlen(first)+1];
lastname=new char[strlen(last)+1];// 为firstname,lastname分配内存空间。
assert(firstname!=NULL);
assert(lastname!=NULL); //测试分配成功与否。
strcpy(firstname,first);
strcpy(lastname,last); //把值拷贝在firstname,及lastname中。
}
const char* Employee::getfirstName()const{