Update 编程实例.cpp

This commit is contained in:
Jimp 2021-12-11 13:47:34 +08:00 committed by GitHub
parent 388564c9d9
commit 221daa9bb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,92 +1,92 @@
/* /*
800 800
15% 15%
Employee Employee
*/ */
#include <iostream> #include <iostream>
#include <string> #include <string>
using namespace std; using namespace std;
class Employee{ class Employee{
public: public:
Employee(string Name ,string id){ name=Name; Id=id; } Employee(string Name ,string id) : name(Name), Id(id){ }
string getName(){ return name; } //返回姓名 string getName() const { return name; } //返回姓名
string getID(){ return Id; } //返回身份证号 string getID() const { return Id; } //返回身份证号
float getSalary(){ return 0.0; } //返回薪水 virtual float getSalary() const { return 0.0; } //返回薪水
void print(){ //输出姓名和身份证号 virtual void print() const { //输出姓名和身份证号
cout<<"姓名: "<<name<<"\t\t 编号: "<<Id<<endl; cout<<"姓名: "<<name<<"\t\t 编号: "<<Id<<endl;
} }
private: private:
string name; string name;
string Id; string Id;
};
class Manager:public Employee{
public:
Manager(string Name,string id,int week):Employee(Name,id){
WeeklySalary=week*1000;
}
float getSalary(){ return WeeklySalary; } //获取经理的周薪
void print(){ //打印经理姓名、身份证、周薪
cout<<"经理:"<<getName()<<"\t\t 编号: "<<getID()
<<"\t\t 总工资: "<<getSalary()<<endl;
}
private:
float WeeklySalary; //周薪
}; };
class Manager:public Employee{
public:
Manager(string Name,string id,int week):Employee(Name,id){
WeeklySalary=week*1000;
}
float getSalary() const { return WeeklySalary; } //获取经理的周薪
void print() const { //打印经理姓名、身份证、周薪
cout<<"经理:"<<getName()<<"\t\t 编号: "<<getID()
<<"\t\t 总工资: "<<getSalary()<<endl;
}
private:
float WeeklySalary; //周薪
};
class SaleWorker:public Employee{ class SaleWorker:public Employee{
public: public:
SaleWorker(string name,string id,int profit,int x):Employee(name,id){ SaleWorker(string name,string id,int profit,int x):Employee(name,id){
workerMoney=baseMoney+x*0.05*profit; workerMoney=baseMoney+x*0.05*profit;
} }
float getSalary(){ float getSalary() const {
return workerMoney; return workerMoney;
} }
void print(){ void print() const {
cout<<"销售员:"<<getName()<<"\t\t 编号: "<<getID() cout<<"销售员:"<<getName()<<"\t\t 编号: "<<getID()
<<"\t\t 总工资: "<<getSalary()<<endl; <<"\t\t 总工资: "<<getSalary()<<endl;
} }
private: private:
float baseMoney=800.0; float baseMoney=800.0;
float workerMoney; float workerMoney;
};
class HourWorker:public Employee{
public:
HourWorker(string name,string id,int h):Employee(name,id){
TotalMoney=h*hourMoney;
}
float getSalary(){
return TotalMoney;
}
void print(){
cout<<"小时工:"<<getName()<<"\t\t 编号: "<<getID()
<<"\t\t 总工资: "<<getSalary()<<endl;
}
private:
float hourMoney=100.0;
float TotalMoney;
}; };
class HourWorker:public Employee{
public:
HourWorker(string name,string id,int h):Employee(name,id){
TotalMoney=h*hourMoney;
}
float getSalary() const {
return TotalMoney;
}
void print() const {
cout<<"小时工:"<<getName()<<"\t\t 编号: "<<getID()
<<"\t\t 总工资: "<<getSalary()<<endl;
}
private:
float hourMoney=100.0;
float TotalMoney;
};
int main(){ int main(){
cout<<"请输入工作周:"; cout<<"请输入工作周:";
int week; int week;
cin>>week; cin>>week;
Manager m("小王","11111111",week); Manager m("小王","11111111",week);
m.print(); m.print();
cout<<"请输入销售利润:"; cout<<"请输入销售利润:";
int profit; int profit;
cin>>profit; cin>>profit;
cout<<"请输入销售件数:"; cout<<"请输入销售件数:";
int x; int x;
cin>>x; cin>>x;
SaleWorker s("小李","222222",profit,x); SaleWorker s("小李","222222",profit,x);
s.print(); s.print();
cout<<"请输入工作小时:"; cout<<"请输入工作小时:";
int hour; int hour;
cin>>hour; cin>>hour;
HourWorker h("小何","333333",hour); HourWorker h("小何","333333",hour);
h.print(); h.print();
system("pause"); system("pause");
return 0; return 0;
} }