#include<iostream>
#include<cstring>
#include<iomanip>
using namespace std;
#define M 100
class staff //职工信息类的声明
{
public:
void input(); //录入职工信息函数声明
void show(); //显示职工信息函数声明
void del(); //删除职工信息函数声明
void add(); //添加职工信息函数声明
void change(); // 修改职工信息函数声明
void search(); //查询职工信息函数声明
private:
int num; //职工号
static int n; //静态数据成员n,用来存放实际输入的职工人数
char name[10]; //职工姓名
char tel[12]; //职工电话
char addr[30]; //职工住址
int wage; //职工成绩
};
class staff sta[M]; //定义一个全局数组sta,用来存放职工信息,最多存放100个职工
int staff::n=0; //静态数据成员n的定义及初始化
int main()
{
int select;
while(1)
{
system("cls");
cout<<"\t ******************欢迎使用******************\n";
cout<<"\t ***********银行职工信息管理系统*************\n";
cout<<"\t *------------------------------------------*\n";
cout<<"\t * 1——录入职工信息 *\n";
cout<<"\t * 2——显示职工信息 *\n";
cout<<"\t * 3——查询职工信息 *\n";
cout<<"\t * 4——修改职工信息 *\n";
cout<<"\t * 5——添加职工信息 *\n";
cout<<"\t * 6——删除职工信息 *\n";
cout<<"\t * 0——退出 *\n";
cout<<"\t *------------------------------------------*\n";
cout<<"\t 你要的编号是(0):";
cin>>select;
if(select==0) break;
}
staff s ; //定义一个职工类的对象s
s.input(); //录入职工信息函数调用
s.show(); //显示职工信息函数调用
s.search(); //查询职工信息函数调用
s.change(); // 修改职工信息函数调用
s.add(); //添加职工信息函数调用
s.del(); //删除职工信息函数调用
return 0;
}
void staff::input() //录入职工信息的函数
{
char sel;
do
{
n++;
cout<<"\n请输入第"<< n <<"个职工信息:\n";
cout<<"\t职工编号:";
cin>>sta[n].num;
cout<<"\t职工姓名:";
cin>>sta[n].name;
cout<<"\t职工电话:";
cin>>sta[n].tel;
cout<<"\t职工住址:";
cin>>sta[n].addr;
cout<<"\t职工工资:";
cin>>sta[n].wage;
cout<<"是否要继续录入职工信息(Y/N):";
cin>>sel;
}while(sel=='Y' || sel=='y' );
}
void staff::show() //显示所有职工信息函数
{
cout<<left; //设置输出左对齐
cout<<setw(10)<<"职工编号"<<setw(10)<<"职工姓名"<<setw(13)<<"职工电话"<<setw(20)<<"职工住址"<<setw(12)<<"职工工作"<<endl;
for(int i=0;i<=n;i++)
{
cout<<setw(10)<<sta[i].num<<setw(10)<<sta[i].name<<setw(13)<<sta[i].tel<<setw(20)<<sta[i].addr<<setw(12)<<sta[i].wage<<endl;
}
cout<<endl;
}
void staff:: search() //查询职工信息函数
{
int k,i, p;
char j[10];
cout<<"\t***********选择查询职工信息的方式*************\n";
cout<<"\t* 1姓名查询 *\n";
cout<<"\t* 2职工号查询 *\n";
cout<<"你要输入的编号是(1--2)";
cin>>k;
if(k==1)
{
cout<<"请输入要查询的该职工姓名:";
cin>>j;
for(i=1;i<=n;i++)
{
if(strcmp(sta[i].name,j ) ==0)
{
cout<<"该职工编号为: \t"<<sta[i].num<<endl;
cout<<"该职工电话为:\t"<<sta[i].tel<<endl;
cout<<"该职工住址为:\t"<<sta[i].addr<<endl;
cout<<"该职工工资为:\t"<<sta[i].wage<<endl;
}
}
}
if(k==2)
{
cout<<"请输入要查询的该职工的职工号:";
cin>>p;
for(i=1;i<=n;i++)
{
if(p==sta[i].num)
{
cout<<"该职工姓名为: \t"<<sta[i].name<<endl;
cout<<"该职工电话为:\t"<<sta[i].tel<<endl;
cout<<"该职工住址为:\t"<<sta[i].addr<<endl;
cout<<"该职工工资为:\t"<<sta[i].wage<<endl;
}
}
}
}
void staff::change() //修改职工信息函数
{
int h;
char q[10];
cout<<"\t***********选择修改职工信息的内容*************\n";
cout<<"\t* 1修改工资 *\n";
cout<<"\t* 2修改职工号 *\n";
cout<<"你要输入的编号是(1--2)";
cin>>h;
if(h==1)
{
cout<<"请输入要修改的该职工的姓名:" ;
cin>>q;
for(int i=1;i<=n;i++)
{
if(strcmp(sta[i].name,q)==0)
{
cout<<"该职工工资改为:";
cin>>sta[i].wage;
}
}
cout<<left; //设置输出左对齐
cout<<setw(10)<<"职工编号"<<setw(10)<<"职工姓名"<<setw(13)<<"职工电话"<<setw(20)<<"职工住址"<<setw(12)<<"职工工资"<<endl;
for(int i=1;i<=n;i++)
{
cout<<setw(10)<<sta[i].num<<setw(10)<<sta[i].name<<setw(13)<<sta[i].tel<<setw(20)<<sta[i].addr<<setw(12)<<sta[i].wage<<endl;
}
cout<<endl;
}
if(h==2)
{
cout<<"请输入要修改的该职工的姓名:" ;
cin>> q;
for(int i=1;i<=n;i++)
{
if(strcmp(sta[i].name, q)==0)
{
cout<<"该职工的职工号改为:";
cin>>sta[i].num;
}
}
cout<<left; //设置输出左对齐
cout<<setw(10)<<"职工编号"<<setw(10)<<"职工姓名"<<setw(13)<<"职工电话"<<setw(20)<<"职工地址"<<setw(12)<<"职工工资"<<endl;
for(int i=1;i<=n;i++)
{
cout<<setw(10)<<sta[i].num<<setw(10)<<sta[i].name<<setw(13)<<sta[i].tel<<setw(20)<<sta[i].addr<<setw(12)<<sta[i].wage<<endl;
}
cout<<endl;
}
}
void staff::add() //添加职工信息函数
{
char jj;
do
{
n++;
cout<<"\n请输入第"<< n+1 <<"个职工信息:\n";
cout<<"\t职工编号: ";
cin>>sta[n].num;
cout<<"\t职工姓名: ";
cin>>sta[n].name;
cout<<"\t职工电话:";
cin>>sta[n].tel;
cout<<"\t职工住址: ";
cin>>sta[n].addr;
cout<<"\t职工工资:";
cin>>sta[n].wage;
cout<<"是否要继续添加职工信息(Y/N):";
cin>>jj;
}while(jj=='Y' || jj=='y' );
}
void staff::del() //删除职工信息函数
{
char q[10] ;
cout<<"请输入要删除的该职工的姓名:" ;
cin>> q;
for(int i=1;i<=n;i++)
{
if(strcmp(sta[i].name, q)==0)
{
cout<<"该职工工资删除为:";
cin>>sta[i].wage;
cout<<"该职工编号删除为:";
cin>>sta[i].num;
cout<<"该职工姓名删除为: ";
cin>>sta[i].name;
cout<<"该职工地址删除为: ";
cin>>sta[i].addr;
cout<<"职工电话删除为: ";
cin>>sta[i].tel;
}
cout<<left; //设置左对齐输出
cout<<setw(10)<<"职工编号"<<setw(10)<<"职工姓名"<<setw(13)<<"职工电话"<<setw(20)<<"职工地址"<<setw(12)<<"职工工资"<<endl;
for(int i=1;i<=n;i++)
{
cout<<setw(10)<<sta[i].num<<setw(10)<<sta[i].name<<setw(13)<<sta[i].tel<<setw(20)<<sta[i].addr<<setw(12)<<sta[i].wage<<endl;
}
cout<<endl;
}
}