没有合适的资源?快使用搜索试试~ 我知道了~
包括职工号,姓名,职务,单位,薪水。 还有按条件查询以及排序
资源详情
资源评论
资源推荐
#include<iostream.h>
#include<fstream.h>
#include<string.h>
#include<stdlib.h>
class Employee
{
public:
int emp_id;
char emp_name[20];
int age;
float salary;
char department[20];
char position[20];
Employee *next;
};
class list
{ public:
Employee *start;
list();
bool listEmpty();
void insert();//插入节点.
void displaylist();//输出员工信息,默认按 ID 升序.
int search(int chose);//按员工所有参数进行搜索.
void delinfo(int chose);//删除节点.
void sort();//可选择按员工所有参数进行升序或降序的排列.
void checkidage(int check);//输入格式检查。
};
list::list()
{
start=NULL;
}
bool list::listEmpty()//检查链表是否为空
{
if(start==NULL)
return true;//为空,则返回 true.
else
return false;
}
void list::checkidage(int check)
{
if(check<0||(int)check!=check)
{
cout<<"输入格式错误!!"<<endl;
return;
}
}
void list::insert()//插入添加信息,默认升序。
{
int id,ag;
float sa;
char nm[20],dep[20],po[20];//定义临时变量
cout<<"输入员工的职工号: ";
cin>>id;
cout<<"输入员工的姓名 : ";
cin.ignore();
cin.getline(nm,20);
cout<<"输入员工的年龄(18-60): ";
cin>>ag;
if(ag<18||ag>60)
{
cout<<"输入年龄不合要求!"<<endl;
return;
}
cout<<"输入员工的薪水 : ";
cin>>sa;
cout<<"输入员工单位: ";
cin.ignore();
cin.getline(dep,20);
cout<<"输入员工的职务 : ";
cin.getline(po,20);//此处不用再加 cin.ignore();加了之后无法输出 PO[0];即输入 QWE,
只能输出 WE。
Employee *newnode=new Employee;
newnode->emp_id=id;
newnode->age=ag;
newnode->salary=sa;
strcpy(newnode->emp_name,nm);
strcpy(newnode->department,dep);
strcpy(newnode->position,po);
if(start==NULL||id<=start->emp_id)//判断输入的 ID 是否已经存在
{
if(start!=NULL&&id==start->emp_id)
{ cout<<"\n 此 ID 已经存在!!\n";//重复则报错
return;
}
newnode->next=start;
start=newnode;
return;
}
Employee *current,*previous;
previous=start;
current=start;
while(current!=NULL&&id>=current->emp_id)
{
if(id==current->emp_id)
{
cout<<"\n 此 ID 已经存在\n";
return;
}
previous=current;
current=current->next;
}
newnode->next=current;
previous->next=newnode;
}
void list::displaylist()//输出所有员工信息。
{
Employee *currentnode;
for(currentnode=start;currentnode!=NULL;currentnode=currentnode->next)
{
cout<<"员工的职工号 : "<<currentnode->emp_id<<endl;
cout<<"员工的姓名 : "<<currentnode->emp_name<<endl;
cout<<"员工的年龄 : "<<currentnode->age<<endl;
cout<<"员工的薪水 : "<<currentnode->salary<<endl;
cout<<"员工的单位: "<<currentnode->department<<endl;
cout<<"员工的职务 : "<<currentnode->position<<endl<<endl;
}
}
int list::search(int chose)//员工所有信息的搜索
{
switch(chose)//选择搜索模式
{
case 1:
{
int id;
Employee *current,*previous;
previous=start;
current=start;
cout<<"请输入员工职工号:";
cin>>id;
while(current!=NULL&&id!=current->emp_id)
{
previous=current;
current=current->next;
}
if(current==NULL)//若未找到符合条件的数据,返回 0
{
cout<<"没有你要的资料。"<<endl;
return 0;
}
else
{
cout<<"你所要的数据:";
cout<<"**员工职工号 : "<<current->emp_id<<endl;
cout<<" **员工的姓名 : "<<current->emp_name<<endl;
cout<<" **员工的年龄 : "<<current->age<<endl;
cout<<" **员工的薪水 : "<<current->salary<<endl;
cout<<" **员工的单位: "<<current->department<<endl;
cout<<" **员工的职务 : "<<current->position<<endl;
return id;
}
}break;
case 2:
{
int id[100],n=0;
char nm[20];
Employee *current,*previous;
previous=start;
current=start;
cout<<"请输入员工的姓名:";
cin.ignore();
cin.getline(nm,20);
for(current=start;current!=NULL;current=current->next)
{
if(strcmp(current->emp_name,nm)==0)//判断 emp_name 和 nm 是否一致
{
id[n]=current->emp_id;
cout<<"数据"<<n+1<<":";
cout<<"**员工职工号 : "<<current->emp_id<<endl;
剩余25页未读,继续阅读
fangbo1989
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0