33,321
社区成员




#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
class Person
{
protected:
string name,ID,sex,job;
int age;
double Sumsalary;
public:
Person();
string getID(){return ID;}
string getName(){return name;}
string getSex(){return sex;}
string getJob(){ return job;}
int getAge(){return age;}
double getSumsalary(){ return Sumsalary;}
void InputPerson();
virtual double getpay()=0;
friend ostream &operator <<(ostream &os,Person &In);
};
Person::Person()
{
ID="000000";
name="No Name";
age=0;
sex="No sex";
Sumsalary=0;
job="Wei zhi";
}
void Person::InputPerson()
{
cout<<"Please input ID:"<<endl;
cin>>ID;
cout<<"Plaese input name:"<<endl;
cin>>name;
cout<<"Plaese input age:"<<endl;
cin>>age;
cout<<"Plaese input sex:"<<endl;
cin>>sex;
}
ostream & operator<<(ostream &os,Person &In)
{
os<<In.ID<<" "<<In.name<<" "<<In.job<<" "<<In.age<<" "<<In.sex<<" "<<In.getpay()<<endl;
return os;
}
class Boss:public Person
{
double salary;
int year;
public:
Boss();
void Input();
virtual double getpay();
};
Boss::Boss()
{
job="Boss";
salary=150000.0;
year=0;
}
void Boss::Input()
{
InputPerson();
cout<<"Please input Salary:"<<endl;
cin>>salary;
cout<<"Please input Year:"<<endl;
cin>>year;
}
double Boss::getpay()
{
return Sumsalary=salary*year;
}
class Employee:public Person
{
double salary,bonus;
int month;
public:
Employee();
void Input();
virtual double getpay();
};
Employee::Employee()
{
job="Employee";
salary=2000;
bonus=500;
month=0;
}
void Employee::Input()
{
InputPerson();
cout<<"Please input Salary:"<<endl;
cin>>salary;
cout<<"Please input Bonus:"<<endl;
cin>>bonus;
cout<<"Please input Month:"<<endl;
cin>>month;
}
double Employee::getpay()
{
return Sumsalary=(salary+bonus)*month ;
}
class Hourly_Worker :public Person
{
double salary;
int hour;
public:
Hourly_Worker();
void Input();
virtual double getpay();
};
Hourly_Worker::Hourly_Worker()
{
job="Hourly_Worker";
salary=15;
hour=0;
}
void Hourly_Worker::Input()
{
InputPerson();
cout<<"Please input Salary:"<<endl;
cin>>salary;
cout<<"Please input Hour:"<<endl;
cin>>hour;
}
double Hourly_Worker::getpay()
{
return Sumsalary=salary*hour;
}
class Comm_Worker :public Person
{
double salary,profit;
int month;
public:
Comm_Worker();
void Input();
virtual double getpay();
};
Comm_Worker::Comm_Worker()
{
job="Comm_Worker";
salary=1800;
profit=20000;
month=0;
}
void Comm_Worker::Input()
{
InputPerson();
cout<<"Please input Salary:"<<endl;
cin>>salary;
cout<<"plaese input Profit:"<<endl;
cin>>profit;
cout<<"plaese input Month:"<<endl;
cin>>month;
}
double Comm_Worker::getpay()
{
return Sumsalary=month*(salary+profit*0.05) ;
}
class report
{
public:
void add();
void search();
void del();
void print();
};
void report::print()
{
ifstream ioFile("EmployeeInfo.txt",ios::in);
if(ioFile.fail())
{
perror("ioFile");
cout<<"Cannot open the file!\n";
return ;
}
string id,Name,Sex,Job;
int Age;
double Salary;
ioFile>>id;
while(ioFile.peek()!=EOF)
{
ioFile>>Name>>Job>>Age>>Sex>>Salary;
cout<<id<<"\t "<<Name<<"\t"<<Job<<"\t"<<Age<<"\t"<<Sex<<"\t"<<Salary<<endl;
ioFile>>id;
}
ioFile.close();
}
void report::add()
{
int choice1;
char ch;
cout<<"要添加员工的信息吗(y):";
cin>>ch;
Boss p1;
Employee p2;
Hourly_Worker p3;
Comm_Worker p4;
while(ch=='y')
{
ofstream ioFile("EmployeeInfo.txt",ios::out|ios::app);
if(!ioFile)
{
cout<<"Can not open the file!"<<endl;
return ;
}
cout<<"请选择类型:"<<endl;
cout<<"----------------------------------------------------------------"<<endl;
cout<<"1 BOss"<<setw(6)<<"│"<<" 2 Employee"<<setw(6)<<"│"<<"3 Hourly_Worker"<<
setw(6)<<"│"<<"4 Comm_Worker"<<"│"<<endl;
cout<<"----------------------------------------------------------------"<<endl;
cin>>choice1;
switch(choice1)
{
case 1:
p1.Input();
ioFile<<p1;
break;
case 2:
p2.Input();
ioFile<<p2;
break;
case 3:
p3.Input();
ioFile<<p3;
break;
case 4:
p4.Input();
ioFile<<p4;
break;
}
ioFile.close();
cout<<"继续添加员工信息吗?(y/n):";
cin>>ch;
}
cout<<"添加成功......"<<endl;
}
void report::search()
{
string id,Name,Sex,Job;
int Age;
double Salary;
string number;
int ok=0;
cout<<"请输入要查询的工作号:"<<endl;
cin>>number;
ifstream ioFile("EmployeeInfo.txt",ios::in);
if(ioFile.fail())
{
perror("ioFile");
cout<<"Cannot open the file!\n";
return ;
}
cout<<"正在寻找,请等待……"<<endl;
ioFile>>id;
while(ioFile.peek()!=EOF)
{
if(id==number)
{
ioFile>>Name>>Job>>Age>>Sex>>Salary;
cout<<id<<"\t "<<Name<<"\t"<<Job<<"\t"<<Age<<"\t"<<Sex<<"\t"<<Salary<<endl;
ok=1;
break;
}
else
ioFile>>id;
}
if(ok)
cout<<number<<"已经成功找到"<<endl;
else
cout<<number<<"不存在,寻找失败!"<<endl;
ioFile.close();
}
void report::del()
{
string id,Name,Sex,Job,number;
int Age;
double Salary;
cout<<"请输入您要删除员工的编号:"<<endl;
cin>>number;
ifstream ioFile("EmployeeInfo.txt",ios::in);
ofstream temp("TempEmployeeInfo.txt",ios::trunc);
ioFile>>id;
while(ioFile.peek()!=EOF)
{
ioFile>>Name>>Job>>Age>>Sex>>Salary;
if(id!=number)
temp<<id<<" "<<Name<<" "<<Job<<" "<<Age<<" "<<Sex<<" "<<Salary<<endl;
ioFile>>id;
}
ioFile.close();
ofstream ioFile1("EmployeeInfo.txt",ios::trunc);
temp.close();
ifstream temp1("TempEmployeeInfo.txt",ios::in);
temp1>>id;
while(temp1.peek()!=EOF)
{
temp1>>Name>>Job>>Age>>Sex>>Salary;
ioFile1<<id<<" "<<Name<<" "<<Job<<" "<<Age<<" "<<Sex<<" "<<Salary<<endl;
temp1>>id;
}
temp1.close();
ioFile1.close();
cout<<"正在删除,请等待……"<<endl;
cout<<number<<"已经成功删除"<<endl;
}
class Interface
{
public:
void displayInterface();
void displayWdb();
};
void Interface::displayInterface()
{
cout<<" ☆☆☆☆人事管理管理系统☆☆☆☆" <<endl;
cout<<"* * * * * * * * * * * * * * * * * * * * * * * * * * * *"<<endl
<<"* * * * * * * * * * * * * * * * * * * * * * * * * * * *"<<endl
<<"* * 1: 录入员工信息 * *"<<endl
<<"* * 2: 显示员工信息 * *"<<endl
<<"* * 3: 查找员工信息 * *"<<endl
<<"* * 4: 删除员工信息 * *"<<endl
<<"* * 5: 退出系统 * *"<<endl
<<"* * * * * * * * * * * * * * * * * * * * * * * * * * * *"<<endl
<<"* * * * * * * * * * * * * * * * * * * * * * * * * * * *"<<endl
<<" 请选择:";
}
void Interface::displayWdb()
{
cout<<"-----------------------------------------------------------------------"<<endl;
cout<<"工作号"<<setw(6)<<"│"<<setw(6)<<"姓名"<<setw(6)<<"│"<<setw(6)<<"职位"<<setw(6)
<<"│"<<setw(6)<<"年龄"<<setw(6)<<"│";
cout<<setw(6)<<"性别"<<setw(6)<<"│"<<setw(6)<<"工资"<<setw(6)<<"│"<<endl;
cout<<"-----------------------------------------------------------------------"<<endl;
}
int main()
{
system("color 006");
Interface sys;
report cfy;
int choice;
sys.displayInterface();
while (1)
{
cin>>choice;
switch(choice)
{
case 1:
cfy.add();
break;
case 2:
sys.displayWdb();
cfy.print();
break;
case 3:
sys.displayWdb();
cfy.search();
break;
case 4:
cfy.del();
break;
case 5:
cout<<"欢迎使用本公司产品!"<<endl;
break;
}
if(choice==5)
break;
getchar();
getchar();
system("cls");
sys.displayInterface();
}
}