毕业论文论文范文课程设计实践报告法律论文英语论文教学论文医学论文农学论文艺术论文行政论文管理论文计算机安全
您现在的位置: 毕业论文 >> 课程设计 >> 正文

通讯录管理系统C语言课程设计

更新时间:2010-7-14:  来源:毕业论文

通讯录管理系统C语言课程设计
#include <string.h>

  #include <stdio.h>

  #include<stdlib.h>

  int cntAddr=0,i,j;

  char in[12];

  const char * strFmt="\n%d\t%s\t%s\t%s\t%s\n";

  typedef struct ADDRESSD {

  int ID;

  char name[12];

  char workPlace[12];

  char teleOff[12];

  char teleHome[12];

  }ADDRESS;

  ADDRESS addrTmp[100],adTmp;

  int load(ADDRESS adr[]){

  FILE *fp;

  if((fp=fopen("c:\\txl.txt","r"))!=NULL){

  cntAddr=0;

  while(!feof(fp)){

  fscanf(fp,"%d %s %s %s %s ",&(adr[cntAddr].ID),adr[cntAddr].name,adr[cntAddr].workPlace,adr[cntAddr].teleOff,adr[cntAddr].teleHome);

  ++cntAddr;

  }

  }

  fclose(fp);

  return cntAddr;

  };

  void list(ADDRESS addr[],int length){

  for(i=0;i<length;++i)printf(strFmt,addr.ID,addr.name,addr.workPlace,addr.teleOff,addr.teleHome);

  }

  void display(ADDRESS addr[]){

  for(i=0;i<cntAddr;++i)addrTmp=addr;

  for(i=0;i<cntAddr-1;++i)for(j=i+1;j<cntAddr;++j)if(addrTmp.ID>addrTmp[j].ID){adTmp=addrTmp;addrTmp=addrTmp[j];addrTmp[j]=adTmp;}

  for(i=0;i<cntAddr;++i)printf(strFmt,addrTmp.ID,addrTmp.name,addrTmp.workPlace,addrTmp.teleOff,addrTmp.teleHome);

  }

  void namesort(ADDRESS addr[],int length){

  for(i=0;i<length;++i)addrTmp=addr;

  for(i=0;i<length-1;++i)for(j=i+1;j<length;++j)if(strcmp(addrTmp.name,addrTmp[j].name)>0){adTmp=addrTmp;addrTmp=addrTmp[j];addrTmp[j]=adTmp;}

  for(i=0;i<length;++i)printf(strFmt,addrTmp.ID,addrTmp.name,addrTmp.workPlace,addrTmp.teleOff,addrTmp.teleHome);

  };

  void save(ADDRESS adr[],int length){

  FILE *fp;

  fp=fopen("c:\\txl.txt","w");

  for(i=0;i<cntAddr;++i)fprintf(fp,"%d %s %s %s %s ",adr.ID,adr.name,adr.workPlace,adr.teleOff,adr.teleHome);

  fclose(fp);

  };

  void unitssort(ADDRESS addr[],int length){

  for(i=0;i<length;++i)addrTmp=addr;

  for(i=0;i<length-1;++i)for(j=i+1;j<length;++j)if(strcmp(addrTmp.workPlace,addrTmp[j].workPlace)>0){adTmp=addrTmp;addrTmp=addrTmp[j];addrTmp[j]=adTmp;}

  for(i=0;i<length;++i)printf(strFmt,addrTmp.ID,addrTmp.name,addrTmp.workPlace,addrTmp.teleOff,addrTmp.teleHome);

  };

  void namesearch(ADDRESS addr[],int length){

  printf("请输入姓名:\n");

  scanf("%s",&in);

  for(i=0;i<length;++i)if(strcmp(addr.name,in)==0)printf(strFmt,addr.ID,addr.name,addr.workPlace,addr.teleOff,addr.teleHome);

  };

  void unitssearch(ADDRESS adr[],int length){

  printf("请输入班级:\n");

  scanf("%s",&in);

  for(i=0;i<length;++i)if(strcmp(adr.workPlace,in)==0)printf(strFmt,adr.ID,adr.name,adr.workPlace,adr.teleOff,adr.teleHome);

  };

  void officenumbersearch(ADDRESS adr[],int length){

  printf("请输入移动电话:\n");

  scanf("%s",&in);

  for(i=0;i<length;++i)if(strcmp(adr.teleOff,in)==0)printf(strFmt,adr.ID,adr.name,adr.workPlace,adr.teleOff,adr.teleHome);

  };

  void homenumbersearch(ADDRESS adr[],int length){

  printf("请输入家庭电话:\n");

  scanf("%s",&in);

  for(i=0;i<length;++i)if(strcmp(adr.teleHome,in)==0)printf(strFmt,adr.ID,adr.name,adr.workPlace,adr.teleOff,adr.teleHome);

  };

  int delet(ADDRESS adr[],int length){

  printf("要修改第几条记录:\n");

  scanf("%d",&j);

  for(i=j;i<length-1;++i)adr=adr[i+1];

  return --length;

  };

  void rewrite(ADDRESS adr[],int length){

  printf("要修改第几条记录:\n");

  scanf("%d",&j);

  printf("请输入ID:\n");

  scanf("%d",&i);

  adr[j].ID=i;

  printf("请输入姓名:\n");

  scanf("%s",in);

  strcpy(adr[j].name,in);

  printf("请输入班级:\n");

  scanf("%s",in);

  strcpy(adr[j].workPlace,in);

  printf("请输入移动电话:\n");

  scanf("%s",in);

  strcpy(adr[j].teleOff,in);

  printf("请输入家庭电话:\n");

  scanf("%s",in);

  strcpy(adr[j].teleHome,in);

  };

  int add(ADDRESS adr[],int length){

  printf("请输入ID:\n");

  scanf("%d",&i);

  adr[length].ID=i;

  printf("请输入姓名:\n");

  scanf("%s",in);

  strcpy(adr[length].name,in);

  printf("请输入班级:\n");

  scanf("%s",in);

  strcpy(adr[length].workPlace,in);

  printf("请输入移动电话:\n");

  scanf("%s",in);

  strcpy(adr[length].teleOff,in);

  printf("请输入家庭电话:\n");

  scanf("%s",in);

  strcpy(adr[length].teleHome,in);

  return ++cntAddr;

  };

  void copy(){

  FILE *fp,*fc;

  printf("请输入新文件名(路径中的反斜杠用\\表示)\n");

  scanf("%s",&in);

  if((fp=fopen("c:\\txl.txt","r"))!=NULL){

  fc=fopen(in,"w");

  while(!feof(fp)){

  fscanf(fp,"%d %s %s %s %s ",&(adTmp.ID),adTmp.name,adTmp.workPlace,adTmp.teleOff,adTmp.teleHome);

  fprintf(fc,"%d %s %s %s %s ",adTmp.ID,adTmp.name,adTmp.workPlace,adTmp.teleOff,adTmp.teleHome);

  }

  fclose(fc);

  }

  fclose(fp);

  };

  int enter(ADDRESS adr[]){

  cntAddr=0;

  printf("请按次序输入数据,结束按CTRL+z:\n");

  while(1){

  printf("请输入ID:\n");

  if(scanf("%d",&i)==EOF)break;

  adr[cntAddr].ID=i;

  printf("请输入姓名:\n");

  if(scanf("%s",in)==EOF)break;

  strcpy(adr[cntAddr].name,in);

  printf("请输入班级:\n");

  if(scanf("%s",in)==EOF)break;

  strcpy(adr[cntAddr].workPlace,in);

  printf("请输入移动电话:\n");

  if(scanf("%s",in)==EOF)break;

  strcpy(adr[cntAddr].teleOff,in);

  printf("请输入家庭电话:\n");

  if(scanf("%s",in)==EOF)break;

  strcpy(adr[cntAddr].teleHome,in);

  ++cntAddr;

  }

  return cntAddr;

  };

  void showpaixu(ADDRESS adr[],int length)

  {

  int choice;

  menu1:

  system("cls");

  printf("\n\n\n\n *************************通讯录信息管理系统*************************\n\n");

  printf(" 1. 全部显示通讯录信息\n\n");

  printf(" 2. 按序号显示通讯录信息\n\n");

  printf(" 3. 按姓名排序\n\n");

  printf(" 4. 按班级排序\n\n");

  printf(" 0. 返回上一级菜单\n\n");

  printf(" ********************************************************************\n");

  printf(" 请选择(0~4)\n ");

  scanf("%d",&choice);

  switch(choice)

  {

  case 1:

  list(adr,length);

  printf(" 请按任意键返回...\n");

  system("pause");

  break;

  case 2:

  display(adr);

  printf(" 请按任意键返回...\n");

  system("pause");break;

  case 3:

  namesort(adr,length);

  printf(" 请按任意键返回...\n");

  system("pause");

  break;

  case 4:

  unitssort(adr,length);

  printf(" 请按任意键返回...\n");

  system("pause");

  break;

  case 0: return;

  }

  goto menu1;

  }

  void chazhao(ADDRESS adr[],int length)

  {

  int choice;

  menu2:

  system("cls");

  printf("\n\n\n\n *************************通讯录信息管理系统*************************\n\n");

  printf(" 1. 通过姓名查找\n\n");

  printf(" 2. 通过班级查找\n\n");

  printf(" 3. 通过移动电话查找\n\n");

  printf(" 4. 通过家庭电话查找\n\n");

  printf(" 0. 返回上一级菜单\n\n");

  printf(" ********************************************************************\n");

  printf(" 请选择(0~4)\n ");

  scanf("%d",&choice);

  switch(choice)

  {

  case 1:

  namesearch(adr,length);

  printf(" 请按任意键返回...\n");

  system("pause");

  break;

  case 2:

  unitssearch(adr,length);

  printf(" 请按任意键返回...\n");

  system("pause");

  break;

  case 3:

  officenumbersearch(adr,length);

  printf(" 请按任意键返回...\n");

  system("pause");

  break;

  case 4:

  homenumbersearch(adr,length);

  printf(" 请按任意键返回...\n");

  system("pause");

  break;

  case 0: return;

  }

  goto menu2;

  }

  void biangeng(ADDRESS adr[],int length)

  {

  int choice;

  menu3:

  system("cls");

  printf("\n\n\n\n *************************通讯录信息管理系统*************************\n\n");

  printf(" 1. 删除记录\n\n");

  printf(" 2. 修改记录\n\n");

  printf(" 3. 添加记录\n\n");

  printf(" 0. 返回上一级菜单\n\n");

  printf(" ********************************************************************\n");

  printf(" 请选择(0~3)\n ");

  scanf("%d",&choice);

  switch(choice)

  {

  case 1:

  length=delet(adr,length);

  save(adr,length);

  printf(" 请按任意键返回...\n");

  getchar();

  break;

  case 2:

  rewrite(adr,length);

  save(adr,length);

  printf(" 请按任意键返回...\n");

  getchar();

  break;

  case 3:

  length=add(adr,length);

  save(adr,length);

  printf(" 请按任意键返回...\n");

  getchar();

  break;

  case 0: return;

  }

  goto menu3;

  }

  int wenjian(ADDRESS adr[],int length)

  {

  int choice;

  menu4:

  system("cls");

  printf("\n\n\n\n *************************通讯录信息管理系统*************************\n\n");

  printf(" 1. 导入文件到通讯录\n\n");

  printf(" 2. 把当前文件复制到新文件上\n\n");

  printf(" 0. 返回上一级菜单\n\n");

  printf(" ********************************************************************\n");

  printf(" 请选择(0~2)\n ");

  scanf("%d",&choice);

  switch(choice)

  {

  case 1: length=load(adr);

  printf("您已经成功的导入文件到通讯录!\n");

  printf(" 请按任意键返回...\n");

  system("pause");break;

  case 2: copy();

  printf("复制成功!\n");

  printf(" 请按任意键返回...\n");

  system("pause");break;

  case 0: return length;

  }

  goto menu4;

  }

  void about()

  {

  system("color 87");

  system("cls");

  printf("\n\n\n\n 《通讯录信息管理系统》\n\n\n");

  printf(" *****************************************\n\n\n");

  printf(" 优文论文网\n\n\n");

  printf(" 制作人:毕业论文http://www.youerw.com\n\n\n");

  printf(" *****************************************\n\n\n");

  printf(" 请按任意键返回主菜单...");

  system("pause");

  }

  void main()

  {

  int choice;

  int length;

  ADDRESS adr[100] ;

  menu:

  system("color f9");

  system("cls");

  printf("\n\n\n\n *************************通讯录信息管理系统毕业论文http://www.youerw.com*************************\n\n");

  printf(" 请选择以下通讯录管理功能:\n\n");

  printf(" 1. 通讯录信息输入\n\n");

  printf(" 2. 通讯录信息浏览及排序\n\n");

  printf(" 3. 通讯录信息查询\n\n");

  printf(" 4. 通讯录信息更改\n\n");

  printf(" 5. 通讯录及文件操作\n\n");

  printf(" 6. 关于通讯录信息管理系统\n\n");

  printf(" 0. 退出通讯录管理系统\n\n");

  printf(" ********************************************************************\n");

  printf(" 请选择(0~6)\n ");

  scanf("%d",&choice);

  switch(choice)

  {

  case 1: length=enter(adr);

  save(adr,length);

  printf("\n 请按任意键返回...\n");

  system("pause");break;

  case 2: showpaixu(adr,length);break;

  case 3: chazhao(adr,length);break;

  case 4: biangeng(adr,length);break;

  case 5: length=wenjian(adr,length);break;

  case 6: about();break;

  case 0: return;

  }   goto menu;   }

通讯录管理系统C语言课程设计下载如图片无法显示或论文不完整,请联系qq752018766
设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©youerw.com 优文论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。