#include<iostream>
#include<iomanip>
#include<fstream>
#include<string>
using namespace std;
struct jishujingli //职工信息结构体定义
{
char name[10]; //职工姓名
int level; //业绩等级
int salary; //职工工资
};
struct jishujingli jsjl; //定义一个全局变量jsjl,用来存放职工信息
struct xiaoshoujingli //职工信息结构体定义
{
char name[10]; //职工姓名
int profit; //总经额
int salary; //职工工资
};
struct xiaoshoujingli xsjl; //定义一个全局变量xsjl,用来存放职工信息
struct jishurenyuan //职工信息结构体定义
{
char name[10]; //职工姓名
int time; //工作时间
int salary; //职工工资
};
struct jishurenyuan jsry[3]; //定义一个全局变量jsry,用来存放职工信息
struct xiaoshourenyuan //职工信息结构体定义
{
char name[10]; //职工姓名
int sale; //销售总量
int salary; //职工工资
};
struct xiaoshourenyuan xsry[3]; //定义一个全局变量xsry,用来存放职工信息
struct wenmi //职工信息结构体定义
{
char name[10]; //职工姓名
int sale; //奖金
int salary; //职工工资
};
struct wenmi wm[2]; //定义一个全局变量wm,用来存放职工信息
int a=0,b=0,c=0; //存放实际输入的职工人数
void input() ; //录入职工信息函数声明
void show(); //显示职工信息函数声明
void save(); //存档
void getsave(); //打开存档
void account(); //计算当月公司总工资
int main()
{
int choose;
while(1)
{
cout<<"\t ******************欢迎使用******************"<<endl;
cout<<"\t ****************工资管理系统****************"<<endl;
cout<<"\t *------------------------------------------*"<<endl;
cout<<"\t * 1——录入员工信息 *"<<endl;
cout<<"\t * 2——显示员工信息 *"<<endl;
cout<<"\t * 3——存档 *"<<endl;
cout<<"\t * 4——打开存档 *"<<endl;
cout<<"\t * 0——退出 *"<<endl;
cout<<"\t *------------------------------------------*"<<endl;
cout<<"\t 你要输入的编号是(0--4):";
cin>>choose;
if(choose==0) break;
switch(choose){
case 1:
input();
break;
case 2:
show();
break;
case 3:
save();
cout<<" ********************************************"<<endl;
cout<<" *********************以存档*****************"<<endl;
cout<<" ********************************************"<<endl;
break;
case 4:
getsave();
cout<<" ********************************************"<<endl;
cout<<" *********************以读取*****************"<<endl;
cout<<" ********************************************"<<endl;
break;
default:
cout<<"没有此选项,请重新选择!"<<endl;
cout<<" ********************************************"<<endl;
cout<<" ***********没有此选项,请重新选择!**********"<<endl;
cout<<" ********************************************"<<endl;
}
}
return 0;
}
void input()
{
cout<<endl<<"\t技术经理姓名:";
cin>>jsjl.name;
cout<<"\t业绩等级(1~3):";
cin>>jsjl.level;
jsjl.salary=5000+1000*jsjl.level;
cout<<"\t当月工资(元):"<<jsjl.salary<<endl;
cout<<endl<<"\t销售经理姓名:";
cin>>xsjl.name;
cout<<"\t总经额(元):";
cin>>xsjl.profit;
xsjl.salary=5000+(xsjl.profit*3)/1000;
cout<<"\t当月工资(元):"<<xsjl.salary<<endl;
do
{
cout<<endl<<"\t技术人员姓名:";
cin>>jsry[a].name;
cout<<"\t工作时间(小时):";
cin>>jsry[a].time;
jsry[a].salary=40*jsry[a].time;
cout<<"\t当月工资(元):"<<jsry[a].salary<<endl;
a++;
}while(a<3);
do
{
cout<<endl<<"\t销售人员姓名:";
cin>>xsry[b].name;
cout<<"\t销售总量(元):";
cin>>xsry[b].sale;
xsry[b].salary=(5*xsry[b].sale)/100;
cout<<"\t当月工资(元):"<<xsry[b].salary<<endl;
b++;
}while(b<3);
do
{
cout<<endl<<"\t文秘姓名:";
cin>>wm[c].name;
cout<<"\t奖金(元):";
cin>>wm[c].sale;
wm[c].salary=4000+wm[c].sale;
cout<<"\t当月工资(元):"<<wm[c].salary<<endl;
c++;
}while(c<2);
account();
}
void show()
{
cout<<left;
cout<<setw(20)<<"技术经理姓名"<<setw(20)<<"业绩等级"<<setw(12)<<"当月工资"<<endl;
cout<<setw(20)<<jsjl.name<<setw(20)<<jsjl.level<<setw(12)<<jsjl.salary<<endl;
cout<<setw(20)<<"销售经理姓名"<<setw(20)<<"总经额"<<setw(12)<<"当月工资"<<endl;
cout<<setw(20)<<xsjl.name<<setw(20)<<xsjl.profit<<setw(12)<<xsjl.salary<<endl;
cout<<setw(20)<<"技术人员姓名"<<setw(20)<<"工作时间"<<setw(12)<<"当月工资"<<endl;
for(int a=0;a<3;a++)
{
cout<<setw(20)<<jsry[a].name<<setw(20)<<jsry[a].time<<setw(12)<<jsry
[a].salary<<endl;
}
cout<<endl;
cout<<setw(20)<<"销售人员姓名"<<setw(20)<<"销售总量"<<setw(12)<<"当月工资"<<endl;
for(int b=0;b<3;b++)
{
cout<<setw(20)<<xsry[b].name<<setw(20)<<xsry[b].sale<<setw(12)<<xsry
[b].salary<<endl;
}
cout<<endl;
cout<<setw(20)<<"文秘姓名"<<setw(20)<<"奖金"<<setw(12)<<"当月工资"<<endl;
for(int c=0;c<2;c++)
{
cout<<setw(20)<<wm[c].name<<setw(20)<<wm[c].sale<<setw(12)<<wm[c].salary<<endl;
}
cout<<endl;
account();
}
void save()
{
ofstream fout;
fout.open("工资表.txt");
fout<<jsjl.name<<setw(8)<<jsjl.level<<setw(8)<<jsjl.salary<<endl;
fout<<xsjl.name<<setw(8)<<xsjl.profit<<setw(8)<<xsjl.salary<<endl;
fout<<jsry[0].name<<setw(8)<<jsry[0].time<<setw(8)<<jsry[0].salary<<endl;
fout<<jsry[1].name<<setw(8)<<jsry[1].time<<setw(8)<<jsry[1].salary<<endl;
fout<<jsry[2].name<<setw(8)<<jsry[2].time<<setw(8)<<jsry[2].salary<<endl;
fout<<xsry[0].name<<setw(8)<<xsry[0].sale<<setw(8)<<xsry[0].salary<<endl;
fout<<xsry[1].name<<setw(8)<<xsry[1].sale<<setw(8)<<xsry[1].salary<<endl;
fout<<xsry[2].name<<setw(8)<<xsry[2].sale<<setw(8)<<xsry[2].salary<<endl;
fout<<wm[0].name<<setw(8)<<wm[0].sale<<setw(8)<<wm[0].salary<<endl;
fout<<wm[1].name<<setw(8)<<wm[1].sale<<setw(8)<<wm[1].salary<<endl;
}
void getsave()
{
ifstream fin;
fin.open("工资表.txt");
fin>>jsjl.name>>jsjl.level>>jsjl.salary;
fin>>xsjl.name>>xsjl.profit>>xsjl.salary;
fin>>jsry[0].name>>jsry[0].time>>jsry[0].salary;
fin>>jsry[1].name>>jsry[1].time>>jsry[1].salary;
fin>>jsry[2].name>>jsry[2].time>>jsry[2].salary;
fin>>xsry[0].name>>xsry[0].sale>>xsry[0].salary;
fin>>xsry[1].name>>xsry[1].sale>>xsry[1].salary;
fin>>xsry[2].name>>xsry[2].sale>>xsry[2].salary;
fin>>wm[0].name>>wm[0].sale>>wm[0].salary;
fin>>wm[1].name>>wm[1].sale>>wm[1].salary;
}
void account()
{
int acsalery=jsjl.salary+xsjl.salary+jsry[0].salary+jsry[1].salary+jsry[2].salary+xsry
[0].salary+xsry[1].salary+xsry[2].salary+wm[0].salary+wm[1].salary;
cout<<endl<<"\t公司当月总工资(元):"<<acsalery<<endl;
}
1,.运行程序之后出现这样的界面,选择1,开始录入员工的信息。
2.开始录入员工信息,按照要求以此录入一个技术经理,一个销售经理,三个技术人员,三个销售人员,两个文秘的资料。
3输入2,显示已输入的员工数据。
4. 输入3,将输入的资料存档到txt文件中。
5. 关闭程序,重新打开后输入4打开存档。
6. 再输入2,就显示已经存档的资料