我刚做过
但不是太好
你看一下
#include<iostream.h>
extern"C"{
#include<string.h>
}
class employee
{//基类
private:
char * num;
char * name;
public:
employee()
{
num=0;
name=0;
}
employee(char * num1,char * name1 )
{
num= new char[4];
strcpy(num,num1);
name=new char [strlen(name1)+1];
strcpy(name,name1);
}
~employee()
{
delete [] num;
delete [] name;
}
void print()const
{
cout<<"num:"<<num<<endl;
cout<<"name:"<<name<<endl;
}
};
class part:public employee
{ //兼职技术员
private:
int hour;
float salary;
public:
part(char * num1,char *name1,int h)
:employee(num1,name1)
{
hour=h;
salary=float(100*hour);
}
void print()const
{
employee::print();
cout<<"position:"<<"part(兼职技术员)"<<endl;
cout<<"salary:"<<salary<<endl;
cout<<endl;
}
};
class sales :public employee
{//销售员
private:
int amount;
float salary;
public:
sales(char * num1,char * name1,int am)
:employee(num1,name1)
{
amount=am;
salary=float(0.4*amount);
}
void print()const
{
employee::print();
cout<<"position:"<<"sales(销售员)"<<endl;
cout<<"salary:"<<salary<<endl;
cout<<endl;
}
};
class manager : public employee
{//经理
private:
float salary;
public:
manager(char *num1,char * name1,float salary1)
:employee(num1,name1)
{
salary=8000;
}
void print()const
{
employee::print();
cout<<"position:"<<"manager(经理)"<<endl;
cout<<"salary:"<<salary<<endl;
cout<<endl;
}
};
class salemanager:public employee
{//销售经理
private:
float salary;
int totalamount;
public:
salemanager(char *num1,char * name1,int tamount)
:employee(num1,name1)
{
totalamount=tamount;
salary=float(5000+0.04*totalamount);
}
void print ()const
{
employee::print ();
cout<<"position:"<<"salemanager(销售经理)"<<endl;
cout<<"salary:"<<salary<<endl;
}
};
void main()
{
manager m1("001","li",8000);
manager m2("002","wang",0);
part p1("003","liu",20);
sales s1("004","han",5000);
salemanager sm1("005","zheng",10000);
m1.print();
m2.print ();
p1.print ();
s1.print ();
sm1.print ();
}