找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2328|回复: 1
打印 上一主题 下一主题
收起左侧

C语言通讯录管理小系统源程序

[复制链接]
跳转到指定楼层
楼主
ID:350383 发表于 2018-6-12 21:43 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
这是我c语言实训花了一周写的c语言程序,都是原创,希望大家多多指教

  1. /* Note:Your choice is C IDEx 向爱军 35 手机通讯录管理系统 */
  2. #include "stdio.h"
  3. #include "stdlib.h"
  4. #include "string.h"
  5. #include "windows.h"
  6. struct Mobile_Phone
  7. {
  8.         char name[20];
  9.     char number[20];
  10.         
  11. };
  12. typedef struct Mobile_Phone mobile_Phone;
  13. void input(mobile_Phone contacts[],int *cntp);
  14. void display(mobile_Phone contacts[],int *cntp);

  15. void delet(mobile_Phone contacts[],int *cntp);//删除功能
  16. void deleteNo(mobile_Phone contacts[],int *cntp);
  17. void deleteNumber(mobile_Phone contacts[],int *cntp);
  18. void deleteAll(mobile_Phone contacts[],int *cntp);
  19. void deleteNAME(mobile_Phone contacts[],int *cntp);

  20. void lookup(mobile_Phone contacts[],int *cntp) ;//查找功能
  21. void lookupNo(mobile_Phone contacts[],int *cntp) ;
  22. void lookupNumber(mobile_Phone contacts[],int *cntp) ;
  23. void lookupNAME(mobile_Phone contacts[],int *cntp) ;

  24. void main()
  25. {
  26.     mobile_Phone contacts[50];
  27.     int count=0;
  28.     int choise;
  29.     MessageBox(NULL,"Welcome to mobile phone address book management system !","提示",MB_OK);
  30.     do
  31.     {
  32.             system("cls");
  33.             printf("*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n");
  34.         printf("*=*               Programming instruction *=*\n");
  35.         printf("*=* Please save your contact list in time!*=*\n");
  36.         printf("*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n");
  37.             printf("\n\n\n\n      ****   MENU   ******\n");
  38.             printf("      1.   Input your cellphone contacts information \n");   //录入手机联系人信息
  39.             printf("      2.   Delete the cellphone contacts  information\n");    //删 除联系人信息
  40.             printf("      3.   Display the cellphone contacts information\n");    //显示联系人信息
  41.             printf("      4.   Look for mobile phone contacts information\n");//查找联系人的信息
  42.             printf("      0.   *Exit*\n\n");                                //退出
  43.             printf("\n   Please enter your choise:(0~4):");
  44.             do
  45.             {
  46.                     scanf("%d",&choise);
  47.                     if(choise<0||choise>5)
  48.                             printf("\n  输入错误,请重新选择(0~5):");
  49.             }while(choise<0||choise>5);
  50.             switch(choise)
  51.             {
  52.                     case 1:input(contacts,&count);break;
  53.                     case 2:delet(contacts,&count);break;
  54.                     case 3:display(contacts,&count);break;
  55.                     case 4:lookup(contacts,&count);break;
  56.                     case 0:break;
  57.             }
  58.             printf("\n");
  59.     }while(choise!=0);
  60. }
  61. void input(mobile_Phone contacts[],int *cntp)   //录入联系人信息
  62. {
  63.         int i;
  64.         freopen("d:\\gushi.in","r",stdin);
  65.         printf("Please enter your phone's  Name and Telephone number: \n");
  66.         for(i=0;i<16;i++)
  67.                 {
  68.                         scanf("%s %s",&contacts[i].name,&contacts[i].number);
  69.                         *cntp+=1;
  70.                 }
  71.       freopen("con","r",stdin);
  72. }
  73. void display(mobile_Phone contacts[],int *cntp) //显示手机联系人信息
  74. {
  75.         int i;
  76.         printf("       No   Name   Telephone  \n");
  77.         for(i=0;i<*cntp;i++)
  78.         {
  79.                 printf("        %d    %s    %s\n",i+1,&contacts[i].name,&contacts[i].number);
  80.                
  81.         }
  82.         fflush(stdin);
  83.         getchar();
  84. }

  85. void delet(mobile_Phone contacts[],int *cntp)  //删除菜单
  86. {
  87.         int choise;
  88.     do
  89.     {   
  90.             system("cls");
  91.             printf("\n\n\n\n      ****   Delete Menu   ******\n");
  92.             printf("           1. Delete information by number \n");//按电话号码删除联系人信息
  93.             printf("           2. Delete information by name \n"); //按名字删除
  94.             printf("           3. Delete all \n");         
  95.             printf("           4. Delete information by No \n");//按序号删除         
  96.             printf("           0.  *EXIT*\n\n");   //退出
  97.             printf("\n        Please your choise:(0~4):");
  98.             do
  99.             {
  100.                     scanf("%d",&choise);
  101.                     if(choise<0||choise>4)
  102.                             printf("\n  input error !,please reinput(0~4):");
  103.             }while(choise<0||choise>4);
  104.             switch(choise)
  105.             {
  106.                     case 1:deleteNumber(contacts,cntp);break;
  107.                     case 2:deleteNAME(contacts,cntp);break;
  108.                     case 3:deleteAll(contacts,cntp);break;
  109.                     case 4:deleteNo(contacts,cntp);break;                    
  110.                     case 0:break;
  111.             }
  112.             printf("\n");
  113.     }while(choise!=0);
  114. }
  115. void deleteNumber(mobile_Phone contacts[],int *cntp)  //按电话号码删除
  116. {
  117.         int n,t,k,j;
  118.         char num[12];        
  119.     do{  
  120.               printf("input number information   :\t");
  121.           scanf("%s",&num);
  122.               for(k=0;k<*cntp;k++)
  123.               {        
  124.                   n=strcmp(num,contacts[k].number);                        
  125.                   if(n==0)               
  126.                   break;                                          
  127.               }
  128.               if(n!=0) printf("No find such person ,please again");   
  129.      }while(n!=0);
  130.      j=k;
  131.      for(j;(j+1)<*cntp;j++)
  132.      {                                                  
  133.               contacts[j].number[12]=contacts[j+1].number[12];
  134.           for(t=0;t<12;t++)
  135.               {                  
  136.                   contacts[j].name[t]=contacts[j+1].name[t];                     
  137.               }   
  138.     }                     
  139.         *cntp=*cntp-1;

  140. }
  141. void deleteAll(mobile_Phone contacts[],int *cntp)
  142. {
  143.         
  144.    *cntp=0;
  145.    
  146. }
  147. void deleteNAME(mobile_Phone contacts[],int *cntp)  //按名字删除
  148. {
  149.         int n,t,k,j,x;
  150.         char nam[12];        
  151.     do{  
  152.                  printf("input Name information   :\t");
  153.           scanf("%s",&nam);
  154.               for(k=0;k<*cntp;k++)
  155.               {        
  156.                   n=strcmp(nam,contacts[k].name);                  
  157.                   x=n;
  158.                   if(x==0)               
  159.                   break;                                          
  160.               }
  161.               if(n!=0) printf("No find such person ,please again");   
  162.      }while(n!=0);
  163.      j=k;
  164.      for(j;(j+1)<*cntp;j++)
  165.      {                                                  
  166.               contacts[j].number[12]=contacts[j+1].number[12];
  167.           for(t=0;t<12;t++)
  168.               {                  
  169.                   contacts[j].name[t]=contacts[j+1].name[t];                     
  170.               }   
  171.     }                     
  172.         *cntp=*cntp-1;
  173. }
  174. void deleteNo(mobile_Phone contacts[],int *cntp)  //按手机联系人的序号删除
  175. {
  176.         int no,i=0,j,t;
  177.            printf("\n please input you want look up contact's No : ");  //请输入你要删除的联系人在手机里的序号
  178.         do{
  179.            scanf("%d",&no);
  180.            if(no<1||no>500)
  181.            printf("input error ,Please reinput:");
  182.         }while(no<1||no>500);        
  183.              j=no-1;
  184.      for(j;(j+1)<*cntp;j++)
  185.      {                                                  
  186.               contacts[j].number[12]=contacts[j+1].number[12];
  187.           for(t=0;t<12;t++)
  188.               {                  
  189.                   contacts[j].name[t]=contacts[j+1].name[t];                     
  190.               }   
  191.     }                     
  192.         *cntp=*cntp-1;            

  193. }
  194. void lookup(mobile_Phone contacts[],int *cntp)  //查找联系人菜单
  195. {
  196.         int choise;
  197.     do
  198.     {   
  199.             system("cls");
  200.             printf("\n\n\n\n      ****   Search Menu   ******\n");
  201.             printf("      1.  input  information by Delete's No\n");//按手机联系人的序号查找
  202.             printf("      2.  input  information by Delete's Number\n");//按联系人电话号码查找
  203.             printf("      3.  input  information by Delete's Name\n");//按名字查找
  204.             printf("      0.   *EXIT*\n\n");
  205.             printf("\n   Please your choise:(0~3):");
  206.             do
  207.             {
  208.                     scanf("%d",&choise);
  209.                     if(choise<0||choise>3)
  210.                             printf("\n  input error ,please reinput(0~3):");
  211.             }while(choise<0||choise>3);
  212.             switch(choise)
  213.             {
  214.                     case 1:lookupNo(contacts,cntp);break;
  215.                     case 2:lookupNumber(contacts,cntp);break;            
  216.                     case 3:lookupNAME(contacts,cntp);break;
  217.                     case 0:break;
  218.             }
  219.             printf("\n");
  220.     }while(choise!=0);
  221. }
  222. void lookupNo(mobile_Phone contacts[],int *cntp)  //按序号查找
  223. {
  224.         int no,i=0;
  225.            printf("\n please input you want look up contact's No : ");  //请输入你要查找的联系人在手机里的序号
  226.         do{
  227.            scanf("%d",&no);
  228.            if(no<1||no>100)
  229.            printf("input error ,Please reinput:");
  230.         }while(no<1||no>100);        
  231.                i=no;
  232.                printf("        No     Name    telephone\n");
  233.                    printf("        %d    %s     %s   \n",i,contacts[i-1].name,contacts[i-1].number);
  234.     fflush(stdin);
  235.         getchar();
  236. }
  237. void lookupNumber(mobile_Phone contacts[],int *cntp)  //按电话号码查找联系人信息
  238. {
  239.         int n,k;
  240.         char num[12];        
  241.     do{                     
  242.               printf(" input you want look up contact's telephone :\t\t");
  243.           scanf("%s",&num);
  244.               for(k=0;k<*cntp;k++)
  245.               {        
  246.                   n=strcmp(num,contacts[k].number);                                 
  247.                   if(n==0)               
  248.                   break;                                          
  249.               }
  250.               if(n!=0) printf("No find such telephone number,please again ");   
  251.     }while(n!=0);
  252.            printf("        No    Name    telephone  \n");
  253.            printf("        %3d    %s     %s   \n",k+1,contacts[k].name,contacts[k].number);
  254.            fflush(stdin);
  255.            getchar();               
  256. }
  257. void lookupNAME(mobile_Phone contacts[],int *cntp)  //按名字查找
  258. {
  259.         int n,k,x;
  260.         char nam[12];        
  261.     do{  
  262.                     
  263.               printf("input you want look up contact's name :\t");
  264.           scanf("%s",&nam);
  265.               for(k=0;k<*cntp;k++)
  266.               {        
  267.                   n=strcmp(nam,contacts[k].name);                  
  268.                   x=n;
  269.                   if(x==0)               
  270.                   break;                                          
  271.               }
  272.               if(n!=0) printf("No find such person,please again");   
  273.      }while(n!=0);
  274.           x=k;
  275.           printf("        NO     Name   Telephone\n");
  276.           printf("        %3d    %s     %s   \n",x+1,contacts[x].name,contacts[x].number);
  277.           fflush(stdin);
  278.           getchar();               
  279. }
复制代码


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:366621 发表于 2018-7-7 15:06 | 只看该作者
这个不错  对文件进行操作  功能、函数设置合理      
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表