文档库 最新最全的文档下载
当前位置:文档库 › 老板雇员小时工营销继承Person类C++源程序

老板雇员小时工营销继承Person类C++源程序

//实验七.cpp
#include <iostream>
#include <string>
using namespace std;

//----class Person-----------
class Person
{
private:
char name[20];
int num;
int age;
char sex;
public:
Person(){};
Person(char *,int,int,char);
virtual ~Person(){};

virtual double getPay()=0;
virtual void print();
};

Person::Person(char *p_name,int p_num,int p_age,char p_sex)
{
strcpy(name,p_name);
num=p_num;
age=p_age;
sex=p_sex;
}
void Person::print()
{
cout<<name<<" ";
cout<<num<<" "<<age<<" "<<sex<<" "<<endl;
}

//------class Boss-----------
class Boss:public Person
{
private:
double pay;
public:
Boss(){};
Boss(char *,int,int,char,double);
virtual ~Boss(){};

void setPay(double);
virtual double getPay();
virtual void print();
};

Boss::Boss(char *p_name,int p_num,int p_age,char p_sex,double p_pay)
:Person(p_name,p_num,p_age,p_sex)
{
pay=p_pay;
}
void Boss::setPay(double p_pay)
{
pay=p_pay;
}
double Boss::getPay()
{
return pay;
}
void Boss::print()
{
Person::print();
cout<<pay<<endl;
}

//----------class Employee-----------------------
class Employee:public Person
{
private:
double wage;
double bonus;
public:
Employee(){};
Employee(char *,int,int,char,double,double);
virtual ~Employee(){};

void setPay(double,double);
virtual double getPay();
virtual void print();
};

Employee::Employee(char *p_name,int p_num,int p_age,char p_sex,double p_wage,
double p_bonus):Person(p_name,p_num,p_age,p_sex)
{
wage=p_wage;
bonus=p_bonus;
}
void Employee::setPay(double p_wage,double p_bonus)
{
wage=p_wage;
bonus=p_bonus;
}
double Employee::getPay()
{
return wage+bonus;
}
void Employee::print()
{
Person::print();
cout<<wage<<" "<<bonus<<endl;
}
//---------class HourlyWorker--------------------
class HourlyWorker:public Person
{
private:
double worktime;
double price;
public:
HourlyWorker(){};
HourlyWorker(char *,int,int,char,double,double);
virtual ~HourlyWorker(){};

void setPay(double,double);
virtual double getPay();
virtual void print();
};

HourlyWorker::HourlyWorker(char *p_name,int p_num,int p_age,char p_sex,
double p_work,double p_price):Person(p_name,p_num,p_age,p_sex)
{
worktime=p_work;
price=p_price;
}
void HourlyWorker::setPay(double p_work,double p_price)
{
worktime=p_work;
price=p_price;
}
double HourlyWorker::getPay()
{
return worktime*price;
}
void HourlyWorker::print()
{
Person::print();
cout<<worktime<<" "<<price<<endl;
}

//-------------class CommWorker------------------
class CommWorker:public Person
{
private:
double wage;
double profitonsale;
public:
CommWorker(){};
CommWorker(char *,int,int,char,double,double);
virtual ~CommWorker(){};

void setPay(double,double);
virtu

al double getPay();
virtual void print();
};

CommWorker::CommWorker(char *p_name,int p_num,int p_age,char p_sex,
double p_w
age,double p_profitonsale):Person(p_name,p_num,p_age,p_sex)
{
wage=p_wage;
profitonsale=p_profitonsale;
}
void CommWorker::setPay(double p_wage,double p_profitonsale)
{
wage=p_wage;
profitonsale=p_profitonsale;
}
double CommWorker::getPay()
{
return wage+profitonsale*0.05;
}
void CommWorker::print()
{
Person::print();
cout<<wage<<" "<<profitonsale<<endl;
}

//---------------------------
void test(Person &p)
{
p.print();
cout<<"pay:"<<p.getPay()<<endl;
}
void main()
{
Boss boss1("黄春秀",2201,35,'f',150000);
Employee employee1("刘大海",2203,27,'m',6300,1205.48);
HourlyWorker hourlyworker("Alice Munro",2207,82,'f',35.2,218.59);
CommWorker dmk("杜茂康",2210,48,'m',10500.56,780000);
test(boss1);
test(employee1);
test(hourlyworker);
test(dmk);
}

相关文档