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

📄 人员信息管理系统.cpp

📁 上学期做的一个实验
💻 CPP
📖 第 1 页 / 共 2 页
字号:
				return t2;
			}
			if((ifile.eof())&&(m==0))
			{
				cout<<"对不起,找不到您所要修改的姓名,请重输!"<<endl;
				getch();
			}
		}
		ifile.close();
	}
	return 0;
}

long num(int &n)
{
	int i,m=0;
	long t,t2;
	char b[100],line[100];
	while(1)
	{
		ifstream ifile("data.txt",ios_base::binary);
		cout<<"请输入要修改人员的编号:";
		fflush(stdin);
		n=int(isdigit1());
		while(ifile.good())
		{
			t=ifile.tellg();
			ifile.read(b,sizeof("编号"));
			ifile>>i;
			ifile.seekg(t);
			ifile.getline(line,100);
			if(i==n)
			{
				m=1;
				t2=t;
				cout<<line<<endl;
				ifile.close();
				return t2;
			}
			if((ifile.eof())&&(m==0))
			{
				cout<<"对不起,找不到您所要修改的编号,请重输!"<<endl;
				getch();
			}
		}
		ifile.close();
	}
	return 0;
}

void rework(int n,long t2)
{
	int i;
	long t3;
	employee e1;
	manager m1;
	technician t1;
	salesman s1;
	float accumpay;
	float workhours;
	float sales;
	char a[100];
	while(1)
	{
		ofstream ofile("data.txt",ios_base::in);
		cout<<"请输入职位(1职员.2经理.3技术人员.4销售人员.5返回.6退出系统.):"<<endl;
		scanf("%d",&i);
		gets(a);
		switch(i)
		{
		case 1:
			t3=job1(e1,t2,n);
			ofile.seekp(t3);
			e1.SetJob("职员");
			cout<<"请输入月薪:";
			accumpay=isdigit1();
			e1.SetAccumpay(accumpay);
			ofile<<setiosflags(ios_base::left)<<"职位:"<<setw(10)<<e1.GetJob()
				<<"月薪:"<<setw(6)<<e1.GetAccumpay()<<setw(15)<<" "<<endl;
			ofile.close();
			datamanage();
			break;
		case 2:
			t3=job1(m1,t2,n);
			ofile.seekp(t3);
			m1.SetJob("经理");
			cout<<"请输入月薪:";
			accumpay=isdigit1();
			m1.SetAccumpay(accumpay);
			ofile<<setiosflags(ios_base::left)<<" 职位:"<<setw(10)<<m1.GetJob()
				<<"月薪:"<<setw(6)<<m1.GetAccumpay()<<setw(15)<<" "<<endl;
			ofile.close();
			datamanage();
			break;
		case 3:
			t3=job1(t1,t2,n);
			ofile.seekp(t3);
			t1.SetJob("技术人员");
			cout<<"请输入本月的工作时数:";
			workhours=isdigit1();
			t1.SetworkHours(workhours);
			t1.pay();
			ofile<<setiosflags(ios_base::left)<<"职位:"<<setw(10)<<t1.GetJob()<<"月薪:"<<setw(6)<<t1.GetAccumpay()
				 <<"工作时数:"<<setw(6)<<t1.GetworkHours()<<endl;
			ofile.close();
			datamanage();
			break;
		case 4:
			t3=job1(s1,t2,n);
			ofile.seekp(t3);
			s1.SetJob("销售人员");
			cout<<"请输入本月的销售总额:";
			sales=isdigit1();
			s1.Setsales(sales);
			s1.pay();
			ofile<<setiosflags(ios_base::left)<<"职位:"<<setw(10)<<s1.GetJob()<<"月薪:"<<setw(6)<<s1.GetAccumpay()
				 <<"销售总额:"<<setw(6)<<s1.Getsales()<<endl;
			ofile.close();
			datamanage();
			break;
		case 5:
			ofile.close();
			datamanage();
			break;
		case 6:
			exit(7);
		default:
			cout<<"错误.请重新输入."<<endl;
			getch();
			break;
		}
	}
}


//-------------------------------------------人员信息浏览-------------------------------------------------

//-------------------------------------------------全体信息浏览-------------------------------------------

void a_datasearch()
{
	system("cls");
	char ch;
	ifstream f("data.txt");
	while(f.get(ch))
		cout<<ch;
	f.close();
	cout<<endl<<endl;
	cout<<"----------------------------键入回车返回上一层-------------------------"<<endl;
	getch();
	datascan();
}

//------------------------------------------------单类信息浏览-------------------------------------------
void s_datasearch()
{
	char a[100];
	int i=0;	 
	while(1)  
	{   
		system("cls");
		cout<<"请输入浏览方式:1.性别 2.职位 3.编号 4.姓名5.返回上一层"<<endl;	
		scanf("%d",&i);
		gets(a);
		switch(i) 
		{
		case 1:
			sexsearch();
			break;
		case 2:
			jobsearch();
			break;
		case 3:
			numsearch();
			getch();
			break;
		case 4:
			namesearch();
			break;
		case 5:
			datascan();
			break;
		default:			
			cout<<"输入错误,请重新输入!"<<endl;	
			getch();
			break;
		}
	}
//	getchar();
}






//------------------------------------------统计-------------------------------------------------

//总人数统计
void peoplestat()
{
	system("cls");
	int i=0;
	char buf[1000]; 
	long t1;
	
	ifstream   f("data.txt", ios::binary);
	while(f.good())   
	{   
		t1=f.tellg();
		f.getline(buf,1000); 
        i++;
	}
	i--;
	f.close();
	cout<<"公司的总人数为:";
	cout<<i<<"人"<<endl;
	cout<<endl<<"--------------------------键入回车键返回上一层------------------------";
	getch();
	datastat();
}

void sexstat()
{
    int i=0,j=0;
	long t1,t2;
	static char sexm[]="男",sexf[]="女";
	char t[100];
	char buf[1000],buf1[1000];
    ifstream   sm("data.txt", ios::binary);	
    ifstream   sf("data.txt", ios::binary);
    system("cls");
	cout<<"公司男性人员有:";
	while(sm.good())
	{
		t1=sm.tellg();
		sm.getline(buf,1000);
		sm.seekg(t1);
		sm.read(buf1,27);
		sm>>t;
		if(strcmp(t,sexm)==0)
		{
			i++;
		}
		sm.getline(buf,1000);
		t2=sm.tellg();
		t1=t2;
	}
	sm.close();
	cout<<i<<"人"<<endl<<endl;

	cout<<"公司女性人员有:";
	while(sf.good())
	{
		t1=sf.tellg();
		sf.getline(buf,1000);
		sf.seekg(t1);
		sf.read(buf1,27);
		sf>>t;
		if(strcmp(t,sexf)==0)
		{
			j++;
		}
		sf.getline(buf,1000);
		t2=sf.tellg();
		t1=t2;
	}
	sf.close();
	cout<<j<<"人"<<endl<<endl;
	cout<<endl<<"--------------------------键入回车键返回上一层------------------------"; 
	getch();
	datastat();
}
void jobstat()
{
	int i=0,j=0,h=0,k=0;
	long t1,t2;
	static char peoplelist1[]="职员",peoplelist2[]="经理",peoplelist3[]="技术人员",peoplelist4[]="销售人员";
    ifstream   p1("data.txt", ios::binary);
	ifstream   p2("data.txt", ios::binary);
	ifstream   p3("data.txt", ios::binary);
	ifstream   p4("data.txt", ios::binary);
	char n[100],t[100];
	char buf[1000],buf1[1000];
    system("cls");
	cout<<"公司职员有:";
	while(p1.good())
	{
		t1=p1.tellg();
		p1.getline(buf,1000);
		strcpy(buf1,buf);
		p1.seekg(t1);
		p1>>n;
		p1>>n;
		p1>>n;
		p1>>n;
		p1>>n;
		p1.read(buf1,sizeof("职业:"));
		p1>>t;
		if(strcmp(t,peoplelist1)==0)
		{
			i++;
		}
		p1.getline(buf,1000);
		t2=p1.tellg();
		t1=t2;
	}
	p1.close();
	cout<<i<<"人"<<endl<<endl;

	cout<<"公司经理有:";
	while(p2.good())
	{
		t1=p2.tellg();
		p2.getline(buf,1000);
		strcpy(buf1,buf);
		p2.seekg(t1);
		p2>>n;
		p2>>n;
		p2>>n;
		p2>>n;
		p2>>n;
		p2.read(buf1,sizeof("职业:"));
		p2>>t;
		if(strcmp(t,peoplelist1)==0)
		{
			j++;
		}
		p2.getline(buf,1000);
		t2=p2.tellg();
		t1=t2;
	}
	p2.close();
	cout<<j<<"人"<<endl<<endl;

	cout<<"公司技术人员有:";
	while(p3.good())
	{
		t1=p3.tellg();
		p3.getline(buf,1000);
		strcpy(buf1,buf);
		p3.seekg(t1);
		p3>>n;
		p3>>n;
		p3>>n;
		p3>>n;
		p3>>n;
		p3.read(buf1,sizeof("职业:"));
		p3>>t;
		if(strcmp(t,peoplelist3)==0)
		{
			h++;
		}
		p3.getline(buf,1000);
		t2=p3.tellg();
		t1=t2;
	}
	p3.close();
	cout<<h<<"人"<<endl<<endl;

	
    cout<<"公司技术人员有:";
	while(p4.good())
	{
		t1=p4.tellg();
		p4.getline(buf,1000);
		strcpy(buf1,buf);
		p4.seekg(t1);
		p4>>n;
		p4>>n;
		p4>>n;
		p4>>n;
		p4>>n;
		p4.read(buf1,sizeof("职业:"));
		p4>>t;
		if(strcmp(t,peoplelist4)==0)
		{
			k++;
		}
		p4.getline(buf,1000);
		t2=p4.tellg();
		t1=t2;
	}
	p4.close();
	cout<<k<<"人"<<endl<<endl;
	cout<<endl<<"--------------------------键入回车键返回上一层------------------------"; 
	getch();
	datastat();
}

void numsearch()
{
	int m=0,n,num;
	long t1,t2;
	char buf[100],buf1[100];
	while(1)
	{
		ifstream ns("data.txt",ios_base::binary);
		cout<<"请输入要查询的编号:"<<endl;
		fflush(stdin);
		num=int(isdigit1());
		while(ns.good())
		{
			t1=ns.tellg();
			ns.getline(buf,1000);
			strcpy(buf1,buf);
			ns.seekg(t1);
			ns.read(buf1,sizeof("编号"));
			ns>>n;
			if(num==n)
			{
				m=1;
				cout<<buf<<endl;
				ns.close();			
				cout<<endl<<endl;
				cout<<"---------------------键入回车返回上一层----------------------"<<endl;
				getch();
				s_datasearch();
			}
		    ns.getline(buf,1000);
			t2=ns.tellg();
			t1=t2;
			if((ns.eof())&&(m==0))
			{
				cout<<"对不起,找不到您所要查询的编号,请重输!"<<endl;
				ns.close();
				getch();
			}
		}
	}
}

void namesearch()
{
	int m=0;
	long t1,t2;
	char buf[100],buf1[100],namestr[100],t[100];
	ifstream ns("data.txt",ios_base::binary);
	while(1)
	{
		cout<<"请输入要查询的人员姓名:"<<endl;
		scanf("%s",&namestr);
		gets(buf1);
		while(ns.good())
		{
			t1=ns.tellg();
			ns.getline(buf,1000);
			ns.seekg(t1);
			ns.read(buf1,14);
			ns>>t;
			if(!strcmp(t,namestr))
			{
				m++;
				cout<<buf<<endl;
				//ns.close();			
			}
		    ns.getline(buf,1000);
		   	t2=ns.tellg();
		    t1=t2;
			if((ns.eof())&&(m==0))
			{
				cout<<"对不起,找不到您所要查询的姓名!"<<endl;
				ns.close();
				getch();
				s_datasearch();
			}
		}
		if((ns.eof())&&(m))
		{
			cout<<"---------------------键入回车返回上一层----------------------"<<endl;
			ns.close();
			getch();
			s_datasearch();
		}
	}
}	

void sexsearch()
{
	static char sexm[]="男",sexf[]="女";
    ifstream   sm("data.txt", ios::binary);	
    ifstream   sf("data.txt", ios::binary);
	char buf[100],buf1[100],t[100];
	long t1,t2;

	cout<<"---------------------公司男性人员----------------------"<<endl;
			while(sm.good())
			{
				t1=sm.tellg();
				sm.getline(buf,1000);
				sm.seekg(t1);
				sm.read(buf1,27);
				sm>>t;
				if(strcmp(t,sexm)==0)
				{
					cout<<buf<<endl;
				}
				sm.getline(buf,1000);
				t2=sm.tellg();
				t1=t2;
			}
			sm.close();
			cout<<endl<<endl;

			cout<<"---------------------公司女性人员----------------------"<<endl;
			while(sf.good())
			{
				t1=sf.tellg();
				sf.getline(buf,1000);
				sf.seekg(t1);
				sf.read(buf1,27);
				sf>>t;
				if(strcmp(t,sexf)==0)
				{
					cout<<buf<<endl;
				}
			sf.getline(buf,1000);
			t2=sf.tellg();
			t1=t2;
			}
			sf.close();
			cout<<endl<<endl;
			cout<<"---------------------键入回车返回上一层----------------------"<<endl;
			getch();
			s_datasearch();
}

void jobsearch()
{
	static char peoplelist1[]="职员",peoplelist2[]="经理",peoplelist3[]="技术人员",peoplelist4[]="销售人员";
    ifstream   p1("data.txt", ios::binary);
	ifstream   p2("data.txt", ios::binary);
	ifstream   p3("data.txt", ios::binary);
	ifstream   p4("data.txt", ios::binary);
	char buf[100],buf1[100],t[100];
	long t1,t2;
	cout<<"-----------------------公司职员------------------------"<<endl;
			while(p1.good())
			{
				t1=p1.tellg();
				p1.getline(buf,1000);
				strcpy(buf1,buf);
				p1.seekg(t1);
			    p1>>buf1;
				p1>>buf1;
				p1>>buf1;
				p1>>buf1;
				p1>>buf1;
				p1.read(buf1,sizeof("职位:"));
				p1>>t;
				if(strcmp(t,peoplelist1)==0)
				{
					cout<<buf<<endl;
				}
			    p1.getline(buf,1000);
		    	t2=p1.tellg();
			    t1=t2;
			}
			p1.close();
			cout<<endl<<endl;

			cout<<"-----------------------公司经理------------------------"<<endl;
			while(p2.good())
			{
				t1=p2.tellg();
				p2.getline(buf,1000);
				strcpy(buf1,buf);
				p2.seekg(t1);
			    p2>>buf1;
				p2>>buf1;
				p2>>buf1;
				p2>>buf1;
				p2>>buf1;
				p2.read(buf1,sizeof("职位:"));
				p2>>t;
				if(strcmp(t,peoplelist2)==0)
				{
					cout<<buf<<endl;
				}
			    p2.getline(buf,1000);
		    	t2=p1.tellg();
			    t1=t2;
			}
			p2.close();
			cout<<endl<<endl;

			cout<<"---------------------公司技术人员----------------------"<<endl;
			while(p3.good())
			{
				t1=p3.tellg();
				p3.getline(buf,1000);
				strcpy(buf1,buf);
				p3.seekg(t1);
			    p3>>buf1;
				p3>>buf1;
				p3>>buf1;
				p3>>buf1;
				p3>>buf1;
				p3.read(buf1,sizeof("职位:"));
				p3>>t;
				if(strcmp(t,peoplelist3)==0)
				{
					cout<<buf<<endl;
				}
			    p3.getline(buf,1000);
		    	t2=p1.tellg();
			    t1=t2;
			}
			p3.close();
			cout<<endl<<endl;

			cout<<"---------------------公司销售人员----------------------"<<endl;
			while(p4.good())
			{
				t1=p4.tellg();
				p4.getline(buf,1000);
				strcpy(buf1,buf);
				p4.seekg(t1);
			    p4>>buf1;
				p4>>buf1;
				p4>>buf1;
				p4>>buf1;
				p4>>buf1;
				p4.read(buf1,sizeof("职位:"));
				p4>>t;
				if(strcmp(t,peoplelist4)==0)
				{
					cout<<buf<<endl;
				}
			    p4.getline(buf,1000);
		    	t2=p1.tellg();
			    t1=t2;
			}
			p4.close();
			cout<<endl<<endl;
			cout<<"---------------------键入回车返回上一层----------------------"<<endl;
			getch();
			s_datasearch();
}

⌨️ 快捷键说明

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