| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 467 人关注过本帖
标题:求C++高手完成职工管理系统
取消只看楼主 加入收藏
dd521
Rank: 1
来 自:湖南长沙
等 级:新手上路
帖 子:9
专家分:0
注 册:2009-3-1
结帖率:100%
收藏
 问题点数:0 回复次数:0 
求C++高手完成职工管理系统
#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<fstream.h>
struct work
{
      char name[20];//姓名
      char num[20];//工职号
};
class WORK//职工信息基类
{
  public:
      work wk;
      WORK()  //构造函数
      {
      }
      void dispwk_in();//职工信息简表存档(只含有姓名和年龄的职工信息简表存档)
      void dispwk();//简表输出函数(文件)
      ~WORK()  //析构函数
      {}
};
struct WORK_manager
{      
     int age;//年龄
     char sex[20];//性别
     char greed[20];//学历
     int pay;//工资
     char dress[20];//住址
     char tell[20];//电话
};
class work_manager:public WORK //职工信息处理
{
  public:
        WORK_manager st;
        work_manager *next;
        work_manager():WORK()//构造函数
        {
        }
        void handle_menu();//菜单函数
        work_manager* add();//增加职工信息
        void addin();//增加函数
        void dispwks_in();//存档函数(全部数据存入文件并验证是否正确存档)
        void dispwks();//全部数据输出函数(文件)   
        void finde();//查询函数(多种方式查询)
        work_manager* cute();//删除函数(指定的职工号和姓名)
        void dail();//修改函数(指定的职工号和姓名)
        void out();//职工信息浏览函数(内存)
        
        void handle_menu1();//首菜单函数
         friend istream& operator>>(istream &in,work_manager& A)
         {
             in>>A.wk.name>>A.wk.num>>A.st.age>>A.st.sex>>A.st.greed>>A.st.pay>>A.st.dress>>A.st.tell;
             return in;
         }
         friend ostream& operator<<(ostream &out,const work_manager* A)
         {
            out<<"\t"<<A->wk.name<<"\t"<<A->wk.num<<"\t"<<A->st.age<<"\t"<<A->st.sex<<"\t"<<A->st.greed<<"\t"<<A->st.pay<<"\t"<<A->st.dress<<"\t"<<A->st.tell;
            return out;
         }
         ~work_manager()//析构函数
         {}
}*head   ;
void work_manager::handle_menu()//首菜单函数
{
   int i;
   handle_menu1();
   cin>>i;
   while(i<1||i>7)
   {
      system("cls");
      cout<<"输入有错,请重新输入:";
      handle_menu1();
      cin>>i;
   }
   switch(i)
   {
      case 1:dail(); break;
      case 2:cute(); break;
      case 3:finde(); break;
      case 4:out(); break;
      case 5:dispwk_in(); break;
      case 6:head=add(); break;
      case 7:exit(0); break;
   }
}
void WORK::dispwk_in()//职工信息简表存档(只含有姓名和年龄的职工信息简表存档)
{   
    ifstream fout("E:\\职工信息管理系统2.txt",ios::out);
    if(!fout)
    {
        cout<<"文件未打开!"<<endl;
        //handle_menu();
    }
    work_manager *opp;
    opp=head;
    if(!opp)
    {
         cout<<"无文件存档!"<<endl;
         //handle_menu();
    }
    while(opp->next!=NULL)
    {
        fout<<opp->wk.name;
        fout<<opp->wk.num;
        opp++;
    }
    fout.close();
}
void WORK::dispwk()//简表输出函数(文件)
{
   ifstream fin("e:\\职工信息管理系统2.txt",ios::in);
   if(!fin)
   {
       cout<<"没打开文件!\n";
       exit(1);
   }
   else
   {
   
     work_manager *hand=NULL,*q ,*p;
     p=new (work_manager);
     fin>>p->wk.name;
     fin>>p->wk.num;
     fin>>p->st.age;
     fin>>p->st.dress;
     fin>>p->st.greed;
     fin>>p->st.pay;
     fin>>p->st.sex;
     fin>>p->st.tell;
     if(!p)
     {
        cout<<"内存不足,请重启!"<<endl;
        exit(1);
     }
     while(p->wk.num!=0)
     {
          q=new work_manager;            
          if(!q)
          {
            cout<<"内存不足,请重启!"<<endl;
            exit(1);
          }
          fin>>p->wk.name;
          fin>>p->wk.num;
          fin>>p->st.age;
          fin>>p->st.dress;
          fin>>p->st.greed;
          fin>>p->st.pay;
          fin>>p->st.sex;
          fin>>p->st.tell;
          p->next=NULL;   
          if(hand==NULL)
          {
          hand=p;
          }   
          else
          {
             q=hand;
             while(q->next!=NULL)
             {
                q=q->next;     
             }
             q->next=p;
          }
    }
   }
}
void work_manager::dispwks_in()//存档函数(全部数据存入文件并验证是否正确存档)
{
      ifstream fout("E:\\职工信息管理系统.txt",ios::out);
    if(!fout)
    {
        cout<<"文件未打开!"<<endl;
        handle_menu();
    }
        work_manager *opp;
       opp=head;
        if(!opp)
        {
            cout<<"无文件存档!"<<endl;
             handle_menu();
        }
    while(opp->next!=NULL)
    {
        fout<<opp->wk.name;
        fout<<opp->wk.num;
        fout<<opp->st.age;
        fout<<opp->st.dress;
        fout<<opp->st.greed;
        fout<<opp->st.pay;
        fout<<opp->st.sex;
        fout<<opp->st.tell;
        opp++;
    }
    fout.close();
}
void work_manager::dispwks()//全部数据输出函数(文件)
{
   ifstream fin("e:\\职工信息管理系统.txt",ios::in);
   if(!fin)
   {
       cout<<"没打开文件!\n";
       exit(1);
   }
   else
   {
   
     work_manager *hand=NULL,*q ,*p;
     p=new (work_manager);
     fin>>p->wk.name;
     fin>>p->wk.num;
     fin>>p->st.age;
     fin>>p->st.dress;
     fin>>p->st.greed;
     fin>>p->st.pay;
     fin>>p->st.sex;
     fin>>p->st.tell;
     if(!p)
     {
        cout<<"内存不足,请重启!"<<endl;
        exit(1);
     }
     while(p->wk.num!=0)
     {
          q=new work_manager;            
          if(!q)
          {
            cout<<"内存不足,请重启!"<<endl;
            exit(1);
          }
          fin>>p->wk.name;
          fin>>p->wk.num;
          fin>>p->st.age;
          fin>>p->st.dress;
          fin>>p->st.greed;
          fin>>p->st.pay;
          fin>>p->st.sex;
          fin>>p->st.tell;
          p->next=NULL;   
          if(hand==NULL)
          {
          hand=p;
          }   
          else
          {
             q=hand;
             while(q->next!=NULL)
             {
                q=q->next;     
             }
             q->next=p;
          }
    }
   }
   
}
void work_manager::finde()//查询函数(多种方式查询)
{
    char input[20];
    int sa;
    system("cls");
    cout<<"1.通过职工号"<<endl;
    cout<<"2.通过姓名"<<endl;
    cout<<"3.通过性别"<<endl;//
    cout<<"4.通过学历"<<endl;
    cout<<"5.通过地址"<<endl;
    cin>>sa;
    while(sa<1||sa>5)
    {
            cout<<"输入有错,重选1-5"<<endl;
            cin>>sa;
            break;
    }
    work_manager *q;
    q=head;
    while(q!=NULL)
    {
            switch(1)
            {
              cout<<"请输入职工号:"<<endl;
              gets(input);
              while(q->next!=NULL)
              {
                 if(strcmp(input,q->wk.num)==0)
                {
                   cout<<"\t工号";
                   cout<<"\t姓名\t年龄\t性别\t学历\t工资\t地址\t联系电话\n";
                   cout<<'\t'<<q->wk.num<<'\t'<<q->wk.name<<'\t'<<q->st.age<<'\t'<<q->st.sex<<'\t'<<q->st.greed<<'\t'<<q->st.pay<<'\t'<<q->st.dress<<'\t'<<q->st.tell<<endl;
                }
                q++;
              }
            }  
            switch(2)
            {
              cout<<"请输入姓名:"<<endl;
              gets(input);
              while(q->next!=NULL)
              {
                if(strcmp(input,q->wk.name)==0)
                {
                   cout<<"\t工号";
                   cout<<"\t姓名\t年龄\t性别\t学历\t工资\t地址\t联系电话\n";
                   cout<<'\t'<<q->wk.num<<'\t'<<q->wk.name<<'\t'<<q->st.age<<'\t'<<q->st.sex<<'\t'<<q->st.greed<<'\t'<<q->st.pay<<'\t'<<q->st.dress<<'\t'<<q->st.tell<<endl;
        
                }
                 q++;
              }
            }
            switch(3)
            {
              gets(input);
              while(q->next!=NULL)
              {
                if(strcmp(input,q->st.sex)==0)
                {
                   cout<<"\t工号";
                   cout<<"\t姓名\t年龄\t性别\t学历\t工资\t地址\t联系电话\n";
                   cout<<'\t'<<q->wk.num<<'\t'<<q->wk.name<<'\t'<<q->st.age<<'\t'<<q->st.sex<<'\t'<<q->st.greed<<'\t'<<q->st.pay<<'\t'<<q->st.dress<<'\t'<<q->st.tell<<endl;
                }
                q++;
              }
            }
            switch(4)
            {
              gets(input);
              while(q->next!=NULL)
              {
                if(strcmp(input,q->st.greed)==0)
                {
                   cout<<"\t工号";
                   cout<<"\t姓名\t年龄\t性别\t学历\t工资\t地址\t联系电话\n";
                   cout<<'\t'<<q->wk.num<<'\t'<<q->wk.name<<'\t'<<q->st.age<<'\t'<<q->st.sex<<'\t'<<q->st.greed<<'\t'<<q->st.pay<<'\t'<<q->st.dress<<'\t'<<q->st.tell<<endl;
                }
                q++;
              }
            }
            switch(5)
            {
              gets(input);
              while(q->next!=NULL)
              {
                 if(strcmp(input,q->st.dress)==0)
                 {
                   cout<<"\t工号";
                   cout<<"\t姓名\t年龄\t性别\t学历\t工资\t地址\t联系电话\n";
                   cout<<'\t'<<q->wk.num<<'\t'<<q->wk.name<<'\t'<<q->st.age<<'\t'<<q->st.sex<<'\t'<<q->st.greed<<'\t'<<q->st.pay<<'\t'<<q->st.dress<<'\t'<<q->st.tell<<endl;
                 }
                 q++;
              }
            }      
    }
    cout<<"没有找到相应的记录"<<endl;
}
work_manager* work_manager::cute()//删除函数(指定的职工号和姓名)
{
    char input[20];
    int sa;
    cout<<"\t\t\t1.通过职工号"<<endl;
    cout<<"\t\t\t2.通过姓名"<<endl;
    cout<<"请输入:"<<endl;
   
    cin>>sa;
    while(sa<1||sa>2)
    {
            cout<<"输入有错,重选1-2"<<endl;
            cin>>sa;
            break;
    }
    switch(sa)
    {
       case 1:
        cout<<"请输入职工号:"<<endl;
        break;
           case 2:
        cout<<"请输入姓名:"<<endl;
        
    }
    gets(input);
    work_manager *p,*q;
    q=head;
    while(q!=NULL)
    {
   
        if((sa==1&&strcmp(input,q->wk.num)==0)||sa==2&&strcmp(input,q->wk.name)==0)
        {
            if(q==head)
                head=q->next;
            else
            {
                 p->next=q->next;
                 cout<<"被删除记录的信息如下:"<<endl;
                 cout<<"\t工号\t";
                 cout<<"\t姓名\t年龄\t性别\t学历\t工资\t地址\t联系电话\n";
                 cout<<'\t'<<q->wk.num<<'\t'<<q->wk.name<<'\t'<<q->st.age<<'\t'<<q->st.sex<<'\t'<<q->st.greed<<'\t'<<q->st.pay<<'\t'<<q->st.dress<<'\t'<<q->st.tell<<endl;
                 delete(q);
            }
        }
        else
        {
           p=q;
           q=q->next;
        
        }
    }
    cout<<"没有找到相应的记录"<<endl;
    return head;

}
void work_manager::dail()//修改函数(指定的职工号和姓名)
{
      char input[20];
    int sa;
    cout<<"\t\t\t1.通过职工号"<<endl;
    cout<<"\t\t\t2.通过姓名"<<endl;
    cout<<"请输入职工号:"<<endl;
   
    cin>>sa;
    while(sa<1||sa>2)
    {
            cout<<"输入有错,重选1-2"<<endl;
            cin>>sa;
            break;
    }
    switch(sa)
    {
       case 1:
        cout<<"请输入职工号:"<<endl;
        break;
           case 2:
        cout<<"请输入姓名:"<<endl;
        
    }
    gets(input);
    work_manager *p,*q;
    q=head;
    while(q!=NULL)
    {
   
        if((sa==1&&strcmp(input,q->wk.num)==0)||sa==2&&strcmp(input,q->wk.name)==0)
        {
            if(q==head)
                head=q->next;
            else
            {
                 cout<<"需被修改记录的信息如下:"<<endl;
                 cout<<"\t工号";
                 cout<<"\t姓名\t年龄\t性别\t学历\t工资\t地址\t联系电话\n";
                     cout<<'\t'<<q->wk.num<<'\t'<<q->wk.name<<'\t'<<q->st.age<<'\t'<<q->st.sex<<'\t'<<q->st.greed<<'\t'<<q->st.pay<<'\t'<<q->st.dress<<'\t'<<q->st.tell<<endl;
                     cout<<"请输入!"<<endl;
                             cout<<"职工号:";
                             cin>>q->wk.num;
                             cout<<"姓名:";
                             cin>>q->wk.name;
                             cout<<"年龄:";
                             cin>>q->st.age;
                             cout<<"性别:";
                             cin>>q->st.sex;
                             cout<<"学历:";
                             cin>>q->st.greed;
                             cout<<"工资:";
                             cin>>q->st.pay;
                             cout<<"地址:";
                             cin>>q->st.dress;
                             cout<<"电话号码:";
                             cin>>st.tell;
            }
        }
        else
        {
           p=q;
           q=q->next;
        
        }
    }
    cout<<"没有找到相应的记录"<<endl;
  
}
void work_manager::out()//职工信息浏览函数(内存)
{
   work_manager *q;
   q=head;
   while(q->next!=NULL)
   {
     cout<<"\t工号";
     cout<<"\t姓名\t年龄\t性别\t学历\t工资\t地址\t联系电话\n";
     cout<<'\t'<<q->wk.num<<'\t'<<q->wk.name<<'\t'<<q->st.age<<'\t'<<q->st.sex<<'\t'<<q->st.greed<<'\t'<<q->st.pay<<'\t'<<q->st.dress<<'\t'<<q->st.tell<<endl;                     
    q++;
   }
   cout<<"没有找到相应的记录"<<endl;
   handle_menu();
}
work_manager* work_manager::add()
{
   work_manager *p ,*hand,*q;
   char h='y';
   //cout<<"确认增加请按Y,返回请按其他键:";
   //cin>>h;
   hand=NULL;
   while(h=='y'||h=='Y')
   {

    q=new(work_manager);   
    if(!q)
    {
          cout<<"内存不足,请重启运行!"<<endl;
          exit(0);   
    }
    else
    {
      if(hand==NULL)
      {
         hand=q;
      }   
      else
      {
        p=hand;
        q->addin();
        while(p->next=NULL)
        {
             p=p->next;     
        }
        p->next=q;
        q->next=NULL;
      }
    }
    cout<<"继续添加请按Y,退出请按其他键:";
    cin>>h;
   }
   system("cls");
   handle_menu();
   return  hand;
}
void work_manager::addin()
{
            cout<<"\t姓名:";
            cin>>wk.name;
            cout<<"\t职工号:";
            cin>>wk.num;
            cout<<"\t年龄:";
            cin>>st.age;
            cout<<"\t性别:";
            cin>>st.sex;
            cout<<"\t学历:";
            cin>>st.greed;
            cout<<"\t工资:";
            cin>>st.pay;
            cout<<"\t地址:";
            cin>>st.dress;
            cout<<"\t联系电话:";
            cin>>st.tell;
}

void work_manager::handle_menu1()//菜单函数
{
   cout<<"    \t\t\t    ┎════┰════┒          "<<endl;
   cout<<"    \t\t\t    ║欢迎﹎  ┃﹎﹎﹎﹎║          "<<endl;
   cout<<"    \t\t\t    ║﹎﹎﹎﹎┃登陆﹎﹎║          "<<endl;
   cout<<"    \t\t\t    ║﹎﹎职管┃ ﹎﹎﹎ ╱╲        "<<endl;
   cout<<"    \t\t\t    ║﹎﹎﹎﹎  ﹎系统..◣╱        "<<endl;
   cout<<"    \t\t\t    ┖════┸════┚ .        "<<endl;
   cout<<"                                              "<<endl;
   cout<<"    \t\t\t    -○━━━━━━━━●━.        "<<endl;
   cout<<"\t\t\t1.修改职工信息\t\t2.删除职工信息"<<endl;
   cout<<"\t"<<endl;
   cout<<"\t"<<endl;
   cout<<"\t\t\t3.查询职工信息\t\t4.显示职工信息"<<endl;
   cout<<"\t"<<endl;
   cout<<"\t"<<endl;
   cout<<"\t\t\t5.存档职工信息\t\t6.增加职工信息"<<endl;//菜单选择区
   cout<<"\t"<<endl;
   cout<<"\t"<<endl;
   cout<<"\t\t\t7.退出"<<endl;
   cout<<"\t\t请选择输入:";
}
int main()
{
   work_manager worker;
   worker.handle_menu();
   return 0;
}
搜索更多相关主题的帖子: 职工 管理 系统 
2009-09-25 18:59
快速回复:求C++高手完成职工管理系统
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019639 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved