欧美色欧美亚洲高清在线观看,国产特黄特色a级在线视频,国产一区视频一区欧美,亚洲成a 人在线观看中文

  1. <ul id="fwlom"></ul>

    <object id="fwlom"></object>

    <span id="fwlom"></span><dfn id="fwlom"></dfn>

      <object id="fwlom"></object>

      C語言課程設(shè)計 職工信息管理系統(tǒng) 單鏈表實現(xiàn)程序源代碼

      時間:2019-05-14 01:16:57下載本文作者:會員上傳
      簡介:寫寫幫文庫小編為你整理了多篇相關(guān)的《C語言課程設(shè)計 職工信息管理系統(tǒng) 單鏈表實現(xiàn)程序源代碼》,但愿對你工作學(xué)習(xí)有幫助,當(dāng)然你在寫寫幫文庫還可以找到更多《C語言課程設(shè)計 職工信息管理系統(tǒng) 單鏈表實現(xiàn)程序源代碼》。

      第一篇:C語言課程設(shè)計 職工信息管理系統(tǒng) 單鏈表實現(xiàn)程序源代碼

      //C語言課程設(shè)計 職工信息管理系統(tǒng)—單鏈表實現(xiàn) #include “stdio.h” #include “stdlib.h” #include “string.h”

      int saveflag=0;/*是否需要存盤的標(biāo)志變量*/

      struct employee { char name[15];char num[10];/* 工號 */ char sex[4];char bm[15];char zc[20];int gz;

      };

      typedef struct node { struct employee data;struct node *next;}Node,*Link;

      //Link l(注意是:字母l不是數(shù)字1)void add(Link l);void disp(Link l);//查看職工所有信息 void del(Link l);//刪除功能

      Node* Locate(Link l,char findmess[],char nameornum[]);

      void Qur(Link l);//查詢功能 void Tongji(Link l);//統(tǒng)計 void Sort(Link l);//排序 void Modify(Link l);//修改功能

      void save(Link l);//將單鏈表l中的數(shù)據(jù)寫入文件

      void printe(Node *p);//本函數(shù)用于打印鏈表中某個節(jié)點的數(shù)據(jù)內(nèi)容 */

      //以下4個函數(shù)用于輸出中文標(biāo)題 void printstart();void Wrong();void Nofind();void printc();

      void menu(){ printf(“t*****************************************************************n”);printf(“t* *n”);printf(“t*

      職工信息管理系統(tǒng)_結(jié)構(gòu)體數(shù)組實現(xiàn) *n”);printf(“t* *n”);printf(“t* [1] 增加職工信息 [2] 刪除職工信息 *n”);printf(“t* [3] 查詢職工信息 [4] 修改職工信息 *n”);printf(“t* [5] 插入職工記錄 [6] 統(tǒng)計職工記錄 *n”);printf(“t* [7] 排序 [8] 保存職工信息 *n”);printf(“t* [9] 顯示數(shù)據(jù) [0] 退出系統(tǒng) *n”);printf(“t* *n”);printf(“t*****************************************************************n”);} //void menu菜單結(jié)束

      void Disp(Link l)//顯示單鏈表l中存儲的職工記錄,內(nèi)容為employee結(jié)構(gòu)中定義的內(nèi)容 { int count=0;Node *p;p=l->next;// l存儲的是單鏈表中頭結(jié)點的指針,該頭結(jié)點沒有存儲職工信息,指針域指向的后繼結(jié)點才有職工信息

      if(!p)/*p==NULL,NUll在stdlib中定義為0*/ {

      printf(“n=====>提示:沒有職工記錄可以顯示!n”);

      return;}

      printf(“tttt顯示結(jié)果n”);printstart();//打印橫線

      printc();//打印各學(xué)科標(biāo)題

      printf(“n”);

      while(p)//逐條輸出鏈表中存儲的職工信息

      {

      printe(p);

      p=p->next;} printstart();printf(“n”);} //void Disp結(jié)束

      void printstart(){ printf(“---------n”);}

      void Wrong(){ printf(“n=====>提示:輸入錯誤!n”);}

      void Nofind(){ printf(“n=====>提示:沒有找到該職工!n”);}

      void printc()/* 本函數(shù)用于輸出中文 */ { printf(“ 工號t 姓名 性別 部門 職稱 工資 總工資平均工資n”);}

      void printe(Node *p)/* 本函數(shù)用于打印鏈表中某個節(jié)點的數(shù)據(jù)內(nèi)容 */ { printf(“%-12s%st%st%dt%dt%dt %dt %dn”,p->data.num,p->data.name,p->data.sex,p->data.bm,p->data.zc,p->data.gz);}

      //Locate(l,findmess,“num”);/* 該函數(shù)用于定位連表中符合要求的結(jié)點,并返回該指針 */ Node* Locate(Link l,char findmess[],char zcornum[]){ Node *r;if(strcmp(zcornum,“num”)==0)/* 按工號查詢 */ {

      r=l->next;

      while(r!=NULL)

      {

      if(strcmp(r->data.num,findmess)==0)/*若找到findmess值的工號*/

      return r;

      r=r->next;

      } } else if(strcmp(zcornum,“zc”)==0)/* 按職稱查詢 */ {

      r=l->next;

      while(r!=NULL)

      {

      if(strcmp(r->data.zc,findmess)==0)/*若找到findmess值的職工職稱*/

      return r;

      r=r->next;

      } } return 0;/*若未找到,返回一個空指針*/ }

      //add()函數(shù)中,無節(jié)點時,r指向list頭,有節(jié)點時,r指向末尾節(jié)點 void Add(Link l)/* 增加職工 */ { Node *p,*r,*s;/*實現(xiàn)添加操作的臨時的結(jié)構(gòu)體指針變量*/ char num[10];int flag=0;r=l;s=l->next;//鏈表沒有節(jié)點時,s=null;/鏈表有節(jié)點時,指向第一個職工節(jié)點

      while(r->next!=NULL)//如果存在后繼結(jié)點時,r指針后移一個

      r=r->next;/*將指針移至于鏈表最末尾,準(zhǔn)備添加記錄*/

      while(1){

      printf(“請你輸入工號(以'0'返回上一級菜單:)”);

      scanf(“%s”,num);

      if(strcmp(num,“0”)==0)//輸入'0',跳出while(1),即跳出add()函數(shù)

      break;

      s=l->next;//作用? 每次從第一個節(jié)點開始找,看num是否重復(fù)。

      while(s)//工號重復(fù)時,返回主菜單

      {

      if(strcmp(s->data.num,num)==0)

      {

      printf(“=====>提示:工號為'%s'的職工已經(jīng)存在,若要修改請你選擇'4 修改'!n”,num);

      flag=1;//break;

      return;

      }

      s=s->next;

      } //while(s)

      p=(Node *)malloc(sizeof(Node));//生成沒賦值的新節(jié)點 p

      strcpy(p->data.num,num);

      printf(“請你輸入姓名:”);

      scanf(“%s”,p->data.name);

      getchar();

      printf(“請你輸入性別:”);

      scanf(“%s”,p->data.sex);

      getchar();

      printf(“請你輸入職工所在部門:”);

      scanf(“%d”,&p->data.bm);

      getchar();

      printf(“請你輸入職工職稱:”);

      scanf(“%d”,&p->data.zc);

      getchar();

      printf(“請你輸入職工工資:”);

      scanf(“%d”,&p->data.gz);

      getchar();

      /* 信息輸入已經(jīng)完成 */

      p->next=NULL;/*表明這是鏈表的尾部結(jié)點*/

      r->next=p;/*將新建的結(jié)點加入鏈表尾部中*/

      r=p;

      saveflag=1;} //while(1)} //void Add增加結(jié)束

      void Del(Link l)/* 刪除 */ { int sel;Node *p,*r;/*實現(xiàn)刪除操作的臨時的結(jié)構(gòu)體指針變量*/ char findmess[20];

      if(!l->next)//當(dāng)list無后繼結(jié)點時,提示和結(jié)束返回del(){

      printf(“n=====>提示:沒有記錄可以刪除!n”);

      return;}

      printf(“n=====>1按工號刪除n=====>2按姓名刪除n”);scanf(“%d”,&sel);if(sel==1)//按工號刪除

      {

      printf(“請你輸入要刪除的工號:”);

      scanf(“%s”,findmess);

      p=Locate(l,findmess,“num”);

      if(p)

      {

      r=l;

      while(r->next!=p)

      r=r->next;//從第一個結(jié)點找起,直到發(fā)現(xiàn)r->next=p, 刪除結(jié)點,跳出循環(huán)

      r->next=p->next;//r r->next(p)p->next

      free(p);

      printf(“n=====>提示:該職工已經(jīng)成功刪除!n”);

      saveflag=1;

      }

      else

      Nofind();//顯示一句話

      } //if(sel==1)else if(sel==2)//按姓名刪除

      {

      是待

      printf(“請你輸入要刪除的姓名:”);

      scanf(“%s”,findmess);

      p=Locate(l,findmess,“name”);

      if(p)

      {

      r=l;

      while(r->next!=p)

      r=r->next;

      r->next=p->next;//r r->next(p)p->next

      free(p);

      printf(“n=====>提示:該職工已經(jīng)成功刪除!n”);

      saveflag=1;

      }

      else

      Nofind();} //if(sel==2)else

      Wrong();//顯示輸入錯誤的話 } //void Del刪除結(jié)束

      void Qur(Link l)//查詢功能 { int sel;char findmess[20];Node *p;//實現(xiàn)查詢操作的臨時的結(jié)構(gòu)體指針變量

      if(!l->next){

      printf(“n=====>提示:沒有資料可以查詢!n”);

      return;}

      printf(“n=====>1按工號查找n=====>2按職稱查找n”);scanf(“%d”,&sel);

      if(sel==1)/* 工號 */ {

      printf(“請你輸入要查找的工號:”);

      scanf(“%s”,findmess);

      p=Locate(l,findmess,“num”);

      if(p)

      {

      printf(“tttt查找結(jié)果n”);

      printstart();//打印橫線

      printc();//打印各學(xué)科標(biāo)題

      printe(p);//打印p結(jié)點各個數(shù)據(jù)成員的值

      printstart();//打印橫線

      }

      else

      Nofind();} //if(sel==1)

      else if(sel==2)/* 職稱 */ {

      printf(“請你輸入要查找的職稱:”);

      scanf(“%s”,findmess);

      p=Locate(l,findmess,“zc”);

      if(p)

      {

      printf(“tttt查找結(jié)果n”);

      printstart();

      printc();

      printe(p);

      printstart();

      }

      else

      Nofind();} else

      Wrong();} //void Qur查詢結(jié)束

      void Modify(Link l)//修改功能 { Node *p;char findmess[20];if(!l->next){

      printf(“n=====>提示:沒有資料可以修改!n”);

      return;}

      printf(“請你輸入要修改的職工工號:”);scanf(“%s”,findmess);p=Locate(l,findmess,“num”);

      if(p){

      printf(“請你輸入新工號(原來是%s):”,p->data.num);

      scanf(“%s”,p->data.num);

      printf(“請你輸入新姓名(原來是%s):”,p->data.name);

      scanf(“%s”,p->data.name);

      getchar();

      printf(“請你輸入新性別(原來是%s):”,p->data.sex);

      scanf(“%s”,p->data.sex);

      getchar();

      printf(“請你輸入新的部門(原來是%s):”,p->data.bm);

      scanf(“%d”,&p->data.bm);

      printf(“請你輸入新的職稱(原來是%s):”,p->data.zc);

      scanf(“%d”,&p->data.zc);

      getchar();

      printf(“請你輸入新的工資(原來是%d):”,p->data.gz);

      scanf(“%d”,&p->data.gz);

      printf(“n=====>提示:資料修改成功!n”);

      //shoudsave=1;} else

      Nofind();//if(p)結(jié)束

      } //void Modify(Link l)//修改功能結(jié)束

      //插入記錄:按工號查詢到要插入的節(jié)點的位置,然后在該工號之后插入一個新節(jié)點。

      void Insert(Link l){ Node *s,*r,*p;/*p指向插入位置,p指新插入記錄節(jié)點*/ char ch,new_num[10],old_num[10];//old_num[]保存插入點位置之前的工號,new_num[]保存輸入的新記錄的工號

      int flag=0;s=l->next;system(“cls”);Disp(l);

      while(1){

      //stringinput(s,10,“please input insert location after the Number:”);

      printf(“請你輸入已存在的工號(以'0'返回上一級菜單:)”);

      scanf(“%s”,old_num);

      if(strcmp(old_num,“0”)==0)//輸入'0',跳出while(1),即跳出Insert()函數(shù)

      return;

      s=l->next;//作用? 每次從第一個節(jié)點開始找

      flag=0;

      while(s)/*查詢該工號是否存在,flag=1表示該工號存在*/

      {

      if(strcmp(s->data.num,old_num)==0)

      {

      flag=1;

      break;

      }

      s=s->next;

      }

      if(flag==1)

      break;/*若工號存在,則進(jìn)行插入之前的新記錄的輸入操作*/

      else

      {

      getchar();

      printf(“n=====>The number %s is not existing,try again?(y/n):”,old_num);

      scanf(“%c”,&ch);

      if(ch=='y'||ch=='Y')

      {continue;}

      else

      {return;} //回主菜單

      }

      }//while(1)/*以下新記錄的插入新節(jié)點,工號不能跟已存在的工號相同,操作與Add()相同*/

      printf(“請你輸入待插入的工號(以'0'返回上一級菜單:)”);scanf(“%s”,new_num);if(strcmp(new_num,“0”)==0)//輸入'0',跳出while(1),即跳出add()函數(shù)

      return;s=l->next;//作用? 每次從第一個節(jié)點開始找,看num是否重復(fù)。

      while(s)//工號重復(fù)時,返回主菜單

      {

      if(strcmp(s->data.num,new_num)==0)

      {

      printf(“=====>提示:工號為'%s'的職工已經(jīng)存在'!n”,new_num);

      flag=1;

      return;

      }

      s=s->next;} //while(s)

      p=(Node *)malloc(sizeof(Node));if(!p){

      printf(“n allocate memory failure ”);/*如沒有申請到,打印提示信息*/

      return;/*返回主界面*/ }

      strcpy(p->data.num,new_num);printf(“請你輸入姓名:”);scanf(“%s”,p->data.name);getchar();printf(“請你輸入性別:”);scanf(“%s”,p->data.sex);getchar();printf(“請你輸入部門:”);scanf(“%d”,&p->data.bm);getchar();printf(“請你輸入職稱:”);scanf(“%d”,&p->data.zc);getchar();printf(“請你輸入工資:”);scanf(“%d”,&p->data.gz);getchar();// 信息輸入已經(jīng)完成

      p->next=NULL;/*表明這是鏈表的尾部結(jié)點*/

      saveflag=1;/*在main()有對該全局變量的判斷,若為1,則進(jìn)行存盤操作*/ /*將指針賦值給r,因為l中的頭節(jié)點的下一個節(jié)點才實際保存著學(xué)生的記錄*/

      r=l->next;while(1){

      if(strcmp(r->data.num,old_num)==0)/*在鏈表中插入一個節(jié)點*/

      {

      p->next=r->next;

      r->next=p;

      break;

      }

      r=r->next;}// while(1),r作為查詢指針,依次從第一個節(jié)點找起,找到后 跳出 while(1)循環(huán)

      Disp(l);printf(“nn”);// getchar();

      }

      void Tongji(Link l)//統(tǒng)計 { Node *max,*min;/*用于指向工資最高的節(jié)點*/ Node *t=l->next;if(!t){

      system(“cls”);

      printf(“n=====>Not employee record!n”);

      getchar();

      return;} system(“cls”);Disp(l);max=min=t;while(t){

      if(t->data.gz>=max->data.gz)max=t;

      if(t->data.gz<=min->data.gz)min=t;

      t=t->next;

      printf(“最高工資為:%dn”,max);

      printf(“t%st%st%st%st%st%dnn”,t->data.num,t->data.name,t->data.sex,t->data.bm,t->data.zc,t->data.gz);printf(“最低工資為:%dn”,min);

      printf(“t%st%st%st%st%st%dnn”,t->data.num,t->data.name,t->data.sex,t->data.bm,t->data.zc,t->data.gz);} }

      void Sort(Link l)//排序 { Link ll;Node *p,*rr,*s;int i=0;if(l->next==NULL){ system(“cls”);printf(“n=====>Not employee record!n”);getchar();return;} ll=(Node*)malloc(sizeof(Node));/*用于創(chuàng)建新的節(jié)點*/ if(!ll){

      printf(“n allocate memory failure ”);/*如沒有申請到,打印提示信息*/

      return;/*返回主界面*/ } ll->next=NULL;system(“cls”);Disp(l);/*顯示排序前的所有職工記錄*/ p=l->next;while(p)/*p!=NULL*/ {

      s=(Node*)malloc(sizeof(Node));/*新建節(jié)點用于保存從原鏈表中取出的節(jié)點信息*/

      if(!s)/*s==NULL*/

      {

      printf(“n allocate memory failure ”);/*如沒有申請到,打印提示信息*/

      return;/*返回主界面*/

      }

      s->data=p->data;/*填數(shù)據(jù)域*/

      s->next=NULL;/*指針域為空*/

      rr=ll;

      /*rr鏈表于存儲插入單個節(jié)點后保持排序的鏈表,ll是這個鏈表的頭指針,每次從頭開始查找插入位置*/

      while(rr->next!=NULL && rr->next->data.gz>=p->data.gz)

      {rr=rr->next;} /*指針移至總分比p所指的節(jié)點的總分小的節(jié)點位置*/

      if(rr->next==NULL)/*若新鏈表ll中的所有節(jié)點的總分值都比p->data.gz大時,就將p所指節(jié)點加入鏈表尾部*/

      rr->next=s;

      else /*否則將該節(jié)點插入至第一個總分字段比它小的節(jié)點的前面*/

      {

      s->next=rr->next;

      rr->next=s;

      }

      p=p->next;/*原鏈表中的指針下移一個節(jié)點*/ }

      l->next=ll->next;/*ll中存儲是的已排序的鏈表的頭指針*/

      Disp(l);saveflag=1;printf(“n =====>sort complete!n”);}

      void Save(Link l){ FILE* fp;Node *p;//實現(xiàn)保存操作的臨時的結(jié)構(gòu)體指針變量

      int flag=1,count=0;

      fp=fopen(“employee.txt”,“wb”);if(fp==NULL){

      printf(“n=====>提示:重新打開文件時發(fā)生錯誤!n”);

      return;}

      p=l->next;//p指向第一個記錄結(jié)點

      while(p){

      if(fwrite(p,sizeof(Node),1,fp)==1)//將第一個記錄結(jié)點值寫入文件

      {

      p=p->next;//依次寫入第二個結(jié)點的值,count++;//文件的記錄數(shù)+1

      }

      else

      {

      flag=0;

      break;

      } } //while(p)

      if(count>0){

      printf(“n=====>提示:文件保存成功.(有%d條記錄已經(jīng)保存.)n”,count);

      saveflag=0;} else {

      system(“cls”);

      printf(“保存文件失敗,'0'條記錄被保存!n”);} fclose(fp);} // void Save結(jié)束

      void main(){ Link list;/*定義鏈表*/ // struct node *list;FILE *fp;/* 文件指針 */ int choose;/*保存選擇結(jié)果變量*/ char ch;/*保存(y,Y,n,N)*/

      int count=0;/*保存文件中的記錄條數(shù)(或結(jié)點個數(shù))*/ struct node *p,*r;/*定義記錄指針變量*/ printf(“tttt職工信息管理系統(tǒng)nttttn”);

      list=(struct node*)malloc(sizeof(struct node));

      if(!list){

      printf(“n allocate memory failure ”);/*如沒有申請到,打印提示信息*/

      return;/*返回主界面*/ }

      list->next=NULL;r=list;

      fp=fopen(“employee.txt”,“rb”);if(fp==NULL){

      printf(“n=====>提示:文件還不存在,是否創(chuàng)建?(y/n)n”);

      scanf(“%c”,&ch);

      if(ch=='y'||ch=='Y')

      fp=fopen(“employee.txt”,“ab+”);

      else

      exit(0);} // if(fp==NULL)

      printf(“n=====>提示:文件已經(jīng)打開,正在導(dǎo)入記錄......n”);

      while(!feof(fp))//沒有到文件尾時,循環(huán)

      {

      p=(struct node*)malloc(sizeof(struct node));

      if(!p)

      {

      printf(“ memory malloc failure!n”);/*沒有申請成功*/

      exit(0);/*退出*/

      }

      if(fread(p,sizeof(struct node),1,fp))/* 讀文件的已有內(nèi)容放入結(jié)點中 */

      {

      p->next=NULL;

      r->next=p;

      r=p;/* 將該結(jié)點掛入鏈表中, r指向最后的節(jié)點 */

      count++;

      } } //while(!feof(fp))

      fclose(fp);/* 關(guān)閉文件 */ printf(“n=====>提示:記錄導(dǎo)入完畢,共導(dǎo)入%d條記錄.n”,count);

      while(1){

      menu();

      printf(“tt====>請選擇:”);

      scanf(“%d”,&choose);

      if(choose==0)

      {

      if(saveflag==1)

      {

      getchar();

      printf(“n=====>提示:資料已經(jīng)改動,是否將改動保存到文件中(y/n)?n”);

      scanf(“%c”,&ch);

      if(ch=='y'||ch=='Y')

      Save(list);

      } //if

      printf(“n=====>提示:你已經(jīng)退出系統(tǒng),再見!n”);

      break;

      }//if

      switch(choose)

      {

      case 1:Add(list);

      break;/* 增加職工記錄 */

      case 2:

      Del(list);

      break;/* 刪除職工記錄 */

      case 3:

      Qur(list);

      break;/* 查詢職工記錄 */

      case 4:

      Modify(list);

      break;/* 修改職工記錄 */

      case 5:

      Insert(list);

      break;/*插入職工記錄*/

      case 6:

      Tongji(list);

      break;/*統(tǒng)計職工記錄*/

      case 7:

      Sort(list);

      break;/*排序職工記錄*/

      case 8:

      Save(list);

      break;/* 保存職工記錄 */

      case 9:

      system(“cls”);

      Disp(list);

      break;/*顯示職工記錄*/

      default:

      Wrong();

      getchar();

      break;

      } //switch(choose)}//while(1)} //main()/* */

      第二篇:職工信息管理系統(tǒng) 單鏈表實現(xiàn) C語言源程序(范文)

      #include #include #include int saveflag=0;

      /* 單鏈表內(nèi)容有無發(fā)生改變,是否需要存盤的標(biāo)志變量 */ struct employee {

      };

      typedef struct Node {

      void InitList(LinkList *head)

      /*將單鏈表初始化為空。動態(tài)生成一個頭結(jié)點,并將頭結(jié)點的指針域置為空*/ {

      }

      ListNode *Locatenum(LinkList head,char find[])

      //通過職工工號查找,返回定位指針。{ LinkList p;if((*head=(LinkList)malloc(sizeof(ListNode)))==NULL)

      /*為頭結(jié)點分配一 printf(“系統(tǒng)分配存儲空間失??!n”);個存儲空間*/ exit(-1);(*head)->next=NULL;

      /*將頭結(jié)點的指針域置為空*/ struct employee data;struct Node *next;char num[10];

      /* 工號 */ char name[15];

      /* 姓名 */ char sex[7];

      /* 性別 */ int age;

      /* 年齡 */ char education[15];

      /* 學(xué)歷 */ int salary;

      /* 工資 */ char phone[20];

      /* 電話號碼 */ char address[30];

      /* 住址 */ }ListNode,*LinkList;

      } p=head->next;if(!p)

      //如果職工信息記錄為空,返回NULL。

      {

      } return NULL;if(strcmp(p->data.num,find)==0)return p;p=p->next;return NULL;while(p)ListNode *Locatename(LinkList head,char find[])

      //通過職工姓名查找,返回定位指針。{

      }

      ListNode *Locatesalary(LinkList head,int salary)

      //通過職工工資查找,返回定位指針。{

      LinkList p;p=head->next;if(!p)

      //如果職工信息記錄為空,返回NULL。

      return NULL;while(p){ LinkList p;p=head->next;if(!p)

      //如果職工信息記錄為空,返回NULL。

      {

      } return NULL;if(strcmp(p->data.name,find)==0)return p;p=p->next;return NULL;while(p)

      }

      } if(p->data.salary==salary)return p;p=p->next;return NULL;void Nofind(){ }

      void Modify(LinkList L)

      //修改功能。{

      ListNode *p;

      char find[20];

      if(!L->next)

      {

      printf(“請你輸入要修改的職工工號:”);

      scanf(“%s”,find);

      p=Locatenum(L,find);

      if(p)

      {

      printf(“請你輸入新的工號(原來是%s):”,p->data.num);

      scanf(“%s”,p->data.num);

      getchar();

      printf(“n”);

      printf(“請你輸入新的姓名(原來是%s):”,p->data.name);

      scanf(“%s”,p->data.name);

      getchar();

      printf(“n”);

      printf(“n***提示***:沒有資料可以修改!n”);

      return;printf(“n***提示***:沒有找到該職工!n”);

      }

      printf(“請你輸入新的性別(原來是%s):”,p->data.sex);

      scanf(“%s”,p->data.sex);

      getchar();

      printf(“n”);

      printf(“請你輸入新的年齡(原來是%d):”,p->data.age);

      scanf(“%d”,&p->data.age);

      printf(“n”);

      printf(“請你輸入新的學(xué)歷(原來是%s):”,p->data.education);

      scanf(“%s”,p->data.education);

      getchar();

      printf(“n”);

      printf(“請你輸入新的工資(原來是%d):”,p->data.salary);

      scanf(“%d”,&p->data.salary);

      printf(“n”);

      printf(“請你輸入新的電話(原來是%s):”,p->data.phone);

      scanf(“%s”,p->data.phone);

      getchar();

      printf(“n”);

      printf(“請你輸入新的住址(原來是%s):”,p->data.address);

      scanf(“%s”,p->data.address);

      getchar();

      printf(“n”);

      printf(“n***提示***:資料修改成功!n”);

      saveflag=1;

      }

      else

      Nofind();//if(p)結(jié)束

      } //void Modify(LinkList L)

      //修改功能結(jié)束 void Add(LinkList head)

      /* 錄入職工信息 */ {

      system(“cls”);ListNode *p,*r,*s;

      /* 實現(xiàn)添加操作的臨時的結(jié)構(gòu)體指針變量 */ int sign;

      /* 標(biāo)記重復(fù)工號的變量 */ char num[10];r=head;s=head->next;

      /* 鏈表沒有節(jié)點時,s=NULL;鏈表有節(jié)點時,指向while(r->next!=NULL)/* 如果存在后繼結(jié)點時,r指針后移一個 */ r=r->next;

      /* 將指針移至于鏈表最末尾,準(zhǔn)備添加記錄 */ printf(“輸入‘#’將退出職工信息錄入,退回至主菜單!nn”);while(1){

      printf(“(PS:職工號為‘#’即退出錄入功能)nn”);printf(“請輸入職工號:”);fflush(stdin);

      //清除緩沖區(qū)。gets(num);if(strcmp(num,“#”)==0)/* 輸入‘0’,跳出while(1),即跳出Add()函數(shù) */ break;s=head->next;

      /* 每次從第一個節(jié)點開始找,看num是否重

      while(s){

      if(strcmp(s->data.num,num)==0){

      } s=s->next;printf(“***提示***n工號為:‘%s’的職工信息已經(jīng)存在!printf(”若要修改請按‘4’,放棄請按‘0’!n“);scanf(”%d“,&sign);if(sign==4)

      Modify(head);return;else 第一個職工節(jié)點 */ 復(fù)。*/ n”,num);}//while(s)if((p=(LinkList)malloc(sizeof(ListNode)))==NULL)//生成沒賦值的新節(jié)點 p。

      {

      } strcpy(p->data.num,num);printf(“n”);printf(“請輸入該職工姓名:”);scanf(“%s”,p->data.name);getchar();printf(“n”);printf(“請輸入該職工的性別:(注:男性:male;女性:female)”);scanf(“%s”,p->data.sex);getchar();printf(“n”);printf(“請輸入該職工的年齡:”);scanf(“%d”,&p->data.age);printf(“n”);printf(“請輸入該職工的學(xué)歷:”);scanf(“%s”,p->data.education);getchar();printf(“n”);printf(“請輸入該職工的工資:”);scanf(“%d”,&p->data.salary);printf(“n”);printf(“請輸入該職工的電話號碼:”);scanf(“%s”,p->data.phone);getchar();printf(“n”);printf(“請輸入該職工的住址:”);gets(p->data.address);printf(“n”);p->next=NULL;

      /* 表明這是鏈表的尾部結(jié)點 */ r->next=p;

      /* 將新建的結(jié)點加入鏈表尾部中 */ r=p;saveflag=1;printf(“n”);printf(“系統(tǒng)分配存儲空間失敗!n”);printf(“退出程序!n”);exit(-1);}//while(1)}//void Add函數(shù)結(jié)束。

      void printline()

      //打印橫線。{ }

      void printsubject()

      //打印各分類標(biāo)題。{ }

      void printLinkList(LinkList p)

      //打印p結(jié)點各個數(shù)據(jù)成員的值。{ printf(“ %s

      %s %s

      %d %s %d

      %s

      %sn”,p->data.num,p->data.name,p->data.sex,p->data.age,p->data.education,p->data.salary,p->data.phone,p->data.address);}

      void Allemployeeinfo(LinkList head)//顯示所有職工信息。{

      int count=0;ListNode *p;p=head->next;if(!p){

      } printf(“tttt顯示結(jié)果n”);printline();printsubject();printf(“n”);while(p)printf(“***提示***:目前沒有存儲任何職工記錄!n”);printf(“返回主菜單,請重新選擇功能!n”);return;printf(“ 工 號t 姓 名

      性 別

      年 齡

      學(xué) 歷

      工 資

      電 話tt 住 址n”);printf(“------------------n”);

      } {

      } printline();printf(“n”);printf(“已經(jīng)存儲了%d條職工信息!n”,count);printLinkList(p);p=p->next;count++;void Wrong(){ }

      void menu()

      //主菜單。{

      printf(“n”);printf(“t**********************************************************printf(”t*

      printf(“t*

      printf(”t*

      < 職工信息管理系統(tǒng)_單鏈表實現(xiàn) >

      printf(“t*

      printf(”t*

      [1]

      錄入職工信息

      [2]

      刪除職工信息

      printf(“t*

      [3]

      查詢職工信息

      [4]

      修改職工信息

      printf(”t*

      [5]

      插入職工記錄

      [6]

      統(tǒng)計職工信息

      printf(“t*

      [7]

      排序

      [8]

      保存職工信息

      printf(”t*

      [9]

      顯示所有職工記錄

      [0]

      退出系統(tǒng)

      printf(“n***提示***:輸入錯誤!n”);*********n“);*n”);*n“);*n”);*n“);*n”);*n“);*n”);*n“);*n”);

      printf(“t*

      printf(”t*

      printf(“t*

      版權(quán)所有人:printf(”t*

      電子132班

      printf(“t*

      printf(”t***********************************************************n“);*n”);彭林

      *n“);*n”);1319200063

      *n“);*********n”);} //void menu菜單結(jié)束。

      void Del(LinkList L)//刪除職工信息。{

      int select;

      //刪除方式選擇記錄變量。ListNode *p,*r;char find[20];if(!L->next)

      //當(dāng)list無后繼結(jié)點時,提示和結(jié)束Del()函數(shù)。{

      }

      printf(“n按工號刪除,請按‘1’n按姓名刪除,請按‘2’n”);printf(“n=====>功能選擇:”);scanf(“%d”,&select);if(select==1){

      printf(“請輸入要刪除的職工工號:”);scanf(“%s”,find);getchar();p=Locatenum(L,find);if(p){ r=L;printf(“n***提示***:沒有記錄可以刪除!n”);return;

      } while(r->next!=p)r=r->next;//從第一個結(jié)點找起,直到發(fā)現(xiàn)r->next=p, 是待刪除結(jié)點,跳出循環(huán)。

      r->next=p->next;free(p);printf(“n***提示***:該職工信息已成功刪除!n”);saveflag=1;else Nofind();}//if(select==1).else if(select==2){

      printf(“請輸入要刪除的職工姓名:”);scanf(“%s”,find);getchar();p=Locatename(L,find);if(p){

      } else Nofind();r=L;while(r->next!=p)r=r->next;r->next=p->next;free(p);printf(“n***提示***:該職工信息已成功刪除!n”);saveflag=1;}//if(select==2).else Wrong();

      //顯示輸入錯誤的話

      }//void Del()刪除函數(shù)結(jié)束。

      void Search(LinkList L)

      //查詢職工信息。{ int select;

      int salary;int sign=0;char find[20];ListNode *p;

      //實現(xiàn)查詢操作的臨時結(jié)構(gòu)體指針變量。if(!L->next){

      } printf(“n按工號查找,請按‘1’n按工資查找,請按‘2’n按姓名查找,printf(”n=====>功能選擇:“);scanf(”%d“,&select);printf(”n“);if(select==1)

      //工號。{

      } else if(select==2)

      //工資。{

      printf(”請輸入要查找的工資:“);scanf(”%d“,&salary);p=Locatesalary(L,salary);printf(”請輸入要查找的工號:“);scanf(”%s“,find);getchar();p=Locatenum(L,find);if(p){

      } else Nofind();printf(”tttt

      查找結(jié)果n“);printline();

      //打印橫線。printsubject();

      //打印各分類標(biāo)題。

      printLinkList(p);

      //打印p結(jié)點各個數(shù)據(jù)成員的值。printline();

      //打印橫線。printf(”n***提示***:沒有職工信息資料可以查詢!n“);printf(”返回主菜單,請重新選擇功能!n“);return;請按‘3’n”);

      } if(p){

      } while(p){

      {

      } } if(sign==0)Nofind();printf(“tttt查找結(jié)果n”);printline();printsubject();printLinkList(p);printline();sign++;p=Locatesalary(p,salary);if(p)printf(“tttt查找結(jié)果n”);printline();printsubject();printLinkList(p);printline();sign++;else if(select==3)

      //姓名。{

      printf(“請輸入要查找的姓名:”);scanf(“%s”,find);getchar();p=Locatename(L,find);if(p){

      printf(“tttt查找結(jié)果n”);printline();printsubject();printLinkList(p);

      } } printline();else Nofind();else Wrong();}//void Search()查詢函數(shù)結(jié)束。

      void Save(LinkList L)

      //信息保存到文件中。{

      FILE *fp;ListNode *p;int count=0;int flag=1;fp=fopen(“Employeeinfo.txt”,“wb”);if(fp==NULL){

      } p=L->next;while(p){

      if(fwrite(p,sizeof(ListNode),1,fp)==1)

      //將第一個記錄結(jié)點值寫入文

      {

      p=p->next;

      //依次寫入下一個結(jié)點的 count++;

      //文件的記錄數(shù)+1。printf(“n***提示***:打開文件時發(fā)生錯誤!n”);return;件。

      值。

      }

      else

      {

      flag=0;

      printf(“寫入文件過程發(fā)生錯誤!n”);

      break;

      }

      }//while(p).if(count>0){

      } else {

      } fclose(fp);system(“cls”);//清屏。

      printf(“文件保存失敗!‘0’條記錄被保存。n”);printf(“n***提示***:文件保存成功。(有%d條記錄已經(jīng)保存。)n”,count);saveflag=0;

      }//void Save()函數(shù)結(jié)束。

      void Sort(LinkList L)

      //排序功能函數(shù)。{

      ListNode *p,*m,*n;int i,j,count=0;p=L->next;if(!p){

      } system(“cls”);

      //清屏。printf(“按工資從低到高排序:n”);printf(“***以下為排序前的所有職工記錄***n”);Allemployeeinfo(L);while(p){

      } for(i=0;i

      //不包含頭結(jié)點的職工信息結(jié)點的總個數(shù)。p=p->next;system(“cls”);

      //清屏。printf(“無任何職工信息!n”);printf(“返回主菜單!n”);return;

      }

      {

      } printf(“***以下為排序后的所有職工記錄***n”);Allemployeeinfo(L);saveflag=1;printf(“排序成功!n”);n=L;p=L->next;m=p->next;while(m){

      } if(p->data.salary>m->data.salary){

      } else {

      } n=p;p=m;m=m->next;n->next=p->next;p->next=m->next;m->next=p;n=m;m=p->next;void Statistics(LinkList L)//統(tǒng)計職工中的最高工資和最低工資。{

      ListNode *Max,*Min;int i;ListNode *t=L->next;if(!t){ system(“cls”);

      //清屏。printf(“沒有儲存任何職工記錄!n”);

      }

      } printf(“返回主菜單,請先錄入職工信息!n”);return;system(“cls”);Max=Min=t;t=t->next;while(t){

      } printf(“最高工資為:%dn”,Max->data.salary);printf(“最低工資為:%dn”,Min->data.salary);printf(“若要查看最低,最高工資的相關(guān)職工信息,n”);printf(“請按‘1’,然后按照提示進(jìn)行相關(guān)操作,n”);printf(“否則,請按‘1’除外的任何數(shù)字鍵以退出統(tǒng)計功能,返回主菜單。n”);printf(“n=====>功能選擇:”);scanf(“%d”,&i);if(i==1)Search(L);

      //顯示符合要求的職工信息。return;else if(Max->data.salarydata.salary)Max=t;

      //Max指針指向最高工資的職工結(jié)點。Min=t;

      //Min指針指向最低工資的職工結(jié)點。if(Min->data.salary>t->data.salary)t=t->next;void Insert(LinkList L)

      //插入新的職工信息。{

      printf(“本功能可以通過姓名和工號查找到符合要求的n”);//功能介紹。printf(“相關(guān)職工信息,然后將您希望添加進(jìn)去的新的n”);printf(“職工信息插入到該職工信息記錄的后面。n”);ListNode *p,*s;char find[20];

      //存放工號和姓名的變量。int i;printf(“通過姓名查找,請按‘1’。n”);printf(“通過工號查找,請按‘2’。n”);

      printf(“返回主菜單,請按‘3’。n”);printf(“n=====>功能選擇:”);scanf(“%d”,&i);printf(“n”);if(i==3){

      } else if(i==1){

      printf(“請輸入已在存儲記錄中的職工姓名:”);scanf(“%s”,find);getchar();p=Locatename(L,find);//定位。if(!p){

      } s=(LinkList)malloc(sizeof(ListNode));if(!s){

      } printf(“請輸入新職工工號:”);gets(s->data.num);printf(“n”);printf(“請輸入新職工姓名:”);scanf(“%s”,s->data.name);getchar();printf(“n”);printf(“請輸入新職工的性別:(注:男性:male;女性:female)”);scanf(“%s”,s->data.sex);printf(“系統(tǒng)分配存儲空間失?。”);system(“cls”);return;printf(“您輸入的該職工姓名不在信息記錄中,請重新核審!n”);printf(“返回主菜單。n”);return;system(“cls”);

      //退出插入功能,返回主菜單。return;

      } getchar();printf(“n”);printf(“請輸入新職工的年齡:”);scanf(“%d”,&s->data.age);printf(“n”);printf(“請輸入新職工的學(xué)歷:”);scanf(“%s”,s->data.education);getchar();printf(“n”);printf(“請輸入新職工的工資:”);scanf(“%d”,&s->data.salary);printf(“n”);printf(“請輸入新職工的電話號碼:”);scanf(“%s”,s->data.phone);getchar();printf(“n”);printf(“請輸入新職工的住址:”);scanf(“%s”,s->data.address);getchar();printf(“n”);s->next=p->next;p->next=s;printf(“姓名為:%s的新職工信息已成功插到姓名為:%s的職工信息記saveflag=1;

      //資料已改動的存儲變量。錄后面。n”,s->data.name,p->data.name);else if(i==2){

      printf(“請輸入已在存儲記錄中的職工工號:”);scanf(“%s”,find);getchar();p=Locatenum(L,find);//定位。if(!p){

      printf(“您輸入的該職工工號不在信息記錄中,請重新核審!n”);printf(“返回主菜單。n”);return;

      } s=(LinkList)malloc(sizeof(ListNode));if(!s){

      } printf(“請輸入新職工工號:”);gets(s->data.num);printf(“n”);printf(“請輸入新職工姓名:”);scanf(“%s”,s->data.name);getchar();printf(“n”);printf(“請輸入新職工的性別:(注:男性:male;女性:female)”);scanf(“%s”,s->data.sex);getchar();printf(“n”);printf(“請輸入新職工的年齡:”);scanf(“%d”,&s->data.age);printf(“n”);printf(“請輸入新職工的學(xué)歷:”);scanf(“%s”,s->data.education);getchar();printf(“n”);printf(“請輸入新職工的工資:”);scanf(“%d”,&s->data.salary);printf(“n”);printf(“請輸入新職工的電話號碼:”);scanf(“%s”,s->data.phone);getchar();printf(“n”);printf(“請輸入新職工的住址:”);scanf(“%s”,s->data.address);getchar();printf(“n”);printf(“系統(tǒng)分配存儲空間失?。”);system(“cls”);return;

      }

      } s->next=p->next;p->next=s;printf(“姓名為:%s的新職工信息已成功插到姓名為:%s的職工信息記saveflag=1;錄后面。n”,s->data.name,p->data.name);else {

      } printf(“功能選擇有誤!返回主菜單。n”);return;void main(){

      LinkList L;/*定義鏈表*/ // struct Node *list;

      FILE *fp;/* 文件指針 */

      int choose;/*保存選擇結(jié)果變量*/

      char ch;

      /*保存(y,Y,n,N)*/

      int count=0;/*保存文件中的記錄條數(shù)(或結(jié)點個數(shù))*/

      struct Node *p,*r;

      /*定義記錄指針變量*/

      printf(“tttt職工信息管理系統(tǒng)nttttn”);

      L=(struct Node*)malloc(sizeof(struct Node));

      if(!L)

      {

      printf(“n系統(tǒng)分配存儲空間失?。”);/*如沒有申請到,打印提示信

      return;

      /*返回菜單*/ 息*/

      }

      L->next=NULL;

      r=L;

      fp=fopen(“Employeeinfo.txt”,“rb”);

      if(fp==NULL)

      {

      printf(“n***提示***:存儲職工信息的文件還不存在,是否創(chuàng)建?

      scanf(”%c“,&ch);(y/n)n”);

      */

      if(ch=='y'||ch=='Y')

      {

      fp=fopen(“Employeeinfo.txt”,“ab+”);

      printf(“文件創(chuàng)建成功!n”);

      }

      else

      {

      printf(“文件沒有創(chuàng)建,無法寫入職工信息!nn”);

      printf(“<-----退 出 職 工 信 息 管 理 系 統(tǒng)----->n”);

      exit(0);

      }

      } // if(fp==NULL)

      printf(“n=====>提示:文件已經(jīng)打開,正在導(dǎo)入記錄......n”);

      while(!feof(fp))//沒有到文件尾時,循環(huán)

      {

      fclose(fp);/* 關(guān)閉文件 */

      printf(“n=====>提示:記錄導(dǎo)入完畢,共導(dǎo)入%d條記錄。n”,count);

      while(1)

      p=(struct Node*)malloc(sizeof(struct Node));

      if(!p)

      {

      if(fread(p,sizeof(struct Node),1,fp))/* 讀文件的已有內(nèi)容放入結(jié)點中

      {

      p->next=NULL;

      r->next=p;

      r=p;/* 將該結(jié)點掛入鏈表中, r指向最后的節(jié)點 */

      count++;

      printf(“ memory malloc failure!n”);

      /*沒有申請成功*/

      exit(0);

      /*退出*/

      }

      }

      } //while(!feof(fp))

      {

      menu();

      printf(“tt====>請選擇:”);

      scanf(“%d”,&choose);

      if(choose==0)

      {

      if(saveflag==1)

      {

      getchar();

      printf(“n=====>提示:資料已經(jīng)改動,是否將改動保存到文件

      scanf(”%c“,&ch);

      if(ch=='y'||ch=='Y')

      Save(L);中(y/n)?n”);

      } //if

      printf(“n***提示***:您已經(jīng)退出系統(tǒng),歡迎再次使用!~n”);

      break;

      }//if switch(choose){ case 1:Add(L);

      break;break;break;break;break;break;Sort(L);break;Save(L);case 2:Del(L);case 3:Search(L);case 4:Modify(L);case 5:Insert(L);case 6:Statistics(L);case 7: case 8:

      break;system(“cls”);Allemployeeinfo(L);break;case 9: default:

      } } } Wrong();break;

      第三篇:C語言課程設(shè)計 職工信息管理系統(tǒng) 結(jié)構(gòu)體數(shù)組實現(xiàn)程序源代碼

      //C語言課程設(shè)計 職工信息管理系統(tǒng)—結(jié)構(gòu)體數(shù)組實現(xiàn) #include #include #include

      struct employee { char num[10];char name[15];char sex[5];char bm[20];char zc[20];int gz;};

      int read_file(struct employee em[]);void menu();void write_file(struct employee em[]);void add();void select();//查看職工所有信息 void zc_query();//按職稱查詢 void num_del();//按工號刪除 void tongji();//統(tǒng)計 void sort();//排序

      void num_modify();//按工號修改職工信息 void save();//保存信息 void disp();//顯示職工信息

      void fh();//返回主菜單

      struct employee em[300];//這個數(shù)組用來保存所有的職工信息 和文件里面的一致

      int Number=0;//記錄總的職工人數(shù) 也就是數(shù)組/文件里面的職工人數(shù)

      void menu(){ printf(“t***********************************************************************n”);printf(“t* *n”);printf(“t*

      職工信息管理系統(tǒng)_結(jié)構(gòu)體數(shù)組實現(xiàn) *n”);printf(“t* *n”);printf(“t* [1] 增加職工信息 [2] 查看職工信息 *n”);printf(“t* [3] 查找職工信息 [4] 刪除職工信息 *n”);printf(“t* [5] 統(tǒng)計 [6] 職工工資排列 *n”);printf(“t* [7] 修改職工信息 [8] 保存職工信息 *n”);printf(“t* [9] 顯示職工信息 [0] 退出系統(tǒng) *n”);printf(“t* *n”);printf(“t***********************************************************************n”);} void main(){ int choose=0;FILE *fp=NULL;char yesorno;

      if((fp=fopen(“employee1.txt”,“rb+”))==NULL){ printf(“n=========>提示:文件不存在,是否要創(chuàng)建一個?(y/n)n”);scanf(“%c”,&yesorno);if(yesorno=='y'||yesorno=='Y'){

      //這里僅為了建立文件

      fp=fopen(“employee1.txt”,“wb+”);

      fclose(fp);//關(guān)閉fp所指的文件,釋放文件緩沖區(qū)

      } else

      exit(0);} else {

      Number=read_file(em);//要是文件已經(jīng)有數(shù)據(jù) 將數(shù)據(jù)初始化到數(shù)組中 } system(“cls”);while(1){ menu();printf(“tt====>請選擇:”);scanf(“%d”,&choose);system(“cls”);switch(choose){ case 0:

      exit(0);//退出

      break;

      case 1:

      add();

      fh();//增加職工信息 break;

      case 2:

      select();

      fh();//查看職工信息 break;

      case 3:

      zc_query();

      fh();// 查找

      break;

      case 4:

      num_del();

      fh();//刪除

      break;

      case 5:

      tongji();

      fh();//統(tǒng)計 break;case 6:

      sort();

      fh();//排序 break;case 7:

      num_modify();

      fh();//修改后返回 break;

      case 8:

      save();

      fh();//保存

      break;

      case 9:

      disp();

      fh();

      break;//顯示

      default:

      break;

      } fflush(stdin);getchar();system(“cls”);} } void save(){ printf(“t=====程序在運行時已自動保存.....n”);} void fh(){ printf(“t===>按Enter鍵返回主菜單n”);}

      void num_modify()//修改職工信息 { FILE *fp=NULL;char gh[60];int i=0;int changeIndex=0;//changeIndex 改變標(biāo)記

      int index=0;printf(“請輸入要修改的職工工號:”);scanf(“%s”,gh);for(i=0;i

      if(strcmp(gh,em[i].num)==0)//比較輸入工號和數(shù)組中已有工號

      {

      changeIndex=i;//保存要修改的人的下標(biāo)

      break;

      }

      } printf(“t工號t姓名t性別t部門t職稱t工資n”);printf(“t%st%st%st%st%st%dnn”,em[changeIndex].num,em[changeIndex].name,em[changeIndex].sex,em[changeIndex].bm,em[changeIndex].zc,em[changeIndex].gz);printf(“請重新輸入該職工信息”);printf(“工號:”);scanf(“%s”,em[changeIndex].num);printf(“姓名:”);scanf(“%s”,em[changeIndex].name);printf(“性別:”);scanf(“%s”,em[changeIndex].sex);printf(“部門:”);scanf(“%d”,em[changeIndex].bm);printf(“職稱:”);scanf(“%s”,em[changeIndex].zc);printf(“工資:”);scanf(“%d”,&em[changeIndex].gz);

      //信息修改后重新更新文件里面的數(shù)據(jù) 以保持?jǐn)?shù)據(jù)一致性

      fp=fopen(“employee1.txt”,“wb+”);for(i=0;i

      fwrite(&em[i],sizeof(struct employee),1,fp);//把ptr所指向n*size個字節(jié)輸入到fp所指向的文件中

      } fclose(fp);printf(“t=======>修改成功n”);}

      void disp()//輸出所有職工信息 { int i=0;for(i=0;i

      printf(“t%st%st%st%st%st%dnn”,em[i].num,em[i].name,em[i].sex,em[i].bm,em[i].zc,em[i].gz);} }

      void sort()//排序 {

      struct employee t;

      int wantNUmber=0;int i=0;int j=0;int k=0;for(i=0;i

      for(j=i+1;j

      {

      if(em[j].gz>em[k].gz)

      k=j;

      }

      if(k!=i)

      {

      t=em[i];

      em[i]=em[k];

      em[k]=t;

      }

      }

      printf(“你想輸出前幾名職工的信息:”);scanf(“%d”,&wantNUmber);if(wantNUmber>Number){

      wantNUmber=Number;}

      printf(“t工號t姓名t性別t部門t職稱t工資n”);for(i=0;i

      printf(“t%st%st%st%st%st%dnn”,em[i].num,em[i].name,em[i].sex,em[i].bm,em[i].zc,em[i].gz);}

      }

      void tongji()//統(tǒng)計 {

      int i,m,k,max,min;double sum=0.0;for(i=0;i

      if(em[i].gz>max)

      m=i;

      max=em[m].gz;} printf(“最高工資為:%dn”,max);printf(“t%st%st%st%st%st%dnn”,em[m].num,em[m].name,em[m].sex,em[m].bm,em[m].zc,em[m].gz);i=0;k=0;min=0;min=em[0].gz;for(i=1;i

      if(em[i].gz

      k=i;

      min=em[k].gz;} printf(“最低工資:%dn”,min);printf(“t%st%st%st%st%st%dnn”,em[k].num,em[k].name,em[k].sex,em[k].bm,em[k].zc,em[k].gz);

      }

      void num_del()//按工號刪除 { FILE *fp=NULL;char gh[60];int i=0;int j=0;printf(“請輸入要刪除的職工工號:”);scanf(“%d”,gh);for(i=0;i

      if(strcmp(gh,em[i].num)==0)//如果查找到就刪除

      {

      for(j=i;j

      {

      em[j]=em[j+1];

      }

      Number--;

      } }

      //將剩余數(shù)據(jù)寫入文件 重新一寫的方式打開文件 把以前的數(shù)據(jù)擦除了

      fp=fopen(“employee1.dat”,“wb”);for(i=0;i

      fwrite(&em[i],sizeof(struct employee),1,fp);} fclose(fp);printf(“刪除成功;n”);}

      void zc_query()//按職稱查找 {

      char zc[20];int i=0;printf(“請輸入要查找職工職稱:”);scanf(“%s”,zc);system(“cls”);printf(“t工號t姓名t性別t部門t職稱t工資n”);for(i=0;i

      if(strcmp(zc,em[i].zc)==0)

      {

      printf(“t%st%st%st%st%st%dnn”,em[i].num,em[i].name,em[i].sex,em[i].bm,em[i].zc,em[i].gz);

      } } }

      void select()//查看職工 { int i=0;printf(“以下是全部職工信息n”);printf(“t工號t姓名t性別t部門t職稱t工資n”);for(i=0;i

      printf(“t%st%st%st%st%st%dnn”,em[i].num,em[i].name,em[i].sex,em[i].bm,em[i].zc,em[i].gz);} }

      void add()//增加職工 { int numberTemp=0;int i=0;struct employee temp;//臨時保存信息

      printf(“請輸入要增加職工信息的個數(shù):”);scanf(“%d”,&numberTemp);for(i=0;i

      printf(“輸入第%d個職工信息n”,i+1);

      printf(“工號:”);

      scanf(“%s”,temp.num);

      printf(“姓名:”);

      scanf(“%s”,temp.name);

      printf(“性別:”);

      scanf(“%s”,temp.sex);

      printf(“部門:”);

      scanf(“%s”,temp.bm);

      printf(“職稱:”);

      scanf(“%s”,temp.zc);

      printf(“工資:”);

      scanf(“%d”,&temp.gz);

      em[Number++]=temp;//將剛添加的寫入到數(shù)組

      write_file(&temp);//將剛添加的寫入到文件

      } printf(“添加成功n”);}

      void write_file(struct employee *em){ FILE *fp=NULL;fp=fopen(“employee1.txt”,“rb+”);fwrite(em,sizeof(struct employee),1,fp);fclose(fp);}

      int read_file(struct employee em[]){ FILE *fp=NULL;int i=0;fp=fopen(“employee1.txt”,“rb”);while(fread(&em[i],sizeof(struct employee),1,fp))

      i++;fclose(fp);return i;}

      第四篇:職工信息管理系統(tǒng)源代碼

      #include #include #include int N=2;struct worker/*定義一個職工信息的結(jié)構(gòu)體*/ {

      intnum;

      /*定義一個職工信息的結(jié)構(gòu)體*/ char name[20];

      /*定義一個職工信息的結(jié)構(gòu)體*/

      char sex[10];

      //用字符串存放職工的性別數(shù)據(jù)

      char birth[20];//用字符串存放職工的出生年月數(shù)據(jù)

      char deta[20];//用字符串存放職工的工作年月數(shù)據(jù)

      char education[20];//用字符串存放職工的學(xué)歷數(shù)據(jù)

      double salary;

      //用字符串存放職工的性別數(shù)據(jù)

      char work[30];//用字符串存放職工的職務(wù)數(shù)據(jù)

      char addr[20];//用字符串存放職工的地址數(shù)據(jù)

      char tel[20];//用字符串存放職工的電話數(shù)據(jù) }worker[100];//用結(jié)構(gòu)體數(shù)組存放職工的所有信息 void menu();

      void input();

      void save();

      void read();

      void display();

      void add();

      void search();

      voidsearch_education();

      voidsearch_num();

      void del();

      void modify();

      void main()

      { char s;

      system(“color 3f”);

      printf(“nn”);

      printf(“ t┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓n”);

      printf(“ t┃**********************************************************┃n”);

      printf(“ t┃***┏━━━━━━━━━━━━━━━━━━━━━━━━┓***┃n”);

      printf(“ t┃***┃************************************************┃***┃n”);

      printf(“ t┃***┃***

      ****┃***┃n”);

      printf(“ t┃***┃***

      歡迎使用職工信息管理系統(tǒng)

      ****┃***┃n”);

      printf(“ t┃***┃***

      ****┃***┃n”);

      printf(“ t┃***┃***

      ****┃***┃n”);

      printf(“ t┃***┃***

      制作人吳青伶

      ****┃***┃n”);

      printf(“ t┃***┃***

      ****┃***┃n”);

      printf(“ t┃***┃***

      2013.12.28

      ****┃***┃n”);

      printf(“ t┃***┃***

      ****┃***┃n”);

      printf(“ t┃***┃************************************************┃***┃n”);

      printf(“ t┃***┗━━━━━━━━━━━━━━━━━━━━━━━━┛***┃n”);

      printf(“ t┃**********************************************************┃n”);printf(“ t┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛n”);do { menu();printf(“Do you want to continue?(y/n)”);

      s=getchar();}while(s=='Y'||s=='y');} void menu()/*菜單函數(shù)*/ { int b;printf(“t

      n”);printf(“t

      n”);printf(“t

      n”);printf(“t

      n”);printf(“t

      n”);printf(“t

      請選擇

      n”);printf(“t

      ------------------------------n”);printf(“t

      ||

      ||

      n”);printf(“t

      ||

      1.職工信息錄入

      ||

      n”);printf(“t

      ||

      2.職工信息瀏覽

      ||

      n”);printf(“t

      ||

      3.職工信息添加

      ||

      n”);printf(“t

      ||

      4.職工信息查詢

      ||

      n”);printf(“t

      ||

      5.職工信息刪除

      ||

      n”);printf(“t

      ||

      6.職工信息修改

      ||

      n”);printf(“t

      ||

      0.退出

      ||

      n”);printf(“tn”);printf(“n 輸入你的選擇項(0~6):n”);

      scanf(“%d”,&b);

      switch(b)

      {

      case 1 : //職工信息錄入、保存

      input();

      save();

      getchar();

      break;

      case 2 ://讀入職工信息并顯示

      read();

      display();

      getchar();break;

      case 3 : //添加職工信息

      add();getchar();break;

      case 4 : //查詢職工信息

      search();getchar();break;

      case 5 : //讀入職工信息并實現(xiàn)職工信息刪除功能

      read();

      del();

      getchar();

      break;

      case 6 : //讀入職工信息并修改職工信息

      read();modify();getchar();break;

      case 0 : exit(0);//退出

      default:break;} } void input()

      //錄入職工信息 {

      inti,flag,j;printf(“輸入職工個數(shù)(默認(rèn)個數(shù)為2):”);scanf(“%d”,&N);fflush(stdin);//清除緩存 for(i=0;i

      { loop: printf(“職工號:”);scanf(“%d”,&worker[i].num);fflush(stdin);flag=1;if(worker[N].num<0)

      printf(“請輸入正整數(shù):n”);else for(j=0;j

      {

      if(worker[i].num==worker[j].num)

      {

      flag=0;

      printf(“ 工號重復(fù),請重新輸入!n”);

      goto loop;

      }

      } printf(“姓名:”);scanf(“%s”,worker[i].name);fflush(stdin);printf(“性別:”);scanf(“ %s”,worker[i].sex);fflush(stdin);printf(“出生年月:”);scanf(“%d”,&worker[i].birth);fflush(stdin);printf(“工作年月:”);scanf(“%lf”,&worker[i].deta);fflush(stdin);printf(“請輸入學(xué)歷(中專=zz,大專=dz,本科=bk,研究生=y(tǒng)js):n”);scanf(“%s”,worker[i].education);fflush(stdin);printf(“工資:”);scanf(“%lf”,worker[i].salary);fflush(stdin);printf(“職務(wù):”);scanf(“%s”,worker[i].work);fflush(stdin);printf(“住址:”);scanf(“%s”,worker[i].addr);fflush(stdin);printf(“電話:”);scanf(“%s”,worker[i].tel);fflush(stdin);

      } printf(“n創(chuàng)建完畢!n”);}

      void save()

      //保存函數(shù) {

      FILE *fp;int i;

      if((fp=fopen(“worker.txt”,“wb”))==NULL)//以只寫方式打開一個二進(jìn)制文件

      {

      printf(“ncannot open filen”);

      exit(0);} for(i=0;i

      void read()

      //讀入函數(shù) {

      FILE *fp;int i=0;

      if((fp=fopen(“worker.txt”,“rb”))==NULL)//以只讀方式為輸出打開磁盤文件中的一個二進(jìn)制文件

      {

      printf(“ncannot open filen”);

      exit(0);} do{ fread(&worker[i],sizeof(struct worker),1,fp);//從worker.txt文件向內(nèi)存讀入數(shù)據(jù)(二進(jìn)制)

      i++;}while(!feof(fp));fclose(fp);

      N=i-1;}

      void display()

      //信息瀏覽函數(shù) {

      int i;for(i=0;i

      { printf(“職工號:%dn”,worker[i].num);printf(“姓名:%sn”,worker[i].name);printf(“性別:%sn”,worker[i].sex);printf(“出生年月:%dn”,worker[i].birth);printf(“工作年月:%dn”,worker[i].deta);printf(“學(xué)歷:%sn”,worker[i].education);printf(“工資:%lfn”,worker[i].salary);printf(“職務(wù):%dn”,worker[i].work);printf(“住址:%sn”,worker[i].addr);printf(“電話:%sn”,worker[i].tel);

      } } void add()

      //添加函數(shù) { FILE *fp;int i;struct worker p;double t;printf(“n請輸入新增加職工的信息:n”);

      printf(“請輸入職工號:n”);

      scanf(“%d”,&p.num);

      for(i=0;i

      {

      while(worker[i].num==p.num)

      {

      printf(“ 工號重復(fù),請重新輸入!n”);

      scanf(“%d”,&p.num);

      }

      } printf(“請輸入姓名:n”);scanf(“%s”,p.name);printf(“請輸入性別:n”);scanf(“%s”,p.sex);printf(“請輸入出生年月:n”);scanf(“%d”,&p.birth);printf(“請輸入工作年月:n”);scanf(“%d”,&p.deta);printf(“請輸入學(xué)歷(中專=zz,大專=dz,本科=bk,=yjs:):n”);scanf(“%s”,p.education);printf(“請輸入工資:n”);scanf(“%lf”,&t);p.salary=t;printf(“請輸入職務(wù):n”);scanf(“%s”,p.work);printf(“請輸入住址:n”);scanf(“%s”,p.addr);printf(“請輸入電話:n”);scanf(“%s”,p.tel);printf(“n添加完畢!n”);

      if((fp=fopen(“worker.txt”,“ab”))==NULL)//以追加方式打開一個二進(jìn)制文件尾部

      { printf(“ncannot open filen”);exit(0);

      } fwrite(&p,sizeof(struct worker),1,fp);fclose(fp);} void search()

      //查詢函數(shù) {

      int c;do {

      puts(“nsearch by=>n1.學(xué)歷2.職工號3.取消并返回”);printf(“Which you needed?:n”);scanf(“%d”,&c);

      研究生if(c>3||c<1)

      {

      puts(“nchoiceerror!please again!”);getchar();//此語句用于接受在執(zhí)行上一句時最后輸出的回車符

      }

      } while(c>3||c<1);

      { switch(c)

      { case 1:search_education();break;case 2:search_num();break;case 3:menu();break;

      }

      } } void search_education()

      //按學(xué)歷查詢函數(shù) { inti,flag=0;char s[10];printf(“n請輸入你要查詢的學(xué)歷:n”);scanf(“%s”,s);for(i=0;i

      { if(strcmp(s,worker[i].education)==0)

      {

      printf(“職工號:%dn”,worker[i].num);

      printf(“姓名:%sn”,worker[i].name);

      printf(“性別:%sn”,worker[i].sex);

      printf(“出生年月:%dn”,worker[i].birth);

      printf(“工作年月:%dn”,worker[i].deta);

      printf(“學(xué)歷(中專=zz,大專=dz,yjs):%sn”,worker[i].education);printf(“工資:%lfn”,worker[i].salary);printf(“職務(wù):%lfn”,worker[i].work);

      printf(“住址:%sn”,worker[i].addr);

      printf(“電話:%sn”,worker[i].tel);flag++;

      }

      } if(flag==0)

      printf(“n對不起沒有找到!n”);getchar();} void search_num()

      //按工號查詢函數(shù) { inti,s,flag=0;printf(“n輸入要查詢的職工號!:n”);scanf(“%d”,&s);

      本科=bk,研究生=for(i=0;i

      {

      if(s==worker[i].num)

      {

      printf(“職工號:%dn”,worker[i].num);

      printf(“姓名:%sn”,worker[i].name);

      printf(“性別:%sn”,worker[i].sex);

      printf(“出生年月:%dn”,worker[i].birth);

      printf(“工作年月:%dn”,worker[i].deta);

      printf(“學(xué)歷(中專=zz,大專=dz,本科=bk,研究生=y(tǒng)js):%sn”,worker[i].education);

      printf(“工資:%lfn”,worker[i].salary);printf(“職務(wù):%lfn”,worker[i].work);

      printf(“住址:%sn”,worker[i].addr);

      printf(“電話:%sn”,worker[i].tel);

      flag++;

      }

      }

      if(flag==0)printf(“n對不起沒有找到!please”);

      getchar();}

      void del()

      //刪除函數(shù) { inti,j;FILE *fp;char name[20];char c;if((fp=fopen(“worker.txt”,“wb”))==NULL)//以只寫方式打開一個二進(jìn)制文件

      {

      printf(“ncannot open filen”);exit(0);

      } printf(“請輸入要刪除的職工的姓名:”);scanf(“%s”,name);for(i=0;i

      if(strcmp(name,worker[i].name)==0)//判斷輸入的姓名和原來的姓名是否相同

      {

      printf(“找到該職工,是否刪除?(y/n)”);

      fflush(stdin);

      scanf(“%c”,&c);

      if(c =='Y'||c=='y')

      {

      for(j=i;j

      worker[j]=worker[j+1];

      printf(“刪除成功!n”);

      //break;

      }

      } } if(i>=N){ printf(“沒有找到該職工!n ”);

      return;}

      else {

      N=N-1;

      for(i=0;i

      if(fwrite(&worker[i],sizeof(struct worker),1,fp)!=1)

      {

      printf(“ncannot save filen”);getchar();

      }

      fclose(fp);}

      }

      void modify()

      //修改函數(shù) { struct worker p;FILE *fp;inti,n;double t;printf(“n輸入要修改的職工號:n”);scanf(“%d”,&n);

      for(i=0;i

      if(n==worker[i].num)

      {

      printf(“找到該職工的信息(任意鍵繼續(xù))!”);

      printf(“n請輸入職工的信息!n”);

      printf(“請輸入姓名:n”);scanf(“%s”,p.name);

      printf(“請輸入性別:n”);scanf(“%s”,p.sex);

      printf(“請輸入出身年月:n”);scanf(“%d”,&p.birth);printf(“請輸入工作年月:n”);scanf(“%lf”,&p.deta);

      printf(“請輸入學(xué)歷(中專=zz,大專=dz,yjs):n”);scanf(“%s”,p.education);printf(“請輸入工資:n”);scanf(“%lf”,&t);

      p.salary=t;printf(“請輸入職務(wù):n”);scanf(“%s”,p.work);

      printf(“請輸入住址:n”);scanf(“%s”,p.addr);

      本科=bk,研究生=

      }

      printf(“請輸入電話:n”);scanf(“%s”,p.tel);p.num=n;

      if((fp=fopen(“worker.txt”,“r+”))==NULL)//以讀寫的方式將修改的信息寫入磁盤文件

      {

      printf(“ncannot open filen”);

      exit(0);

      }

      fseek(fp,i*sizeof(struct worker),0);//將位置指針移到i*sizeof(struct worker)個字節(jié)處

      fwrite(&p,sizeof(struct worker),1,fp);

      fclose(fp);

      printf(“修改成功!n”);

      break;} } if(i>=N)printf(“n未找到該職工!n”);

      第五篇:C++課程設(shè)計 教職工信息管理系統(tǒng)源代碼

      教職工信息管理系統(tǒng)源碼

      #include #include #include #include

      #define maxsize 100 fstream iofile;//文件指針

      class Time //時間類 {

      public:

      int year;

      int month;

      int day;};

      class Telem //個人信息 {

      public:

      char name[20];

      char sex[10];

      Time birthtime;//組合Time類

      char num[20];

      char wage[20];

      Time worktime;

      int year;

      char department[20];

      friend istream& operator>>(istream& input,Telem& T);

      friend ostream& operator<<(ostream& output,Telem& T);

      friend int operator-(Time & t1,Time & t2);};

      class People:virtual public Telem //雇員類 {

      public:

      People();

      virtual void AddF()=0;//添加

      virtual void Addall()=0;

      virtual void Add()=0;

      virtual void Display();//輸出數(shù)組的內(nèi)容

      virtual void Displaypart(char p[]);

      virtual void Findname(char n[]);

      virtual void Findyear(int);

      virtual void Del(char n[])=0;

      virtual void Del(int);protected:

      Telem data[maxsize];

      Time now;

      int length;};

      class Teacher:virtual public People //派生虛基類 {

      public:

      virtual void AddF();

      virtual void Addall();

      virtual void Add();

      virtual void Display();

      virtual void Del(int i);

      virtual void Del(char n[]);};

      class worker:virtual public People //派生虛基類 {

      public:

      virtual void AddF();

      virtual void Addall();

      virtual void Add();

      virtual void Display();

      virtual void Del(int i);

      virtual void Del(char n[]);};

      People::People()//系統(tǒng)自動生成的構(gòu)造函數(shù) {

      length=0;

      now.year=2010;

      now.month=7;

      now.day=6;}

      void People::Display()//引用 {

      int i;

      for(i=0;i

      cout<

      void People::Displaypart(char p[])//引用數(shù)組

      {

      int i,c;

      for(i=0;i

      if(strcmp(data[i].wage,p)==0)

      {

      cout<<“輸出選擇姓名1 性別2 編號3 工資4 出生日期5 工作時間6 年齡7 系別8 退出選擇9”<

      while(cin>>c)

      {

      switch(c)

      {

      case 1: cout<<“姓名:”<

      case 2: cout<<“性別:”<

      case 3: cout<<“編號:”<

      case 4: cout<<“工資:”<

      case 5: cout<<“出生日期:”<

      case 6: cout<<“工作時間:”<

      case 7: cout<<“年齡:”<

      case 8: cout<<“系別:”<

      case 9: goto loop;

      default:cout<<“操作錯誤......”<

      }

      }

      loop:;

      } }

      void People::Findname(char n[])//引用 {

      int i;

      for(i=0;i

      if(strcmp(data[i].name,n)==0)//對象引用

      cout<

      void People::Findyear(int y){

      int i;

      for(i=0;i

      if(data[i].year==y)

      cout<

      void People::Del(int i){

      int j;

      if(i<1||i>length)

      cout<<“不存在第”<

      for(j=i;j

      data[j-1]=data[j];

      length--;}

      void worker::AddF(){

      int flag=0;

      iofile.open(“worker_information.txt”,ios::in|ios::binary);//文件的打開與關(guān)閉

      while(iofile.seekg(ios::cur))

      {

      iofile.seekg(length*sizeof(data[length]),ios::beg);

      iofile.read((char*)&data[length],sizeof(data[length]));//文件的隨機(jī)訪問

      length++;

      if(length==maxsize)

      {

      flag=1;

      goto loop;

      }

      }

      People::Del(length);

      cout<<“添加人員信息成功......”<

      loop:

      if(1==flag)

      cout<<“人員信息儲存空間已滿......”<

      iofile.close();}

      void worker::Addall(){

      char ans;

      int flag=0;

      iofile.open(“worker_information.txt”,ios::out|ios::binary);

      do

      {

      cin>>data[length];

      data[length].year=now-data[length].birthtime;

      iofile.write((char*)&data[length],sizeof(data[length]));

      cout<<“添加人員信息成功......”<

      length++;

      if(length==maxsize)

      {

      flag=1;

      goto loop;

      }

      cout<<“contine(Y|N)?”;

      cin>>ans;

      }while('y'==ans||'Y'==ans);loop:

      if(1==flag)

      cout<<“人員信息儲存空間已滿......”<

      iofile.close();}

      void worker::Add(){

      int flag=0;

      iofile.open(“worker_information.txt”,ios::app|ios::out|ios::binary);

      if(length==maxsize)

      {

      flag=1;

      goto loop;

      }

      cin>>data[length];

      data[length].year=now-data[length].birthtime;

      iofile.write((char*)&data[length],sizeof(data[length]));

      cout<<“添加人員信息成功......”<

      length++;

      loop:

      if(1==flag)

      cout<<“人員信息儲存空間已滿......”<

      iofile.close();}

      void worker::Display(){

      cout<<“ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆工人信息 ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆”<

      if(0==length)

      cout<<“無......”<

      int i;

      for(i=0;i

      cout<

      int i,j,k;

      for(i=0;i

      if(strcmp(data[i].name,n)==0){

      k=i+1;break;}

      if(k<1)

      cout<<“不存在姓名”<

      for(j=k;j

      data[j-1]=data[j];

      length--;

      cout<<“刪除人員信息成功......”<

      void worker::Del(int i){

      int j;

      if(i<1||i>length)

      cout<<“不存在第”<

      for(j=i;j

      data[j-1]=data[j];

      length--;

      cout<<“刪除成功......”<

      }

      void Teacher::AddF(){

      int flag=0;

      iofile.open(“Teacher_information.txt”,ios::in|ios::binary);

      while(iofile.seekg(sizeof(data[length]),ios::cur))

      {

      if(iofile.seekg(length*sizeof(data[length]),ios::beg))

      iofile.read((char*)&data[length],sizeof(data[length]));

      else

      break;

      length++;

      if(length==maxsize)

      {

      flag=1;

      goto loop;

      }

      }

      People::Del(length);

      cout<<“添加人員信息成功......”<

      if(1==flag)

      cout<<“人員信息儲存空間已滿......”<

      iofile.close();}

      void Teacher::Addall(){

      char ans;

      int flag=0;

      iofile.open(“Teacher_information.txt”,ios::in|ios::out|ios::binary);

      do

      {

      cin>>data[length];

      data[length].year=now-data[length].birthtime;

      iofile.write((char*)&data[length],sizeof(data[length]));

      cout<<“添加人員信息成功......”<

      length++;

      if(length==maxsize)

      {

      flag=1;

      goto loop;

      }

      cout<<“contine(Y|N)?”;

      cin>>ans;

      }while('y'==ans||'Y'==ans);loop:

      if(1==flag)

      cout<<“人員信息儲存空間已滿......”<

      iofile.close();}

      void Teacher::Add(){

      int flag=0;

      iofile.open(“Teacher_information.txt”,ios::app|ios::out|ios::binary);

      if(length==maxsize)

      {

      flag=1;

      goto loop;

      }

      cin>>data[length];

      data[length].year=now-data[length].birthtime;

      iofile.write((char*)&data[length],sizeof(data[length]));

      cout<<“添加人員信息成功......”<

      length++;loop:

      if(1==flag)

      cout<<“人員信息儲存空間已滿......”<

      iofile.close();}

      void Teacher::Display(){

      cout<<“ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆教師信息 ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆”<

      if(0==length)

      cout<<“無......”<

      int i;

      for(i=0;i

      cout<

      void Teacher::Del(char n[]){

      int i,j,k;

      for(i=0;i

      if(strcmp(data[i].name,n)==0)

      {

      k=i+1;break;

      }

      if(k<1)cout<<“不存在姓名”<

      for(j=k;j

      data[j-1]=data[j];

      length--;

      cout<<“刪除人員信息成功......”<

      void Teacher::Del(int i){

      int j;

      if(i<1||i>length)

      cout<<“不存在第”<

      for(j=i;j

      data[j-1]=data[j];

      length--;

      cout<<“刪除成功......”<

      istream& operator>>(istream& input,Telem& T){

      int y,m,d;

      cout<<“請輸入姓名(以*結(jié)尾):”<

      input.getline(T.name,20,'*');

      cout<<“請輸入性別(以*結(jié)尾 男或女):”<

      input.getline(T.sex,10,'*');

      cout<<“編號(以*結(jié)尾):”<

      input.getline(T.num,20,'*');

      cout<<“工資(以*結(jié)尾):”<

      input.getline(T.wage,20,'*');

      cout<<“請輸入出生日期:”<

      input>>y>>m>>d;

      T.birthtime.year=(y>=1900&&y<=2100)?y:1900;

      T.birthtime.month=(m>=1&&m<=12)?m:1;

      T.birthtime.day=(d>=1&&d<=31)?d:1;

      cout<<“請輸入系別(以*結(jié)尾):”<

      input.getline(T.department,20,'*');

      cout<<“參加工作時間:”<

      input>>y>>m>>d;

      T.worktime.year=(y>=1900&&y<=2100)?y:1900;

      T.worktime.month=(m>=1&&m<=12)?m:1;

      T.worktime.day=(d>=1&&d<=31)?d:1;

      return input;}

      ostream& operator<<(ostream& output,Telem& T){

      cout<<“姓名:”;

      output<

      cout<<“性別:”;

      output<

      cout<<“編號:”;

      output<

      cout<<“工資:”;

      output<

      cout<<“出生日期:”;

      output<

      cout<<“系別:”;

      output<

      cout<<“參加工作時間:”;

      output<

      cout<<“年齡:”;

      output<

      return output;}

      int operator-(Time & t1,Time & t2){

      return t1.year-t2.year;}

      void Showmenu(){

      cout<

      cout<<“

      歡 迎 進(jìn) 入 教 職 工 信 息 管 理 系 統(tǒng)”<

      cout<<“

      2010 年7月7日發(fā)布”<<“

      版權(quán)所有: swa”<

      cout<<“

      ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★人員信息管理系統(tǒng)★ ☆ ★ ☆ ★ ☆ ★ ☆ ★”<

      cout<<“

      1-從鍵盤錄入全部人員記錄

      ☆ ”<

      cout<<“

      ☆ 2-增加一位人員記錄

      ★”<

      cout<<“

      3-顯示全部人員記錄

      ☆”<

      cout<<“

      ☆ 4-按系別輸出人員信息(可選)★ ”<

      cout<<“

      5-按姓名或年齡檢索所有信息☆ ”<

      cout<<“

      ☆ 6-顯示菜單目錄

      ★ ”<

      cout<<“

      7-結(jié)束程序運行

      ☆ ”<

      cout<<“

      ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆”<

      int main(){

      Teacher tea;

      worker stu;

      People *pt=&tea;

      People *ps=&stu;

      int c=0,k=0,l=0,i=0;

      char nam[20],part[20];Showmenu();

      for(;;)

      {

      cout<<“請根據(jù)菜單執(zhí)行相應(yīng)操作: ”;

      cin>>c;

      switch(c)

      {

      case 1:

      {

      cout<<“ ★ ☆ ★ ☆ ★ ☆ ★錄入全部人員記錄 ★ ☆ ★ ☆ ★ ☆ ★”<

      cout<<“ ★ ☆ ★ ☆ ★從鍵盤輸入教師信息 ☆ ★ ☆ ★ ☆”<

      pt->Addall();

      cout<<“ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆從鍵盤輸入工人信息 ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆”<

      ps->Addall();

      break;

      }

      case 2:

      {

      cout<<“ ★ ☆ ★ ☆ ★ ☆ ★ ☆從鍵盤增加一位人員記錄 ★ ☆ ★ ☆ ★ ☆ ★ ☆”<

      cout<<“ ★ ☆ ★ ☆ ★ ☆ ★ ☆教師操作請按1 工人操作請按2 ★ ☆ ★ ☆ ★ ☆ ★ ☆”<

      cin>>k;

      if(1==k)

      pt->Add();

      else if(2==k)

      ps->Add();

      else

      cout<<“操作錯誤...”<

      break;

      }

      case 3:

      {

      cout<<“ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆顯示全部人員記錄 ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆”<

      pt->Display();

      ps->Display();

      break;

      }

      case 4:

      {

      cout<<“ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆按部門輸出人員信息(可選)★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆”<

      cout<<“ ★ ☆ ★ ☆ ★ ☆教師操作請按1 工人操作請按2 ★ ☆ ★ ☆ ★ ☆”<

      cin>>k;

      if(1==k)

      {

      cout<<“請輸入要輸出人員的系別(以*結(jié)尾):”<

      pt->Displaypart(part);

      }

      else if(2==k)

      {

      cout<<“請輸入要輸出人員的系別(以*結(jié)尾):”<

      ps->Displaypart(part);

      }

      else

      cout<<“操作錯誤......”<

      break;

      }

      case 5:

      {

      cout<<“ ★ ☆ ★ ☆ ★ ☆ ★按姓名或年齡檢索所有信息 ★ ☆ ★ ☆ ★ ☆ ★”<

      cout<<“ ★ ☆ ★ ☆ ★ ☆ ★按姓名查找1 按年齡查找2 ★ ☆ ★ ☆ ★ ☆ ★”<

      cin>>k;

      if(1==k)

      {

      cout<<“按姓名查找1 按年齡查找2”<>l;

      if(1==l)

      {

      cout<<“請輸入要查找人員的姓名(以*結(jié)尾):”<

      pt->Findname(nam);

      }

      else if(2==l)

      {

      cout<<“請輸入要查找人的年齡:”<>i;

      pt->Findyear(i);

      }

      else

      cout<<“操作錯誤......”<

      }

      else if(2==k)

      {

      cout<<“按姓名查找1 按年齡查找2”<>l;

      if(1==l)

      {

      cout<<“請輸入要查找人員的姓名(以*結(jié)尾):”<

      ps->Findname(nam);

      }

      else if(2==l)

      {

      cout<<“請輸入要查找人的年齡:”<>i;

      ps->Findyear(i);

      }

      else

      cout<<“操作錯誤......”<

      }

      else

      cout<<“操作錯誤......”<

      break;

      }

      case 6:

      {

      cout<<“ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆顯示菜單目錄 ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆”<

      Showmenu();

      break;

      }

      case 7:

      {

      cout<<“ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆結(jié)束程序運行 ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆”<

      exit(0);

      }

      default:cout<<“操作錯誤......”<

      }

      }

      return 0;}

      下載C語言課程設(shè)計 職工信息管理系統(tǒng) 單鏈表實現(xiàn)程序源代碼word格式文檔
      下載C語言課程設(shè)計 職工信息管理系統(tǒng) 單鏈表實現(xiàn)程序源代碼.doc
      將本文檔下載到自己電腦,方便修改和收藏,請勿使用迅雷等下載。
      點此處下載文檔

      文檔為doc格式


      聲明:本文內(nèi)容由互聯(lián)網(wǎng)用戶自發(fā)貢獻(xiàn)自行上傳,本網(wǎng)站不擁有所有權(quán),未作人工編輯處理,也不承擔(dān)相關(guān)法律責(zé)任。如果您發(fā)現(xiàn)有涉嫌版權(quán)的內(nèi)容,歡迎發(fā)送郵件至:645879355@qq.com 進(jìn)行舉報,并提供相關(guān)證據(jù),工作人員會在5個工作日內(nèi)聯(lián)系你,一經(jīng)查實,本站將立刻刪除涉嫌侵權(quán)內(nèi)容。

      相關(guān)范文推薦