📄 b_7_1.cpp
字号:
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
class employee
{
protected:
int no;
string name;
string duty;
float salary;
static int beginNO;
public:
employee(string tempDuty="职工")
:duty(tempDuty)
{
// duty = tempDuty;
no=beginNO++;
cout<<duty << "姓名:";
cin>> name;
salary=0;
}
~employee()
{
}
//void pay(){}
void display()
{
cout<<duty<<name<<"(编号为"<<no\
<<")"<<"本月工资:"<<salary<<endl;
}
};
int employee::beginNO=100; // 职工起始编号
class technician:public employee
{
private:
float hourlyrate;
int workhours;
public:
technician()
:employee("兼职技术人员")
{ hourlyrate=80;
}
void pay()
{
cout<<name<<"本月工作时数:";
cin>>workhours;
salary=hourlyrate*workhours;
}
};
class saleman:virtual public employee
{
protected:
float commrate;
float sales;
public:
saleman()
:employee("销售员")
{commrate=0.06f;}
void pay()
{
cout<<name<<"本月的销售额:";
cin>>sales;
salary=sales*commrate;
}
};
class manager:virtual public employee
{
protected:
float monthlypay;
public:
manager()
:employee("总经理")
{
monthlypay=10000;
}
void pay(){salary=monthlypay;}
};
class salesmanager:public manager,public saleman
{
public:
salesmanager()
:employee("销售经理")
{
monthlypay=5000;
commrate=0.004f;
}
void pay()
{
cout<<name<<"所负责部门的月销售量:";
cin>>sales;
salary=monthlypay+commrate*sales;
}
};
void main()
{
manager m1;
technician t1;
saleman s1;
salesmanager sm1;
m1.pay();
m1.display();
t1.pay();
t1.display();
s1.pay();
s1.display();
sm1.pay();
sm1.display();
cin.get(); cin.get(); //等待结束,以便调测程序,可以删除
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -