#include<iostream>
#include<string>
#include<fstream>
#include<windows.h>
using namespace std;
void password();
class Staff {
protected:
string id;//职工号
string name;//姓名
string sex;//性别
string age;//年龄
string degree;//学历
string wage;//工资
string address;//住址
string phone;//电话
public:
string get_id();
string get_name();
string get_sex();
string get_age();
string get_degree();
string get_wage();
string get_address();
string get_phone();
void set_id(string id);
void set_name(string name);
void set_sex(string sex);
void set_age(string age);
void set_degree(string degree);
void set_wage(string wage);
void set_address(string address);
void set_phone(string phone);
void set_next(Staff* next);
Staff *get_next();
Staff* next;
};
class List {
public:
List();
void registration(Staff* head);//录入
void search_name(Staff* head);//按姓名查询
void search_id(Staff* head);//按工号查询
void delete_name(Staff* head);//删除
void show_all(Staff* head);//展示
void update(Staff* head);//修改
void menu(Staff* head);//菜单
void start(Staff* head);//开始
void read(Staff* head);//读取
void write1(Staff* head);//写入
void write2(Staff* t);
protected:
Staff*head;
};
string Staff::get_id() {
return id;
}
string Staff::get_name() {
return name;
}
string Staff::get_sex() {
return sex;
}
string Staff::get_age() {
return age;
}
string Staff::get_degree() {
return degree;
}
string Staff::get_wage() {
return wage;
}
string Staff::get_address() {
return address;
}
string Staff::get_phone() {
return phone;
}
void Staff::set_id(string id) {
this->id=id;
}
void Staff::set_name(string name) {
this->name=name;
}
void Staff::set_sex(string sex) {
this->sex=sex;
}
void Staff::set_age(string age) {
this->age=age;
}
void Staff::set_degree(string degree) {
this->degree=degree;
}
void Staff::set_wage(string wage) {
this->wage=wage;
}
void Staff::set_address(string address) {
this->address=address;
}
void Staff::set_phone(string phone) {
this->phone=phone;
}
void Staff::set_next(Staff *next) {
this->next=next;
}
Staff *Staff::get_next() {
return next;
}
List::List() {
head=new Staff();
if(head==NULL) {
cout<<"链表创建失败"<<endl;
exit(0);
}
head->set_next(NULL);
}
void List::registration(Staff* head) {
while(head->next != NULL) {
head = head->next;
}
string id,name,sex,age,degree,wage,address,phone;
cout << "请输入员工信息" << endl;
cout << "职工号: " << endl;
cin >>id;
if(head->get_id()==id) {
cout<<"员工号已存在!"<<endl;
return;
} else {
Staff* p = new Staff;
head->next = p;
p->next = NULL;
p->set_id(id);
cout << "姓名: " << endl;
cin >>name;
p->set_name(name);
cout << "性别: " << endl;
cin >> sex;
p->set_sex(sex);
cout << "年龄: " << endl;
cin >> age;
p->set_age(age);
cout << "学历:" <<endl;
cin >> degree;
p->set_degree(degree);
cout << "工资: " << endl;
cin >> wage;
p->set_wage(wage);
cout << "住址: " << endl;
cin >> address;
p->set_address(address);
cout << "电话: " << endl;
cin >> phone;
p->set_phone(phone);
system("cls");
}
}
void List::show_all(Staff* head) {
Staff *p=head;
int i = 0;
cout<< " 工号" <<"\t";
cout << "姓名"<<"\t";
cout << "性别" <<"\t";
cout << "年龄" <<"\t";
cout << "学历" <<"\t";
cout << "工资" <<"\t";
cout << "住址" <<"\t";
cout << "电话" <<endl;
while(p->get_next() != NULL) {
i++;
p=p->get_next();
cout << "("<< i << ")";
cout << p->get_id() <<"\t";
cout << p->get_name() <<"\t";
cout << p->get_sex() <<"\t";
cout << p->get_age() <<"\t";
cout << p->get_degree() << "\t";
cout << p->get_wage() << "\t";
cout << p->get_address() << "\t";
cout << p->get_phone() << endl;
}
p->set_next(NULL);
}
void List::search_name(Staff* head) {
Staff *p=head;
int count=0;
string n;
cout << "请输入你想查询职工姓名:" << endl;
cin >> n;
while(p!= NULL) {
if(p->get_name() == n) {
count=1;
cout << "工号:" ;
cout << p->get_id() <<"\t";
cout << "名字:";
cout << p->get_name() <<"\t";
cout << "性别:" ;
cout << p->get_sex() <<"\t";
cout << "年龄:" ;
cout << p->get_age() <<"\t";
cout << "学历:" ;
cout << p->get_degree() <<"\t";
cout << "工资:" ;
cout << p->get_wage() <<"\t";
cout << "住址:" ;
cout << p->get_address() <<"\t";
cout << "电话:" ;
cout << p->get_phone() << endl;
}
if(count==0) {
cout << "查无此人!" << endl;
}
p=p->get_next();
}
}
void List::search_id(Staff* head) {
Staff *p=head;
int count=0;
string n;
cout << "请输入你想查询职工号:" << endl;
cin >> n;
while(p!= NULL) {
if(p->get_id() == n) {
count=1;
//system("cls");
cout << "工号:" ;
cout << p->get_id() <<"\t";
cout << "名字:";
cout << p->get_name() <<"\t";
cout << "性别:" ;
cout << p->get_sex() <<"\t";
cout << "年龄:" ;
cout << p->get_age() <<"\t";
cout << "学历:" ;
cout << p->get_degree() <<"\t";
cout << "工资:" ;
cout << p->get_wage() <<"\t";
cout << "住址:" ;
cout << p->get_address() <<"\t";
cout << "电话:" ;
cout << p->get_phone() << endl;
}
if(count==0) {
cout << "查无此人!" << endl;
}
p=p->get_next();
}
}
void List::delete_name(Staff* head) {
Staff* p = head;
string n;
cout << "请输入你想删除职工的姓名:" << endl;
cin >> n;
int count = 0;
while(p != NULL) {
if(p->next->get_name() == n) {
Staff *q = p->next;
write2(q);
p ->next= p->next->next;
delete q;
q=NULL;
system("cls");
cout << "删除成功!" << endl;
count++;
break;
}
p=p->next;
}
if(count == 0) {
cout << "查无此人!" << endl;
}
}
void List::update(Staff* head) {
cout<<"输入要修改对象的工号:"<<endl;
int count = 0;
string ch;
cin >> ch;
while(head->next != NULL) {
if( head->next->get_id()==ch) {
count = 1;
cout << "输入新工号:"<< endl;
string c;
cin >> c;
head->next->set_id(c);
cout<< "输入新姓名:"<< endl;
cin >> c;
head->next->set_name(c) ;
cout<< "输入新性别:"<< endl;
cin >> c;
head->next->set_sex(c) ;
cout<< "输入新年龄:"<< endl;
cin >> c;
head->next->set_age(c) ;
cout<< "输入新学历:"<< endl;
cin >> c;
head->next->set_degree(c) ;
cout<< "输入新工资:"<< endl;
cin >> c;
head->next->set_wage(c) ;
cout<< "输入新住址:"<< endl;
cin >> c;
head->next->set_address(c);
cout<< "输入新电话:"<< endl;
cin >> c;
head->next->set_phone(c) ;
system("cls");
cout << "修改成功" << endl;
break;
}
}
head = head->next;
if(count == 0) {
cout << "查无此人" << endl;
}
}
void List::read(Staff* head) {
Staff* q,*p;
q=head;
string id,name,sex,age,degree,wage,address,phone;
fstream in("公司职工信息管理系统.txt",ios::in);
if(!in.is_open()) {
fstream out("公司职工信息管理系统.txt",ios::out);
}
while(in.peek()!=EOF) {
p =new Staff();
in>> id;
if(in.eof()) {
delete p;
break;
}
p->set_id(id);
in >> name;
p->set_name(name);
in >>sex;
p->set_sex(sex);
in >> age;
p->set_age(age);
in >> degree;
p->set_degree(degree);
in >> wage;
p->set_wage(wage);
in>> address;
p->set_address(address);
in >> phone;
p->set_phone(phone);
q->set_next(p);
q =p;
}
q->set_next(NULL);
in.close();
}
void List::write1(Staff* head) {
Staff* t=head;
ofstream outfile;
outfile.open("公司职工信息管理系统.txt",ios::out);
while(t->next != NULL) {
outfile << t->next->get_id()<<'\t' ;
outfile << t->next->get_name()<<'\t';
outfile << t->next->get_sex()<<'\t';
outfile << t->next->get_age() <<