#include <string>
#include<fstream>
#include<iostream>
#include<algorithm>
#include<vector>
//#include<stdlib>
using namespace std;
/*------------------------------------部门类定义---------------------------------------*/
class Department
{
private:
string Dname;
string Daddress;
string Dgovernor;
string Dphone;
public:
Department(string Dname=" ",string Daddress=" ",string Dgovernor=" ",string Dphone=0);
~Department(){}
void Insert();
void Change();
string GetDname();
string GetDaddress();
string GetDgovernor();
string GetDphone();
void Writefile(fstream &file);
void Readfile(fstream &file);
void Output();
};
Department::Department(string Dname,string Daddress,string Dgovernor,string Dphone)
{
this->Dname=Dname;
this->Daddress=Daddress;
this->Dgovernor=Dgovernor;
this->Dphone=Dphone;
}
void Department::Insert()
{
cout<<"请输入部门信息(部门名称--------部门地址--------部门负责人------部门负责人联系电话):"<<endl;
cin>>Dname>>Daddress>>Dgovernor>>Dphone;
}
void Department::Change()
{
bool exitFlag=false;
int choice;
while(!exitFlag)
{
cout<<"请选择要修改的属性(1~4) "<<endl;
cout<<"1:部门名称 2:部门地址 "<<endl;
cout<<"3:部门负责人 4:部门负责人联系电话 "<<endl;
cin>>choice;
switch(choice)
{
case 0:
exitFlag=true; break;
case 1:
cout<<"请输入部门名称:";
cin>>Dname;
break;
case 2:
cout<<"请输入部门地址:";
cin>>Daddress;
break;
case 3:
cout<<"请输入部门负责人:";
cin>>Dgovernor;
break;
case 4:
cout<<"请输入部门负责人联系电话:";
cin>>Dphone;
break;
}
}
}
string Department::GetDname()
{
return Dname;
}
string Department::GetDaddress()
{
return Daddress;
}
string Department::GetDgovernor()
{
return Dgovernor;
}
void Department::Writefile(fstream &file)
{
file<<Dname<<" "<<Daddress<<" "<<Dgovernor<<" "<<Dphone<<endl;
}
void Department::Readfile(fstream &file)
{
file>>Dname>>Daddress>>Dgovernor>>Dphone;
}
void Department::Output()
{
cout<<"部门名称--------部门地址--------部门负责人------部门负责人联系电话):";
cout<<Dname<<" "<<Daddress<<" "<<Dgovernor<<" "<<Dphone<<endl;
}
/*_____________________________________________________________________________________*/
class System
{
private:
vector<Department> v1;
vector<Department>::iterator iter1;
Department a;
fstream file1;
fstream file2;
void Save1();
public:
System();
void Insert();
void Change();
void Search();
void Output();
void Interface();
};
void System::Save1()//从文件中读出放到容器里
{
file1.open("Department1.txt",ios::in);
if(!file1)
{
cout<<"file open error!"<<endl;
abort();
}
while(!file1.eof())
{
a.Readfile(file1);
v1.push_back(a);
}
file1.close();
}
System::System()
{
cout<<"de";
Save1();
}
void System::Insert()
{
bool exitFlag=false;
char choice;
file2.open("Department2.txt",ios::out|ios::app);
if(!file2)
{
cout<<"file open error!"<<endl;
abort();
}
a.Insert();
v1.push_back(a);
iter1=v1.begin();
while(iter1!=v1.end())
{
(*iter1).Writefile(file2);
iter1++;
}
while(!exitFlag)
{
cout<<"请选择是否继续输入(y/n) : ";
cin>>choice;
switch(choice)
{
case 'y':
//Employee b;
a.Insert();
v1.push_back(a);
iter1=v1.begin();
while(iter1!=v1.end())
{
(*iter1).Writefile(file2);
iter1++;
}
break;
case 'n':
file2.close();
exitFlag=true;
break;
}
}
}
void System::Change()
{
string name;
bool exitFlag=false;
file2.open("Department2.txt",ios::out|ios::app);
if(!file2)
{
cout<<"file open error!"<<endl;
abort();
}
cout<<"请输入部门名称 :";
cin>>name;
for(iter1=v1.begin();iter1!=v1.end();iter1++)
{
if(iter1->GetDname()==name)
{
iter1->Change();
iter1=v1.begin();
while(iter1!=v1.end())
{
(*iter1).Writefile(file2);
iter1++;
}
file2.close();
}
else
cout<<"not found!"<<endl;
}
}
void System::Search()
{
string name;
cout<<"请输入要查找的部门名称:";
cin>>name;
for(iter1=v1.begin();iter1!=v1.end();iter1++)
{
if(iter1->GetDname()==name)
iter1->Output();
else
cout<<"not found!"<<endl;
}
}
void System::Output()
{
for(iter1=v1.begin();iter1!=v1.end();iter1++)
iter1->Output();
}
void System::Interface()
{
int temp;
cout<<"\t\t ********************欢迎使用********************"<<endl;
cout<<"\t\t ****************企业员工信息管理系统****************"<<endl;
cout<<"\t\t 1.信息录入 "<<endl;
cout<<"\t\t 2.信息修改 "<<endl;
cout<<"\t\t 3.信息查询 "<<endl;
cout<<"\t\t 4.信息输出 "<<endl;
cout<<"\t\t 5.退出! "<<endl;
cout<<"\t\t 请您选择(1~5):";
cin>>temp;
switch(temp)
{
case 1:
Insert();
break;
case 2:
Change();
break;
case 3:
Search();
break;
case 4:
Output();
break;
case 5:
exit(0);
}
}
void main()
{
System s;
s.Interface();
}
#include<fstream>
#include<iostream>
#include<algorithm>
#include<vector>
//#include<stdlib>
using namespace std;
/*------------------------------------部门类定义---------------------------------------*/
class Department
{
private:
string Dname;
string Daddress;
string Dgovernor;
string Dphone;
public:
Department(string Dname=" ",string Daddress=" ",string Dgovernor=" ",string Dphone=0);
~Department(){}
void Insert();
void Change();
string GetDname();
string GetDaddress();
string GetDgovernor();
string GetDphone();
void Writefile(fstream &file);
void Readfile(fstream &file);
void Output();
};
Department::Department(string Dname,string Daddress,string Dgovernor,string Dphone)
{
this->Dname=Dname;
this->Daddress=Daddress;
this->Dgovernor=Dgovernor;
this->Dphone=Dphone;
}
void Department::Insert()
{
cout<<"请输入部门信息(部门名称--------部门地址--------部门负责人------部门负责人联系电话):"<<endl;
cin>>Dname>>Daddress>>Dgovernor>>Dphone;
}
void Department::Change()
{
bool exitFlag=false;
int choice;
while(!exitFlag)
{
cout<<"请选择要修改的属性(1~4) "<<endl;
cout<<"1:部门名称 2:部门地址 "<<endl;
cout<<"3:部门负责人 4:部门负责人联系电话 "<<endl;
cin>>choice;
switch(choice)
{
case 0:
exitFlag=true; break;
case 1:
cout<<"请输入部门名称:";
cin>>Dname;
break;
case 2:
cout<<"请输入部门地址:";
cin>>Daddress;
break;
case 3:
cout<<"请输入部门负责人:";
cin>>Dgovernor;
break;
case 4:
cout<<"请输入部门负责人联系电话:";
cin>>Dphone;
break;
}
}
}
string Department::GetDname()
{
return Dname;
}
string Department::GetDaddress()
{
return Daddress;
}
string Department::GetDgovernor()
{
return Dgovernor;
}
void Department::Writefile(fstream &file)
{
file<<Dname<<" "<<Daddress<<" "<<Dgovernor<<" "<<Dphone<<endl;
}
void Department::Readfile(fstream &file)
{
file>>Dname>>Daddress>>Dgovernor>>Dphone;
}
void Department::Output()
{
cout<<"部门名称--------部门地址--------部门负责人------部门负责人联系电话):";
cout<<Dname<<" "<<Daddress<<" "<<Dgovernor<<" "<<Dphone<<endl;
}
/*_____________________________________________________________________________________*/
class System
{
private:
vector<Department> v1;
vector<Department>::iterator iter1;
Department a;
fstream file1;
fstream file2;
void Save1();
public:
System();
void Insert();
void Change();
void Search();
void Output();
void Interface();
};
void System::Save1()//从文件中读出放到容器里
{
file1.open("Department1.txt",ios::in);
if(!file1)
{
cout<<"file open error!"<<endl;
abort();
}
while(!file1.eof())
{
a.Readfile(file1);
v1.push_back(a);
}
file1.close();
}
System::System()
{
cout<<"de";
Save1();
}
void System::Insert()
{
bool exitFlag=false;
char choice;
file2.open("Department2.txt",ios::out|ios::app);
if(!file2)
{
cout<<"file open error!"<<endl;
abort();
}
a.Insert();
v1.push_back(a);
iter1=v1.begin();
while(iter1!=v1.end())
{
(*iter1).Writefile(file2);
iter1++;
}
while(!exitFlag)
{
cout<<"请选择是否继续输入(y/n) : ";
cin>>choice;
switch(choice)
{
case 'y':
//Employee b;
a.Insert();
v1.push_back(a);
iter1=v1.begin();
while(iter1!=v1.end())
{
(*iter1).Writefile(file2);
iter1++;
}
break;
case 'n':
file2.close();
exitFlag=true;
break;
}
}
}
void System::Change()
{
string name;
bool exitFlag=false;
file2.open("Department2.txt",ios::out|ios::app);
if(!file2)
{
cout<<"file open error!"<<endl;
abort();
}
cout<<"请输入部门名称 :";
cin>>name;
for(iter1=v1.begin();iter1!=v1.end();iter1++)
{
if(iter1->GetDname()==name)
{
iter1->Change();
iter1=v1.begin();
while(iter1!=v1.end())
{
(*iter1).Writefile(file2);
iter1++;
}
file2.close();
}
else
cout<<"not found!"<<endl;
}
}
void System::Search()
{
string name;
cout<<"请输入要查找的部门名称:";
cin>>name;
for(iter1=v1.begin();iter1!=v1.end();iter1++)
{
if(iter1->GetDname()==name)
iter1->Output();
else
cout<<"not found!"<<endl;
}
}
void System::Output()
{
for(iter1=v1.begin();iter1!=v1.end();iter1++)
iter1->Output();
}
void System::Interface()
{
int temp;
cout<<"\t\t ********************欢迎使用********************"<<endl;
cout<<"\t\t ****************企业员工信息管理系统****************"<<endl;
cout<<"\t\t 1.信息录入 "<<endl;
cout<<"\t\t 2.信息修改 "<<endl;
cout<<"\t\t 3.信息查询 "<<endl;
cout<<"\t\t 4.信息输出 "<<endl;
cout<<"\t\t 5.退出! "<<endl;
cout<<"\t\t 请您选择(1~5):";
cin>>temp;
switch(temp)
{
case 1:
Insert();
break;
case 2:
Change();
break;
case 3:
Search();
break;
case 4:
Output();
break;
case 5:
exit(0);
}
}
void main()
{
System s;
s.Interface();
}