📄 公司.cpp
字号:
#include <iostream.h>
#include <iomanip.h>
#include <fstream.h>
#include <stdlib.h>
class Employee
{
public:
int number,age;
char name[10],sex[20];
float salary;
static int sum;
};
int Employee::sum=0;
class Technician:public Employee
{
private:
float hourlyrate;
int workhours;
public:
Technician(){hourlyrate=100;}
void pay();
void display();
};
class Salesman:public Employee
{
protected:
float commrate;
float sales;
public:
Salesman(){commrate=0.04;}
void pay();
void display();
void print();
void ff();
};
class Manager:public Employee
{
protected:
float monthlypay;
public:
Manager(){monthlypay =8000;}
void pay();
void display();
};
class Salesmanager:public Manager,public Salesman
{
public:
int number,age,i;
char name[10],sex[23];
float salary;
Salesmanager(){monthlypay=5000;commrate=0.005;}
void pay();
void display();
};
void Technician::pay()
{
cout<<"请输入技术员的职工号"<<endl;
cin>>number;
cout<<"请输入技术员的姓名"<<endl;
cin>>name;
cout<<"请输入技术员的性别"<<endl;
cin>>sex;
cout<<"请输入技术员的年龄"<<endl;
cin>>age;
cout<<"请输入技术员的工作时间"<<endl;
cin>>workhours;
salary=hourlyrate*workhours;
cout<<endl;
}
void Technician::display()
{
cout<<"│"<<setw(8)<<number<<"│"<<setw(8)<<name<<"│"<<setw(8)<<sex<<"│"<<setw(8)<<age<<"│"<<setw(8)<<"技术员"<<"│"<<setw(8)<<salary<<" │"<<endl;
}
void Salesman::pay()
{
cout<<"请输入销售员的职工号"<<endl;
cin>>number;
cout<<"请输入销售员的姓名"<<endl;
cin>>name;
cout<<"请输入销售员的性别"<<endl;
cin>>sex;
cout<<"请输入销售员的年龄"<<endl;
cin>>age;
cout<<"请输入销售员的销售金额"<<endl;
cin>>sales;
sum+=sales;
salary=sales*commrate;
cout<<endl;
}
void Salesman::display()
{
cout<<"│"<<setw(8)<<number<<"│"<<setw(8)<<name<<"│"<<setw(8)<<sex<<"│"<<setw(8)<<age<<"│"<<setw(8)<<"销售员"<<"│"<<setw(8)<<salary<<"│"<<endl;
}
void Manager::pay()
{
cout<<"请输入经理的职工号"<<endl;
cin>>number;
cout<<"请输入经理的姓名"<<endl;
cin>>name;
cout<<"请输入经理的性别"<<endl;
cin>>sex;
cout<<"请输入经理的年龄"<<endl;
cin>>age;
salary=monthlypay;
cout<<endl;}
void Manager::display()
{
cout<<"│"<<setw(8)<<number<<"│"<<setw(8)<<name<<"│"<<setw(8)<<sex<<"│"<<setw(8)<<age<<"│"<<setw(8)<<"经理"<<"│"<<setw(8)<<salary<<"│"<<endl;
}
void Salesmanager::pay()
{
cout<<"请输入销售经理的职工号"<<endl;
cin>>number;
cout<<"请输入销售经理的姓名"<<endl;
cin>>name;
cout<<"请输入销售经理的性别"<<endl;
cin>>sex;
cout<<"请输入销售经理的年龄"<<endl;
cin>>age;
salary=monthlypay+commrate*sum;
cout<<endl;
}
void Salesmanager::display()
{
cout<<"│"<<setw(8)<<number<<"│"<<setw(8)<<name<<"│"<<setw(8)<<sex<<"│"<<setw(8)<<age<<"│"<<setw(8)<<"销售经理"<<"│"<<setw(8)<<salary<<"│"<<endl;
}
void Salesman::print()
{
cout<<"│"<<setw(10)<<number<<"│"<<setw(10)<<name<<"│"<<setw(10)<<sales<<"│"<<endl;
}
void Salesman::ff()
{
cout<<"│"<<setw(10)<<" 销售额合计:"<<setw(10)<<"│"<<setw(10)<<sum<<"│"<<endl;
}
void main()
{
int i,j;
fstream outfile;
Employee employee[5];
Manager manager[1];
Technician technician[1];
Salesman salesman[2];
Salesmanager salesmanager[1];
char choice;
while(5)
{
cout<<" *******************菜单项****************"<<endl;
cout<<" *******1 请选择你要输入或输出的雇员******"<<endl;
cout<<" ******************2 退出*****************"<<endl;
cin>>choice;
switch(choice)
{
case '1':
cout<<" *****************请选择*******************"<<endl;
cout<<" ************3 输入雇员的状况**************"<<endl;
cout<<" ************4 输出雇员的状况**************"<<endl;
cout<<" ***************5 数据备份*****************"<<endl;
cout<<" *****************6 退出*******************"<<endl;
cin>>choice;
switch(choice)
{
case '3':
for(i=0;i<=0;i++)
technician[i].pay();
for(i=0;i<=0;i++)
manager[i].pay();
for(i=0;i<=0;i++)
salesman[i].pay();
for(i=0;i<=2;i++)
salesmanager[i].pay();
continue;
case '4':
cout<<"┌────┬────┬────┬────┬────┬────┐"<<endl;
cout<<"│ 职工号 │ 姓名 │ 性别 │ 年龄 │ 岗位 │ 工资 │"<<endl;
cout<<"├────┼────┼────┼────┼────┼────┤"<<endl;
for(i=0;i<=0;i++)
{
technician[i].display();
cout<<"├────┼────┼────┼────┼────┼────┤"<<endl;}
for(i=0;i<=0;i++)
{
manager[i].display();
cout<<"├────┼────┼────┼────┼────┼────┤"<<endl;}
for(i=0;i<=0;i++)
{
salesman[i].display();
cout<<"├────┼────┼────┼────┼────┼────┤"<<endl;}
for(i=0;i<=2;i++)
salesmanager[i].display();
cout<<"└────┴────┴────┴────┴────┴────┘"<<endl;
cout<<"┌─────┬─────┬─────┐"<<endl;
cout<<"│ 职工号 │ 姓名 │ 销售额 │"<<endl;
cout<<"├─────┼─────┼─────┤"<<endl;
for(i=0;i<=2;i++)
{
salesman[i].print();
if(i<2) cout<<"├─────┼─────┼─────┤"<<endl;
if(i==2)cout<<"├─────┴─────┼─────┤"<<endl;
}
salesman[2].ff();
cout<<"└───────────┴─────┘"<<endl;
continue;
case '5':
outfile.open("filc.txt",ios::out);
if(!outfile)
{
cout<<"filc.txt can't open.\n";
abort();
}
for( j=0;j<4;j++)
{
outfile.write((char*)&employee[j].number,sizeof(employee[j].number));
outfile.write((char*)&employee[j].name,sizeof(employee[j].name));
outfile.write((char*)&employee[j].sex,sizeof(employee[j].sex));
outfile.write((char*)&employee[j].age,sizeof(employee[j].age));
outfile.write((char*)&employee[j].salary,sizeof(employee[j].salary));
}
continue;
case '6':break;
}
case '2':break;
}break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -