C++实例员工信息
假设某销售公司有一般员工、销售员工和销售经理。月工资的计算办法是:
一般员工月薪=基本工资;
销售员工月薪=基本工资+销售额提成率;
销售经理月薪=基本工资+职务工资+销售额提成率。
编写程序,定义一个表示一般员工的基类Employee,它包含三个表示员工基本信息的数据成员:编号
number、姓名name和基本工资basicSalary。
由Employee类派生销售员工Salesman类,Salesman类包含两个新数据成员:销售额sales和静态数据成
员提成比例commrate。
再由Salesman类派生表示销售经理的Salesmanager类。Salesmanager类包含新数据成员:岗位工资
jobSalary。
为这些类定义初始化数据的构造函数,以及输入数据input、计算工资pay和输出工资条print的成员函
数。
设公司员工的基本工资是2000元,销售经理的岗位工资是3000元,提成率=5/1000。在main函数中,
输入若干个不同类型的员工信息测试你的类结构。
#include<iostream>
#include<String.h>
using namespace std;
class Employee{
protected:
char number[5];
char name[10];
double basicSalary;
public: Employee(char number1[]="",char name1[]="",double basicSalary1=2000){
strcpy(number,number1);
strcpy(name,name1);
basicSalary=basicSalary1; }
void Input();
void Print(); };
void Employee::Input(){
cout<<"编号:" ;
cin>> number; cout<<"姓名:" ;
cin>> name; }
void Employee::Print() {
cout<<"编号:"<<this->number<<"\t普通员工:"<<this->name<<"\t本月工资:"<<this->basicSalary<<endl; }
class Salesman:public Employee{
protected:
int sales;
static double commrate;
public:
Salesman(int sales1=0){ sales=sales1; }
void input(){
Employee::Input();
cout<<"本月个人售额:";
cin>>this->sales; }
double Pay() {
double salary;
salary=basicSalary+sales*commrate;
return salary; }
void Print() {
cout<<"编号:"<<this->number<<"\t销售员:"<<this->name<<"\t本月工资:"<<this->Salesman::Pay()<<endl; }};
double Salesman:: commrate=0.005;
class Salesmanager:public Salesman{
public:
Salesmanager(double jSalary=3000){ jobSalary = jSalary; }
void input(){ Employee::Input(); cout<<"部门总销售额:"; cin>>this->sales; }
double Pay(){ double salary; salary =jobSalary +sales*commrate; return salary; }
void Print() { cout<<"编号:"<<this->number<<"\t销售经理:"<<this->name<<"\t本月工资:"<<this->Salesmanager::Pay()<<endl; }
protected:
double jobSalary; };
int main(){
cout<<"普通员工:"<<endl; Employee a; a.Input(); a.Print();
cout<<"销售员:"<<endl; Salesman b; b.input(); b.Print();
cout<<"销售经理:"<<endl; Salesmanager c; c.input();
c.Print(); }
本文作者:TwcatL_tree
本文链接:https://www.cnblogs.com/twcat/p/16912740.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】