#include<stdio.h>
#include<string.h>
#include<iostream>
#include<vector>
#include <algorithm>
#define For for(i=0;i<v.size();i++)
using namespace std;
typedef struct Node{
char number[15];
char name[20];
char sex[10];
char breaday[10];
char xueli[50];
char zhiwu[50];
char phonenumber[18];
char addreass[50];
}node;
vector<node> v;
int key=1;
void xiangmu()
{
printf("\n1、编号\t2、姓名\t3、性别\t4、出生年月 5、学历\t6、职务\t7、电话\t8、住址\n");
}
void insert_node()
{
cout<<"请按顺序输入:"<<endl;
xiangmu();
node p=*(new node);
cin>>p.number>>p.name>>p.sex>>p.breaday>>p.xueli>>p.zhiwu>>p.phonenumber>>p.addreass;
v.push_back(p);
}
void del_node()
{
cout<<"请输入你要删除的员工编号:";
int i;
char temp[50];
cin>>temp;
for(i=0;i<v.size();i++)
{
if(strcmp(v[i].number,temp)==0)
{ v.erase(v.begin()+i); cout<<"删除成功!"<<endl; return ;}
}
if(i==v.size())
cout<<"你要删除的员工号码未找到!!!"<<endl;
}
void print(int i)
{
printf("%s %s %s %s %s %s %s %s\n",v[i].number,v[i].name,v[i].sex,v[i].breaday,v[i].xueli,v[i].zhiwu,v[i].phonenumber,v[i].addreass);
}
void find_node()
{
xiangmu();
cout<<"请选择你要查找的类型和内容:";
int i,choice,count=0;
char s[20];
cin>>choice>>s;
switch(choice)
{
case 1:{
For if(strcmp(v[i].number,s)==0) print(i),count++;}
case 2:{
For if(strcmp(v[i].name,s)==0) print(i),count++;}
case 3:{
For if(strcmp(v[i].sex,s)==0) print(i),count++;}
case 4:{
For if(strcmp(v[i].breaday,s)==0) print(i),count++;}
case 5:{
For if(strcmp(v[i].xueli,s)==0) print(i),count++;}
case 6:{
For if(strcmp(v[i].zhiwu,s)==0) print(i),count++;}
case 7:{
For if(strcmp(v[i].phonenumber,s)==0) print(i),count++;}
case 8:{
For if(strcmp(v[i].addreass,s)==0) print(i),count++;}
}
if(count==0)
cout<<"未找到此员工"<<endl;
else
cout<<"共查找到"<<count<<"个员工"<<endl;
}
void updata()
{
xiangmu();
cout<<"请输入你要更改的员工号、项目号和要更新的内容:";
int i,choice;
char n[20],temp[20];
cin>>n>>choice>>temp;
For if(strcmp(n,v[i].number)==0) {
switch(choice)
{
case 1:strcpy(v[i].number,temp);break;
case 2:strcpy(v[i].name,temp);break;
case 3:strcpy(v[i].sex,temp);break;
case 4:strcpy(v[i].breaday,temp);break;
case 5:strcpy(v[i].xueli,temp);break;
case 6:strcpy(v[i].zhiwu,temp);break;
case 7:strcpy(v[i].phonenumber,temp);break;
case 8:strcpy(v[i].addreass,temp);break;
default :cout<<"项目不合法"<<endl;
}
}
}
bool comp(node a,node b)
{
switch(key)
{
case 2:return strcmp(a.name,b.name)>0;
case 3:return strcmp(a.sex,b.sex)>0;
case 4:return strcmp(a.breaday,b.breaday)>0;
case 5:return strcmp(a.xueli,b.xueli)>0;
case 6:return strcmp(a.zhiwu,b.zhiwu)>0;
case 7:return strcmp(a.phonenumber,b.phonenumber)>0;
case 8:return strcmp(a.addreass,b.addreass)>0;
default :return strcmp(a.number,b.number)>0;
}
}
void sort_node()
{
xiangmu();
cout<<"请输入你要排序的关键字的序号:";
cin>>key;
sort(v.begin(),v.end(),comp);
}
void alloutprint()
{
xiangmu();
int i;
For print(i);
}
int main()
{
printf("\n\n****************welcome********************\n");
int op;
do{
printf("\n1、插入\t2、查询\t3、更新\t4、删除\t5、排序\n6、清屏\t7、查看全部信息\t8、退出\n");
cout<<"请输入你的操作:";
cin>>op;
switch(op)
{
case 1:insert_node();break;
case 2:find_node();break;
case 3:updata();break;
case 4:del_node();break;
case 5:sort_node();break;
case 6:system("cls");break;
case 7:alloutprint();break;
case 8:exit(1);
default :cout<<"没有此操作!!!"<<endl;
}
}while(1);
return 0;
}
我把 我的数据结构课程设计给你了,员工管理系统。差不多。你看着改改就OK了。
追问非常感谢。 好人啊。
很值得参考
追答不客气。