?? managment system.cpp.cpp
字號:
#include<iostream>
#include<stdio.h>
#include<cstring>
using namespace std;
enum Sex{Male,Female};
struct Date
{
int year;
int month;
int day;
};
enum Qualification{Master,Graduated,PhD,Postdoc};
enum Post{Boss,Manager,Clerk};
int namedif(char *a,char *b){//判斷名字從第幾位開始不同
int len1=strlen(a);
int len2=strlen(b);
int max=len1>len2?len1:len2;
for(int i=0;i<max;i++)
if(a[i]!=b[i])
break;
return i;
}
int birthdif(Date d1,Date d2){//判斷出生日期大小
if(d1.year>d2.year)
return 1;
else if(d1.year<d2.year)
return 0;
else{
if(d1.month>d2.month)
return 1;
else if(d1.month<d2.month)
return 0;
else{
if(d1.day>d2.day)
return 1;
else return 0;
}
}
}
class EmployeeList;
class EmployeeNode
{
friend class EmployeeList;
private:
int no;
char *name;
Sex sex;
Date birthdate;
Date workdate;
Qualification quali;
Post post;
char *addr;
char phone[8];
EmployeeNode *next;
public:
EmployeeNode(){
name=addr=NULL;
next=NULL;
no=0;
}
EmployeeNode(int t){
name=addr=NULL;
next=NULL;
no=t;
}
EmployeeNode(int a,int b){
name=new char[a];
addr=new char[b];
next=NULL;
}
~EmployeeNode(){
delete name;
delete addr;
}
void CreateEmp(){
int t1,t2,t3;
cout<<"請輸入姓名:";
name=new char[10];
cin>>name;
cout<<"請輸入性別(1.男,2.女):";
cin>>t1;
switch(t1){
case 1:sex=Male;break;
case 2:sex=Female;break;
default:cout<<"不存在!"<<endl;
}
cout<<"請輸入出生日期:";
cout<<"年:";cin>>birthdate.year;
cout<<"月:";cin>>birthdate.month;
cout<<"日:";cin>>birthdate.day;
cout<<"請輸入工作開始日期:";
cout<<"年:";cin>>workdate.year;
cout<<"月:";cin>>workdate.month;
cout<<"日:";cin>>workdate.day;
cout<<"請輸入職位(1.老板,2.經理,3.職員):";
cin>>t2;
switch(t2){
case 1:post=Boss;break;
case 2:post=Manager;break;
case 3:post=Clerk;break;
default:cout<<"不存在!"<<endl;
}
cout<<"請輸入學歷(1.學士,2.研究生,3.博士,4.博士后):";
cin>>t3;
switch(t3){
case 1:quali=Master;break;
case 2:quali=Graduated;break;
case 3:quali=PhD;break;
case 4:quali=Postdoc;break;
default:cout<<"Not exist!"<<endl;
}
cout<<"請輸入地址:";
addr=new char[20];
cin>>addr;
cout<<"請輸入電話號碼(8 位):";
for(int i=0;i<8;i++)
cin>>phone[i];
}
void EditName(){
char *newname=new char[10];
cout<<"請輸入修改后的姓名:";
cin>>newname;
for(int i=0;i<10;i++)
name[i]=newname[i];
}
void EditPhone(){
char newphone[8];
cout<<"請輸入修改后的電話:";
for(int j=0;j<8;j++)
cin>>newphone[j];
for(int i=0;i<8;i++)
phone[i]=newphone[i];
}
void EditPost(){
int t;
cout<<"請輸入現在的職位(1.老板,2.經理,3.職員):";
cin>>t;
switch(t){
case 1:post=Boss;break;
case 2:post=Manager;break;
case 3:post=Clerk;break;
}
}
void EditNode(){
int t;
while(t!=4){
cout<<"請輸入你想修改的信息(1.姓名,2.電話,3.職位,4.退出修改):";
cin>>t;
switch(t){
case 1:EditName();break;
case 2:EditPhone();break;
case 3:EditPost();break;
case 4:break;
}
}
}
void print(){
cout<<"~ ~ ~ ~ ~ ~ ~ ~ ~ Information~ ~ ~ ~ ~ ~ ~ ~ ~ "<<endl;
cout<<"姓名:"<<name<<'\t'<<"性別:";
switch(sex){
case 0:cout<<"Male";break;
case 1:cout<<"Female";break;
}
cout<<'\t'<<"電話:";
for(int i=0;i<8;i++)
cout<<phone[i];
cout<<endl;
cout<<"出生日期:"<<birthdate.year<<"-"<<birthdate.month<<"-"<<birthdate.day<<'\t';
cout<<"工作日期:"<<workdate.year<<"-"<<workdate.month<<"-"<<workdate.day<<'\t';
cout<<"序號:"<<no<<endl;
cout<<"學歷:";
switch(quali){
case 0:cout<<"學士";break;
case 1:cout<<"研究生";break;
case 2:cout<<"博士";break;
case 3:cout<<"博士后";break;
}
cout<<'\t'<<"職位:";
switch(post){
case 0:cout<<"老板";break;
case 1:cout<<"經理";break;
case 2:cout<<"職員";break;
}
cout<<'\t';
cout<<"家庭住址:"<<addr<<endl;
cout<<"~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ "<<endl;
cout<<endl;
}
EmployeeNode *Assign(EmployeeNode *item,const EmployeeNode *p){
for(int i=0;i<10;i++)
item->name[i]=p->name[i];
for(i=0;i<20;i++)
item->addr[i]=p->addr[i];
item->birthdate.year=p->birthdate.year;
item->birthdate.month=p->birthdate.month;
item->birthdate.day=p->birthdate.day;
item->workdate.year=p->workdate.year;
item->workdate.month=p->workdate.month;
item->workdate.day=p->workdate.day;
for(i=0;i<8;i++)
item->phone[i]=p->phone[i];
item->quali=p->quali;
item->post=p->post;
item->sex=p->sex;
return item;
}
};
class EmployeeList{
private:
EmployeeNode *first,*last;
public:
EmployeeList(int value){
first=last=new EmployeeNode(value);
}
~EmployeeList(){
MakeEmpty();
delete first;
}
int Get_total(){
return last->no;
}
void MakeEmpty(){
EmployeeNode *q;
while(first->next!=NULL){
q=first->next;
first->next=q->next;
delete q;
}
last=first->next;
}
void Swap(EmployeeNode *p1,EmployeeNode *p2){
EmployeeNode *item=new EmployeeNode(10,20);
item->Assign(item,p1);
p1->Assign(p1,p2);
p2->Assign(p2,item);
delete item;
}
void Sort_name(){//按字典順序排序
EmployeeNode *p=first->next;
int exchange,num=Get_total();
while(num>1){
exchange=0;
while(p->next!=NULL){
int t=namedif(p->name,p->next->name);
if(p->name[t]>p->next->name[t]){
exchange=1;
Swap(p,p->next);
}
p=p->next;
}
if(exchange==0)//沒有交換過
break;
p=first->next;
num--;
}
}
void Sort_birth(){//按年齡從大到小排序
EmployeeNode *p=first->next;
int exchange,num=Get_total();
while(num>1){
exchange=0;
while(p->next!=NULL){
int t=birthdif(p->birthdate,p->next->birthdate);
if(t){
exchange=1;
Swap(p,p->next);
}
p=p->next;
}
if(exchange==0)//沒有交換過
break;
p=first->next;
num--;
}
}
void Sort_post(){
EmployeeNode *p=first->next;
int exchange,num=Get_total();
while(num>1){
exchange=0;
while(p->next!=NULL){
if(p->post>p->next->post){
exchange=1;
Swap(p,p->next);
}
p=p->next;
}
if(exchange==0)//沒有交換過
break;
p=first->next;
num--;
}
}
void Sort(){
cout<<"你想通過哪種方式排序(1.姓名,2.出生日期,3.職位)";
int t;cin>>t;
switch(t){
case 1:Sort_name();break;
case 2:Sort_birth();break;
case 3:Sort_post();break;
}
}
void Edit(){
int t;
cout<<"請輸入你想修改的職工的序號:";
cin>>t;
EmployeeNode *p=Find(t);
p->EditNode();
}
void Find_name(char *str){
EmployeeNode *p=first;
while(p->next!=NULL){
p=p->next;
if(strcmp(p->name,str)==0){
cout<<"這是符合你的查找條件的職工:"<<endl;
p->print();
}
}
}
void Find_quali(int t){
EmployeeNode *p=first;
while(p!=last){
p=p->next;
if(p->quali==(t-1)){
cout<<"這是符合你的查找條件的職工:"<<endl;
p->print();
}
}
}
void Find_post(int t){
EmployeeNode *p=first;
while(p!=last){
p=p->next;
if(p->post==(t-1)){
cout<<"這是符合你的查找條件的職工:"<<endl;
p->print();
}
}
}
void Find(){
char *str;
str=new char[8];
cout<<"你想通過哪種方式查找(1.姓名,2.學歷,3.職位)?:";
int t,t1,t2;
cin>>t;
switch(t){
case 1:cout<<"請輸入你所查找的姓名:";cin>>str;Find_name(str);break;
case 2:cout<<"請輸入你所查找的學歷(1.學士,2.研究生,3.博士,4.博士后):";
cin>>t1;
switch(t1){
case 1:Find_quali(1);break;
case 2:Find_quali(2);break;
case 3:Find_quali(3);break;
case 4:Find_quali(4);break;
}
break;
case 3:cout<<"請輸入你所查找的職位(1.老板,2.經理,3.職員):";
cin>>t2;
switch(t2){
case 1:Find_post(1);break;
case 2:Find_post(2);break;
case 3:Find_post(3);break;
}
break;
}
}
void Insert(){
EmployeeNode *p=first;
int i=1;
while(p!=last){
p=p->next;
i++;
}
EmployeeNode *item=new EmployeeNode(i);
item->CreateEmp();
if(p->next==NULL)
last=item;
p->next=item;
}
EmployeeNode *Find(int i)
{
EmployeeNode *p=first;
while(p!=NULL&&p->no!=i)
p=p->next;
return p;
}
void Remove(){
int t;
cout<<"請輸入你所需要刪除的職工的序號:";
cin>>t;
EmployeeNode *item=Find(t-1),*q;
if(item==NULL||item->next==NULL)
cout<<"不存在!"<<endl;
q=item->next;
item->next=q->next;
delete q;
EmployeeNode *p=first->next;
int i=1;
while(p!=NULL){
p->no=i;
i++;
p=p->next;
}
}
void print(){
EmployeeNode *p=first->next;
while(p!=NULL){
p->print();
p=p->next;
}
}
};
int main()
{
int t=0;
EmployeeList list(0);
cout<<"歡迎!這是由zblhero與吳滔創(chuàng)建的職工管理系統(tǒng)!"<<endl;
int cmd=0;
while(cmd!=7){
cout<<"-------------------MENU------------------"<<endl;
cout<<"1.創(chuàng)建一個新的職工;"<<endl;
cout<<"2.刪除一個已有的職工;"<<endl;
cout<<"3.查詢一個職工;"<<endl;
cout<<"4.編輯修改一個職工的信息;"<<endl;
cout<<"5.對職工排序;"<<endl;
cout<<"6.輸出所有的職工"<<endl;
cout<<"7.退出MENU"<<endl;
cout<<"-----------------------------------------"<<endl;
cin>>cmd;
switch(cmd){
case 1:list.Insert();break;
case 2:list.Remove();break;
case 3:list.Find();break;
case 4:list.Edit();break;
case 5:list.Sort();break;
case 6:list.print();break;
case 7:break;
default:cout<<"這不是命令!"<<endl;
}
if(cmd==7){
cout<<" 非常感謝您對本系統(tǒng)的支持!"<<endl;
cout<<" 聯系方式:bolei654@163.com!"<<endl;
break;
}
}
exit(1);
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -