📄 main.cpp
字号:
#include"string"
#include<string>
#include"staff.h"
#include"cstdio"
#include"conio.h"
#include"fstream"
#include"iostream"
#include"stdlib.h"
#define N 100
using namespace std;
Staff<Personnel> *P[N];
Staff<Maintain> *M[N];
Staff<Sell> *S[N];
const int SIZE_CHAR = 5;
const char CCH[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
int b1=0,b2=0,b3=0;//导入数据条数
string m()//随机生字母
{
char ch[SIZE_CHAR + 1] = {0};
for (int i = 0; i < SIZE_CHAR; ++i)
{
int x = rand() % (sizeof(CCH) - 1);
ch[i] = CCH[x];
}
return ch;
}
ostream& out(ostream& stream)//操纵符
{
return stream <<setiosflags(ios::left)
<<setw(8)<<"工作号"<<setw(8)<<"姓名"
<<setw(6)<<"性别"<<setw(8)<<"身分证"<<setw(12)<<"生日"<<setw(8)<<"地址"
<<setw(10)<<"电话"
<<" 部门 ";
}
void insert()//录入数据
{
int n;
while(1)
{
cout<<"请输入部门的代码: 1-人事部 2-维修部 3-销售部"<<endl;
cin>>n;
if(n==1||n==2||n==3)
{
if(n==1)
{
do
{
Staff<Personnel> *p;
p=new Staff<Personnel>;
p->bumen.show();
p->input();
p->bumen.input();
int q;
do
{
for(int i=0;i<N;i++)
{
q=0;
if(P[i]==NULL)
{break;}
else if(P[i]->No==p->No)
{cout<<"此工作号已存在!请修改~!"<<endl;
p->input();
p->bumen.input();
q++;
break;
}
}
}while(q!=0);
for(int j=0;j<N;j++)
{
if(P[j]==NULL)
{
P[j]=p;
cout<<"输入成功!"<<endl;
break;
}
}
cout<<"你还要继续执行其操作吗?是'1', 否'0':";cin>>n;
}while(n==1);
}
else if(n==2)
{
do
{
Staff<Maintain> *a;
a=new Staff<Maintain>;
a->bumen.show();
a->input();
a->bumen.input();
int q;
do{
for(int i=0;i<N;i++)
{ q=0;
if(M[i]==NULL)
{break;}
else if(M[i]->No==a->No)
{cout<<"此工作号已存在!请修改~!"<<endl;
a->input();
a->bumen.input();
q++;
break;
}
}
}while(q!=0);
for(int j=0;j<N;j++)
{
if(M[j]==NULL)
{
M[j]=a;
cout<<"输入成功!"<<endl;
break;
}
}
cout<<"你还要继续执行其操作吗?是'2', 否'0':";cin>>n;
}while(n==2);
}
else if(n==3)
{
do
{
Staff<Sell> *s;
s=new Staff<Sell>;
s->bumen.show();
s->input();
s->bumen.input();
int q;
do{
for(int i=0;i<N;i++)
{ q=0;
if(S[i]==NULL)
{break;}
else if(S[i]->No==s->No)
{cout<<"此工作号已存在!请修改~!"<<endl;
s->input();
s->bumen.input();
q++;
break;
}
}
}while(q!=0);
for(int j=0;j<N;j++)
{
if(S[j]==NULL)
{
S[j]=s;
cout<<"输入成功!"<<endl;
break;
}
}
cout<<"你还要继续执行其操作吗?是'3', 否'0':";cin>>n;
}while(n==3);
}
}
break;
}
}
void show()//显示数据
{
int n;
while(1)
{
cout<<"请输入部门的代码: 1-人事部 2-维修部 3-销售部 "<<endl;
cin>>n;
if(n==1||n==2||n==3)
{
if(n==1)
{
Staff<Personnel> *p;
cout<<out<<endl;
for(int j=0;j<N;j++)
{
if(P[j]!=NULL){
p=P[j];
p->output();
p->bumen.output();
}
}
break;
}
else if(n==2)
{
Staff<Maintain> *a;
cout<<out<<endl;
for(int i=0;i<N;i++)
{
if(M[i]!=NULL)
{
a=M[i];
a->output();
a->bumen.output();
}
}
break;
}
else if(n==3)
{
Staff<Sell> *s;
cout<<out<<endl;
for(int i=0;i<N;i++)
{
if(S[i]!=NULL)
{
s=S[i];
s->output();
s->bumen.output();
}
}
break;
}
}
else if(n=0) break;
}
}
void find()//查找数据
{
string n;
cout<<"输入你要查找姓名"<<endl;
cin>>n;
for(int j=0;j<N;j++)
{
if(P[j]!=NULL&&(P[j]->Name)==n)
{
P[j]->bumen.show();
cout<<out<<endl;
P[j]->output();P[j]->bumen.output();
break;
}
}
for(j=0;j<N;j++)
{
if(M[j]!=NULL&&(M[j]->Name)==n)
{
M[j]->bumen.show();
cout<<out<<endl;
M[j]->output();M[j]->bumen.output();
break;
}
}
for(j=0;j<N;j++)
{
if(S[j]!=NULL&&(S[j]->Name)==n)
{
S[j]->bumen.show();
cout<<out<<endl;
S[j]->output();S[j]->bumen.output();
break;
}
}
}
void Delete()//删除数据
{
string n;int m;
cout<<"输入你要查找姓名"<<endl;
cin>>n;
cout<<"请输入该员工所在的部门的代码: 1-人事部 2-维修部 3-销售部"<<endl;
cin>>m;
if(m==1)
{
for(int j=0;j<N;j++)
{
if(P[j]!=NULL&&(P[j]->Name)==n)
{
cout<<out<<endl;
P[j]->output();P[j]->bumen.output();
P[j]=NULL;
cout<<"该员工已被删除!"<<endl;
break;
}
}
}
if(m==2)
{
for(int j=0;j<N;j++)
{
if(M[j]!=NULL&&(M[j]->Name)==n)
{
cout<<out<<endl;
M[j]->output();M[j]->bumen.output();
M[j]=NULL;
cout<<"该员工已被删除!"<<endl;
break;
}
}
}
if(m==3)
{
for(int j=0;j<N;j++)
{
if(S[j]!=NULL&&(S[j]->Name)==n)
{
cout<<out<<endl;
S[j]->output();S[j]->bumen.output();
S[j]=NULL;
cout<<"该员工已被删除!"<<endl;
break;
}
}
}
}
void revise()//修改数据
{
string n;int m;
cout<<"输入你要查找姓名"<<endl;
cin>>n;
cout<<"请输入该员工所在的部门的代码: 1-人事部 2-维修部 3-销售部"<<endl;
cin>>m;
if(m==1)
{
for(int j=0;j<N;j++)
{
if(P[j]!=NULL&&(P[j]->Name)==n)
{
cout<<out<<endl;
P[j]->output();P[j]->bumen.output();
P[j]->input();P[j]->bumen.input();
cout<<"该员工修改成功!";
break;
}
}
}
if(m==2)
{
for(int j=0;j<N;j++)
{
if(M[j]!=NULL&&(M[j]->Name)==n)
{
cout<<out<<endl;
M[j]->output();M[j]->bumen.output();
M[j]->input();M[j]->bumen.input();
cout<<"该员工修改成功!";
break;
}
}
}
if(m==3)
{
for(int j=0;j<N;j++)
{
if(S[j]!=NULL&&(S[j]->Name)==n)
{
cout<<out<<endl;
S[j]->output();S[j]->bumen.output();
S[j]->input();S[j]->bumen.input();
cout<<"该员工修改成功!";
break;
}
}
}
}
void clear()//清空数据
{ int n,a=1;
do
{
cout<<"请输入密码"<<" '0'返回界面"<<endl;
cin>>n;
if(n==a)
{
for(int i=0;i<N;i++)
{
P[i]=NULL;
M[i]=NULL;
S[i]=NULL;
}
cout<<"所有员工的资料已被删除!"<<endl;break;
}
else cout<<"输入密码失败!"<<endl;
}while(n!=0);
}
void save()//保存数据
{
ofstream output_file;
ofstream output_file1;
ofstream output_file2;
ofstream output_file3;
cout<<"正在保存中........"<<endl;
output_file.open("Personnel.txt");
if(!output_file)
{cout<<"保存Personnel文件失败!"<<endl;}
for(int i=0;i<N;i++){
if(P[i]!=NULL)
{
output_file<<P[i]->No<<" "<<P[i]->Sex<<" "<<P[i]->Name<<" "<<P[i]->ID<<" "<<P[i]->Birthday<<" "<<P[i]->Address<<" "<<P[i]->Phone<<" "<<P[i]->bumen.Job<<" "<<P[i]->bumen.Pay<<endl;
b1++;
}
}
output_file2.open("Maintain.txt");
if(!output_file2)
{cout<<"保存Maintain文件失败!"<<endl;}
for( i=0;i<N;i++){
if(M[i]!=NULL)
{
output_file2<<M[i]->No<<" "<<M[i]->Sex<<" "<<M[i]->Name<<" "<<M[i]->ID<<" "<<M[i]->Birthday<<" "<<M[i]->Address<<" "<<M[i]->Phone<<" "<<M[i]->bumen.Job<<" "<<M[i]->bumen.Pay<<endl;
b2++;
}
}
output_file3.open("Sell.txt");
if(!output_file3)
{cout<<"保存Sell文件失败!"<<endl;}
for( i=0;i<N;i++){
if(S[i]!=NULL)
{
output_file3<<S[i]->No<<" "<<S[i]->Sex<<" "<<S[i]->Name<<" "<<S[i]->ID<<" "<<S[i]->Birthday<<" "<<S[i]->Address<<" "<<S[i]->Phone<<" "<<S[i]->bumen.Job<<" "<<S[i]->bumen.Pay<<endl;
b3++;
}
}
output_file1.open("kongzhi.txt");
output_file1<<b1<<" "<<b2<<" "<<b3<<endl;//保存数据条数
output_file1.close();
output_file.close();
output_file2.close();
output_file3.close();
cout<<"保存完毕!"<<endl;
}
void main()
{ ifstream input_file;
ifstream input_file1;
ifstream input_file2;
ifstream input_file3;
input_file1.open("kongzhi.txt");
input_file1>>b1>>b2>>b3;
input_file.open("Personnel.txt");
input_file2.open("Maintain.txt");
input_file3.open("Sell.txt");
if(!input_file||!input_file2||!input_file3)
{ cout<<"打开文件失败!"<<endl;
cout<<"建立新的数据!"<<endl;
for(int i=0;i<N;i++)
{
P[i]=NULL;
M[i]=NULL;
S[i]=NULL;
}
for(i=0;i<32;i++)
{
//随机生成数据
P[i]=new Staff<Personnel>;
P[i]->No=100+i;P[i]->Sex='m';P[i]->Name=m();P[i]->ID=1000+rand()%100;
P[i]->Birthday=1988000+rand()%100;P[i]->Address=m();P[i]->Phone=13567+rand()%100;
P[i]->bumen.Job=m();P[i]->bumen.Pay=2000+rand()%101;
M[i]=new Staff<Maintain>;
M[i]->No=100+i;M[i]->Sex='m';M[i]->Name=m();M[i]->ID=1000+rand()%100;
M[i]->Birthday=1988000+rand()%100;M[i]->Address=m();M[i]->Phone=13567+rand()%100;
M[i]->bumen.Job=m();M[i]->bumen.Pay=2000+rand()%101;
S[i]=new Staff<Sell>;
S[i]->No=100+i;S[i]->Sex='m';S[i]->Name=m();S[i]->ID=1000+rand()%100;
S[i]->Birthday=1988000+rand()%100;S[i]->Address=m();S[i]->Phone=13567+rand()%100;
S[i]->bumen.Job=m();S[i]->bumen.Pay=2000+rand()%101;
}
}
else
{
for(int i=0;i<b1;i++)
{
P[i]=new Staff<Personnel>;
input_file>>P[i]->No>>P[i]->Sex>>P[i]->Name>>P[i]->ID>>P[i]->Birthday>>P[i]->Address>>P[i]->Phone>>P[i]->bumen.Job>>P[i]->bumen.Pay;
}
for(i=0;i<b2;i++)
{
M[i]=new Staff<Maintain>;
input_file2>>M[i]->No>>M[i]->Sex>>M[i]->Name>>M[i]->ID>>M[i]->Birthday>>M[i]->Address>>M[i]->Phone>>M[i]->bumen.Job>>M[i]->bumen.Pay;
}
for(i=0;i<b3;i++)
{
S[i]=new Staff<Sell>;
input_file3>>S[i]->No>>S[i]->Sex>>S[i]->Name>>S[i]->ID>>S[i]->Birthday>>S[i]->Address>>S[i]->Phone>>S[i]->bumen.Job>>S[i]->bumen.Pay;
}
cout<<"录入成功!"<<endl;
}
input_file.close();
input_file1.close();
input_file2.close();
input_file3.close();
char n;
while(1){
while(1){
system("color 006");
b1=0,b2=0,b3=0;//清空原先的数据条数
cout<<" ☆☆☆☆人事管理管理系统☆☆☆☆" <<endl;
cout<<"* * * * * * * * * * * * * * * * * * * * * * * * * * * *"<<endl
<<"* * * * * * * * * * * * * * * * * * * * * * * * * * * *"<<endl
<<"* * 1: 录入员工信息 * *"<<endl
<<"* * 2: 显示员工信息 * *"<<endl
<<"* * 3: 查找员工信息 * *"<<endl
<<"* * 4: 删除员工信息 * *"<<endl
<<"* * 5: 修改员工信息 * *"<<endl
<<"* * 6: 清空员工信息 * *"<<endl
<<"* * 7: 保存员工信息 * *"<<endl
<<"* * 8: 退出系统 * *"<<endl
<<"* * * * * * * * * * * * * * * * * * * * * * * * * * * *"<<endl
<<"* * * * * * * * * * * * * * * * * * * * * * * * * * * *"<<endl
<<" 请选择:";
cin>>n;
if(n!='1'||n!='2'||n!='3'||n!='4'||n!='5'||n!='6'||n!='7'||n!='8') break;
}
switch(n)
{
case '1':insert();break;
case '2':show();break;
case '3':find(); break;
case '4':Delete(); break;
case '5':revise();break;
case '6':clear();break;
case '7':save();break;
case '8':exit(0);
default:break;
}
getch();
system("cls");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -