📄 employee.cpp
字号:
//=================================
//工资计算
//06030515 孙颖 2005/12
//=================================
#include<iostream>
#include<string>
#include<fstream>
//=================================
#include<cctype>
using namespace std;
class Employee//基类
{
public:
int id;
char name[10];
double salary;
virtual void display()=0;
};
//派生类 begin:
class Manager:virtual public Employee
{
public:
double basesalary;
void getdata()//get info
{
cout<<endl;
cout<<"Please enter id:";
cin>>id;
cout<<"Please enter name:";
cin>>name;
}
void calculator()
{
basesalary=8000;
salary=basesalary;
}
void display()
{
cout<<endl;
cout<<"Position:manager"<<endl;
cout<<"Id: "<<id<<endl;
cout<<"Name: "<<name<<endl;
cout<<"Salary: "<<"¥"<<salary<<endl;
}
};
class Technician:virtual public Employee
{
private:
float hour;
public:
void getdata()//获得信息
{
cout<<endl;
cout<<"Please enter id:";
cin>>id;
cout<<"Please enter name:";
cin>>name;
cout<<"Please enter the working hours of this month:";
cin>>hour;
if(hour<0||hour>400)
{
cout<<"The data is wrong,and enter the working hours again:";
cin>>hour;
}
}
void calculator()//计算月薪
{
salary=hour*100;
}
void display()
{
cout<<endl;
cout<<"Position:Technician"<<endl;
cout<<"Id: "<<id<<endl;
cout<<"Name: "<<name<<endl;
cout<<"Salary: "<<"¥"<<salary<<endl;
}
};
class Salesman:virtual public Employee
{
public:
double sale;
double rate;
void getdata()//获得信息
{
cout<<endl;
cout<<"Please enter id:";
cin>>id;
cout<<"Please enter name:";
cin>>name;
cout<<"Please enter the total sale of this month:";
cin>>sale;
if(sale<0)
{
cout<<"The data is wrong,and enter the sale again:";
cin>>sale;
}
}
void calculator()//计算月薪
{
rate=0.04;
salary=sale*rate;
}
void display()//显示结果
{
cout<<endl;
cout<<"Position:Salesman"<<endl;
cout<<"Id: "<<id<<endl;
cout<<"Name: "<<name<<endl;
cout<<"Salary: "<<"¥"<<salary<<endl;
}
};
//salesmanager
class Salesmanager:public Salesman,public Manager
{
public:
void getdata()//获得信息
{
cout<<endl;
cout<<"Please enter id:";
cin>>id;
cout<<"Please enter name:";
cin>>name;
cout<<"The total sale of departments charged by him/her in this month:";
cin>>sale;
}
void calculator()//计算月薪
{
basesalary=5000;
rate=0.005;
salary=basesalary+sale*rate;
}
void display()//显示结果
{
cout<<endl;
cout<<"Position: Salesmanager"<<endl;
cout<<"Id: "<<id<<endl;
cout<<"Name: "<<name<<endl;
cout<<"Salary: "<<"¥"<<salary<<endl;
}
};
//派生类 end
void main()
{
int number=0;
bool check=true;
do
{
cout<<"****************************"<<endl;
cout<<"* System of Monthly Pay *"<<endl;
cout<<"* 1.Manager *"<<endl;
cout<<"* 2.Technician *"<<endl;
cout<<"* 3.Salesman *"<<endl;
cout<<"* 4.Salesmanager *"<<endl;
cout<<"* 5.Exit *"<<endl;
cout<<"****************************"<<endl;
cout<<"Please choose the number(1-5):";
check=false;
cin>>number;
switch(number){
case 1:
{
Manager m;
m.getdata();
m.calculator();
m.display();
}break;
case 2:
{
Technician t;
t.getdata();
t.calculator();
t.display();
}break;
case 3:
{
Salesman s1;
s1.getdata();
s1.calculator();
s1.display();
}break;
case 4:
{
Salesmanager s2;
s2.getdata();
s2.calculator();
s2.display();
}break;
case 5:exit(0);
default:cout<<"no this number for chosing,Please enter a number from 1 to 5!"<<endl;
//check=false;
//cout<<endl;
}
}while(!check);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -