⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 people.cpp

📁 高校工资管理系统 Visual C++实现简单的高校工资管理系统
💻 CPP
字号:
#include<fstream.h>
#include"stdlib.h"
#include"people.h"
#include"string.h"
#include"iostream.h"
people::people(){}
people::~people(){}
 struct people_str
{
	int ID;
	char name[8];
	char kind[20];
	double salary;
}pestruct[30];
 struct people_st
{
	char ID[8];
	char name[8];
    char salary[8];
	char kind[8];
}pstruct;
int people::i=0;
void people::addpeople()
{
    cout<<"编号:";  cin>>pestruct[i].ID;
    cout<<"姓名:";  cin>>pestruct[i].name;
	cout<<"基本工资:";  cin>>pestruct[i].salary;
	cout<<"职位:普通教师"; 
	ofstream outfile("worker.txt",ios::in|ios::out);
	if(! outfile)
	{
	  cerr<<endl<<"员工信息文件打开错误!"<<endl;
	  abort();
	}
	outfile.seekp(0,ios::end);
	outfile<<pestruct[i].ID<<" "<<pestruct[i].name<<" "
	<<pestruct[i].salary<<" "<<"普通教师"<<pestruct[i].kind<<endl;
	outfile.close();
	
}
void people::delpeople()
{   
 int i; 
 long inpos;
 cout<<endl<<"请输入待删除员工姓名:";
 cin>>name;
 fstream iofile;
 iofile.open("worker.txt",ios::in|ios::out);
 if(!iofile)
 {
   cerr<<endl<<"员工信息文件读取错误!"<<endl;
   return;
 }
 while(!iofile.eof())
 {
	 inpos=iofile.tellg();
	 iofile>>pstruct.ID>>pstruct.name>>pstruct.salary>>pstruct.kind; 
	 i=strcmp(pstruct.name,name);
  if(i==0)
	 {
	  strcpy(pstruct.ID,"   ");
	   strcpy(pstruct.name,"   ");
         strcpy(pstruct.kind,"   ");
	   strcpy(pstruct.salary,"   ");
   iofile.seekg(inpos);
	   iofile.write((char*)&pstruct,sizeof(pstruct));
  cout<<endl<<"删除成功!";
	   break;

	 }
 }
iofile.close();
if(i!=0)
cout<<"未发现待删除员工记录!";
}

void people::query()
{ 
	

        cout<<endl<<"请输入要查询的员工姓名:";
        cin>>name;
        fstream iofile;
         iofile.open("worker.txt",ios::in|ios::out);
        if(!iofile)
		{
            cerr<<endl<<"员工信息文件读取错误!"<<endl;
             return;
		}
 while(!iofile.eof())
 {
	
	 iofile>>pstruct.ID>>pstruct.name>>pstruct.salary>>pstruct.kind; 
	 i=strcmp(pstruct.name,name);
  if(i==0)
	 {
	 cout<<pstruct.ID<<endl;
	 cout<<pstruct.name<<endl;
	 cout<<pstruct.salary<<endl;
	 cout<<pstruct.kind<<endl;	   
  
	   break;

	 }
 }
   iofile.close();
    if(i!=0)
   cout<<"未发现要查询的员工记录!";
    
}
	void people::ask()
	{

		cout<<endl<<"请输入要查询的员工编号:";
 cin>>name;
 fstream iofile;
 iofile.open("worker.txt",ios::in|ios::out);
 if(!iofile)
 {
   cerr<<endl<<"员工信息文件读取错误!"<<endl;
   return;
 }
 while(!iofile.eof())
 {
	
	 iofile>>pstruct.ID>>pstruct.name>>pstruct.salary>>pstruct.kind; 
	 i=strcmp(pstruct.ID,name);
  if(i==0)
	 {
	 cout<<pstruct.ID<<endl;
	 cout<<pstruct.name<<endl;
	 cout<<pstruct.salary<<endl;
	 cout<<pstruct.kind<<endl;	   
     break;
	  

	 }
 }
iofile.close();
if(i!=0)
cout<<"未发现要查询的员工记录!";

}



 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -