zoukankan      html  css  js  c++  java
  • 员工信息

    #include<iostream>
    #include<fstream>
    #include<string>
    #include<iomanip>
    using namespace std;
    typedef struct node
    {
    	int no,deno,salary;
    	string name;
    	node *pno,*depno,*psalary,*next;
    }*ptrn;
    int length(ptrn &e)
    {
    	int count=0;
        ptrn temm;
    	temm=e;
    	while(temm!=0)
    	{
    		count++;
    		temm=temm->next;
    	}
    	return count;
    }
    void main()
    {
    	ifstream inf("salary.dat",ifstream::out|ifstream::app);
    	string no1,name1,depart,salary1;
    	int time=0;
    	ptrn head,temp,newnode;
    	head=0;
    	while(!inf.eof())
    	{                                                  
    		inf>>no1>>name1>>depart>>salary1;
    		if(time==0)
    		{
    			time=1;
    			continue;
    		}
    		newnode=new node;
    		newnode->no=atoi(no1.c_str());
    		newnode->name=name1;
    		newnode->deno=atoi(depart.c_str());
    		newnode->salary=atoi(salary1.c_str());
    		if(head==0)
    		{
               head=newnode;
    		   temp=newnode;
    		}
    		else
    		{
    			temp->next=newnode;
    			temp=newnode;
    		}
    	}
    	if(head)temp->next=0;
    	inf.close();
        cout<<"               |     (1)添加职工信息      |"<<endl;
    	cout<<"               |     (2)输出所有信息      |"<<endl;
    	cout<<"               |     (3)按职工号输出      |"<<endl;
        cout<<"               |     (4)按部门号输出      |"<<endl;
        cout<<"               |     (5)按工资输出        |"<<endl; 
        cout<<"               |     (6)清空职员信息      |"<<endl;
        cout<<"               |     (7)退出              |"<<endl;
    	cout<<"___________________________________________________________________"<<endl;
    	while(1)
    	{
    		cout<<"                      请输入序号             "<<endl;   
    	    int m;
    	    cin>>m;
    	    if(m==1)
    		{
              cout<<"请按照职员号------姓名-------部门号-------工资的顺序输入"<<endl;
    		  if(head)
    		  {
    			
    			newnode=new node;
    			cin>>newnode->no>>newnode->name>>newnode->deno>>newnode->salary;
    			temp->next=newnode;
    			temp=newnode;
    		   }
    		  else
    		  {
                  newnode=new node;
    		      cin>>newnode->no>>newnode->name>>newnode->deno>>newnode->salary;
    			  head=newnode;
    			  temp=newnode;
    		  }
    		  temp->next=0;
    		  ofstream ouf1("salary.dat");
    		  ouf1<<std::left<<setw(10)<<"职工号"<<std::right<<setw(6)<<"姓--名"<<std::right<<setw(10)<<"部门号"<<std::right<<setw(10)<<"工--资"<<endl;
    		  ptrn tepp;
    		  tepp=head;
    		  while(tepp!=0)
    		  {
    			  ouf1<<std::left<<setw(10)<<tepp->no<<std::right<<setw(6)<<tepp->name<<std::right<<setw(10)<<tepp->deno<<std::right<<setw(10)<<tepp->salary<<endl;
    			  tepp=tepp->next;
    		  }
    		  ouf1.close();
              cout<<"___________________________________________________________________"<<endl;
    		}
    		else if(m==2)
    		{
    			if(head==0)
    				cout<<"                    无信息"<<endl;
    			else
    			{
                    ptrn tem;
    		    	tem=head;
    			    cout<<std::left<<setw(10)<<"职工号"<<std::right<<setw(6)<<"姓--名"<<std::right<<setw(10)<<"部门号"<<std::right<<setw(10)<<"工--资"<<endl;
    			    while(tem!=0)
    				{
    			    	cout<<std::left<<setw(10)<<tem->no<<std::right<<setw(6)<<tem->name<<std::right<<setw(10)<<tem->deno<<std::right<<setw(10)<<tem->salary<<endl;
    				    tem=tem->next;
    				}
    			}
                cout<<"___________________________________________________________________"<<endl;
    		}
    		else if(m==3)
    		{
    		    int mm=0;
    			mm=length(head);
    			for(int i=0;i<mm;i++)
    			{
    				 ptrn te;
    			     te=head;
    				for(int j=0;j<mm-i-1;j++)
    				{                                                                     
    					if(te->no>te->next->no)
    					{
    						ptrn newnode1;
    						newnode1=new node;
    						newnode1->no=te->next->no;
    						newnode1->name=te->next->name;
    						newnode1->deno=te->next->deno;
    						newnode1->salary=te->next->salary;
    						te->next->no=te->no;
    						te->next->name=te->name;
    						te->next->deno=te->deno;
    						te->next->salary=te->salary;
    						te->no=newnode1->no;
    						te->name=newnode1->name;
    						te->deno=newnode1->deno;
    						te->salary=newnode1->salary;                 
    					}
    					te=te->next;                              
    				}
    			}
    			ptrn tem1,tem2;			
    			tem2=head;
    			cout<<std::left<<setw(10)<<"职工号"<<std::right<<setw(6)<<"姓--名"<<std::right<<setw(10)<<"部门号"<<std::right<<setw(10)<<"工--资"<<endl;
    			while(tem2!=0)
    			{
    				tem1=new node;
                   tem1->no=tem2->no;
    			   tem1->name=tem2->name;
    			   tem1->deno=tem2->deno;
    			   tem1->salary=tem2->salary;
    			   tem1->pno=0;
                   cout<<std::left<<setw(10)<<tem1->no<<std::right<<setw(6)<<tem1->name<<std::right<<setw(10)<<tem1->deno<<std::right<<setw(10)<<tem1->salary<<endl;
    			   tem1=tem1->pno;
    			   tem2=tem2->next;
    			}
                cout<<"___________________________________________________________________"<<endl;
    		}
    		else if(m==4)
    		{
             int mm=0;
    			mm=length(head);
    			for(int i=0;i<mm;i++)
    			{
    				 ptrn te;
    			     te=head;
    				for(int j=0;j<mm-i-1;j++)
    				{                                                                     
    					if(te->deno>te->next->deno)
    					{
    						ptrn newnode1;
    						newnode1=new node;
    						newnode1->no=te->next->no;
    						newnode1->name=te->next->name;
    						newnode1->deno=te->next->deno;
    						newnode1->salary=te->next->salary;
    						te->next->no=te->no;
    						te->next->name=te->name;
    						te->next->deno=te->deno;
    						te->next->salary=te->salary;
    						te->no=newnode1->no;
    						te->name=newnode1->name;
    						te->deno=newnode1->deno;
    						te->salary=newnode1->salary;                 
    					}
    					te=te->next;                              
    				}
    			}
    			ptrn tem1,tem2;			
    			tem2=head;
    			cout<<std::left<<setw(10)<<"职工号"<<std::right<<setw(6)<<"姓--名"<<std::right<<setw(10)<<"部门号"<<std::right<<setw(10)<<"工--资"<<endl;
    			while(tem2!=0)
    			{
    				tem1=new node;
                   tem1->no=tem2->no;
    			   tem1->name=tem2->name;
    			   tem1->deno=tem2->deno;
    			   tem1->salary=tem2->salary;
    			   tem1->depno=0;
                   cout<<std::left<<setw(10)<<tem1->no<<std::right<<setw(6)<<tem1->name<<std::right<<setw(10)<<tem1->deno<<std::right<<setw(10)<<tem1->salary<<endl;
    			   tem1=tem1->depno;
    			   tem2=tem2->next;
    			   
    			}
    			cout<<"___________________________________________________________________"<<endl;
    		}
    		else if(m==5)
    		{
    		    
    			int mm=0;
    			mm=length(head);
    			for(int i=0;i<mm;i++)
    			{
    				 ptrn te;
    			     te=head;
    				for(int j=0;j<mm-i-1;j++)
    				{                                                                     
    					if(te->salary>te->next->salary)
    					{
    						ptrn newnode1;
    						newnode1=new node;
    						newnode1->no=te->next->no;
    						newnode1->name=te->next->name;
    						newnode1->deno=te->next->deno;
    						newnode1->salary=te->next->salary;
    						te->next->no=te->no;
    						te->next->name=te->name;
    						te->next->deno=te->deno;
    						te->next->salary=te->salary;
    						te->no=newnode1->no;
    						te->name=newnode1->name;
    						te->deno=newnode1->deno;
    						te->salary=newnode1->salary;                 
    					}
    					te=te->next;                              
    				}  
    			}
    			ptrn tem1,tem2;			
    			tem2=head;
    			cout<<std::left<<setw(10)<<"职工号"<<std::right<<setw(6)<<"姓--名"<<std::right<<setw(10)<<"部门号"<<std::right<<setw(10)<<"工--资"<<endl;
    			while(tem2!=0)
    			{
    				tem1=new node;
                   tem1->no=tem2->no;
    			   tem1->name=tem2->name;
    			   tem1->deno=tem2->deno;
    			   tem1->salary=tem2->salary;
    			   tem1->psalary=0;
                   cout<<std::left<<setw(10)<<tem1->no<<std::right<<setw(6)<<tem1->name<<std::right<<setw(10)<<tem1->deno<<std::right<<setw(10)<<tem1->salary<<endl;
    			   tem1=tem1->psalary;
    			   tem2=tem2->next; 
    			}
                 cout<<"___________________________________________________________________"<<endl; 
    		}
    		else if(m==6)
    		{
    			ofstream ouf5("salary.dat");
    			ouf5<<std::left<<setw(10)<<"职工号"<<std::right<<setw(6)<<"姓--名"<<std::right<<setw(10)<<"部门号"<<std::right<<setw(10)<<"工--资"<<endl;
                ouf5.close();
    			cout<<"                         已清空"<<endl;
                cout<<"___________________________________________________________________"<<endl;
    		}
    		else
    			break;
    	}
    }
    

  • 相关阅读:
    在預設設定下,SQL Server 不允許遠端連接
    windows7语言包安装失败
    使一个销售组织能够销售另一个销售组织的产品
    转:多线程六种多线程方法解决UI线程阻塞
    转:BeginInvoke和EndInvoke方法 (原网址:http://www.cnblogs.com/nokiaguy/archive/2008/07/13/1241817.html)
    员工客户的统驭科目不能更改?
    公司间采购的退货(有序列号)
    排程 经典图示
    取消凭证分解 (取消公司下的多个利润中心)
    查找已删除的交货单信息
  • 原文地址:https://www.cnblogs.com/zztong/p/6695294.html
Copyright © 2011-2022 走看看