📄 renshi.cpp
字号:
//renshi.cpp
#include<iostream.h>
#include<fstream.h>
#include<stdlib.h>
#include<string.h>
class yuangong
{
public:
int ID,find;
int Sa;
char name[30];
void getinfo();
void showinfo();
int salary;
};
void yuangong::getinfo()
{
char n[30];
int s,i;
ofstream outstuf;
outstuf.open("D:\\吴勇\\companyfile\\人事文件.txt",ios::app);
cout<<"请输入个人信息"<<endl;
cout<<"请输入8位的ID号:"<<endl;
cin>>s;
cout<<"请输入姓名:"<<endl;
cin>>n;
cout<<"请输入薪酬:"<<endl;
cin>>i;
ID=s,salary=i;
strcpy(name,n);
outstuf<<"ID号为"<<ID<<'\t'<<"姓名为"<<name<<'\t'<<"薪酬为"<<salary<<"元"<<endl;
outstuf.close();
};
void yuangong::showinfo()
{
fstream f;
f.seekg(0,ios::beg);
long posEnd=f.tellp();
cout<<"请输入ID号码:"<<endl;
cin>>find;
do
{
f.read((char*)& find,8);
}while(ID!=find&&f.tellp()!=posEnd);
if(ID==find)
cout<<ID<<'\t'<<name<<'\t'<<Sa<<endl;
else
{
cout<<"输入错误!"<<endl;
}
}
yuangong YUANGONG;
class zhuren:public yuangong
{
public:
protected: int salary;
};
zhuren ZHUREN;
class jingli:public yuangong
{
public:
protected: int salary;
};
jingli JINGLI;
void op(int w)
{
ofstream outstuf;
if(!outstuf)
{
cerr<<"不能打开文件."<<endl;
abort();
};
outstuf.open("D:\\吴勇\\companyfile\\人事文件.txt",ios::app);
if(w==1)
{
outstuf<<"员工: "<<endl;
YUANGONG.getinfo();
}
else if(w==2)
{
outstuf<<"主任: "<<endl;
ZHUREN.getinfo();
}
else{
outstuf<<"经理: "<<endl;
JINGLI.getinfo();
}
outstuf.close();
}
void employee()
{
int ch1,ch2;
//int number,find;
ofstream outstuf;
outstuf.open("D:\\吴勇\\companyfile\\人事文件.txt",ios::out);
while(1)
{
cout<<endl<<"请输入要进行的操作:"<<endl;
cout<<"1.输入员工信息"<<endl;
cout<<"2.浏览员工信息"<<endl;
//cout<<"3.察看个人信息"<<endl;
cout<<"0.回到主界面"<<endl;
cin>>ch1;
switch(ch1)
{
case 1:
{
while(ch2!=0)
{
cout<<endl<<endl;
cout<<"请输入员工的姓名,编号和薪酬"<<endl;
cout<<"请选择类型: \n";
cout<<"1.职员 \t";
cout<<"2.主任 \t";
cout<<"3.经理 \t";
cout<<"0.退出 \n";
cin>>ch2;
switch(ch2)
{
case 1:op(1);break;
case 2:op(2);break;
case 3:op(3);break;
case 0:continue;
default:cout<<"输入错误,请重新输入"<<'\n'<<endl;
}
}
break;
}
case 2:
{
ifstream inf("D:\\吴勇\\companyfile\\人事文件.txt",ios::in);
char s[80];
for(int i=1;i<=0;i++)
inf.getline(s,80);
while(!inf.eof())
{
inf.getline(s,80);
cout<<s<<endl;
}
inf.close();
break;
}
case 0:return;
default:cout<<endl<<"输入错误,请重新输入"<<endl;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -