这是我c语言实训花了一周写的c语言程序,都是原创,希望大家多多指教
- /* Note:Your choice is C IDEx 向爱军 35 手机通讯录管理系统 */
- #include "stdio.h"
- #include "stdlib.h"
- #include "string.h"
- #include "windows.h"
- struct Mobile_Phone
- {
- char name[20];
- char number[20];
-
- };
- typedef struct Mobile_Phone mobile_Phone;
- void input(mobile_Phone contacts[],int *cntp);
- void display(mobile_Phone contacts[],int *cntp);
- void delet(mobile_Phone contacts[],int *cntp);//删除功能
- void deleteNo(mobile_Phone contacts[],int *cntp);
- void deleteNumber(mobile_Phone contacts[],int *cntp);
- void deleteAll(mobile_Phone contacts[],int *cntp);
- void deleteNAME(mobile_Phone contacts[],int *cntp);
- void lookup(mobile_Phone contacts[],int *cntp) ;//查找功能
- void lookupNo(mobile_Phone contacts[],int *cntp) ;
- void lookupNumber(mobile_Phone contacts[],int *cntp) ;
- void lookupNAME(mobile_Phone contacts[],int *cntp) ;
- void main()
- {
- mobile_Phone contacts[50];
- int count=0;
- int choise;
- MessageBox(NULL,"Welcome to mobile phone address book management system !","提示",MB_OK);
- do
- {
- system("cls");
- printf("*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n");
- printf("*=* Programming instruction *=*\n");
- printf("*=* Please save your contact list in time!*=*\n");
- printf("*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n");
- printf("\n\n\n\n **** MENU ******\n");
- printf(" 1. Input your cellphone contacts information \n"); //录入手机联系人信息
- printf(" 2. Delete the cellphone contacts information\n"); //删 除联系人信息
- printf(" 3. Display the cellphone contacts information\n"); //显示联系人信息
- printf(" 4. Look for mobile phone contacts information\n");//查找联系人的信息
- printf(" 0. *Exit*\n\n"); //退出
- printf("\n Please enter your choise:(0~4):");
- do
- {
- scanf("%d",&choise);
- if(choise<0||choise>5)
- printf("\n 输入错误,请重新选择(0~5):");
- }while(choise<0||choise>5);
- switch(choise)
- {
- case 1:input(contacts,&count);break;
- case 2:delet(contacts,&count);break;
- case 3:display(contacts,&count);break;
- case 4:lookup(contacts,&count);break;
- case 0:break;
- }
- printf("\n");
- }while(choise!=0);
- }
- void input(mobile_Phone contacts[],int *cntp) //录入联系人信息
- {
- int i;
- freopen("d:\\gushi.in","r",stdin);
- printf("Please enter your phone's Name and Telephone number: \n");
- for(i=0;i<16;i++)
- {
- scanf("%s %s",&contacts[i].name,&contacts[i].number);
- *cntp+=1;
- }
- freopen("con","r",stdin);
- }
- void display(mobile_Phone contacts[],int *cntp) //显示手机联系人信息
- {
- int i;
- printf(" No Name Telephone \n");
- for(i=0;i<*cntp;i++)
- {
- printf(" %d %s %s\n",i+1,&contacts[i].name,&contacts[i].number);
-
- }
- fflush(stdin);
- getchar();
- }
- void delet(mobile_Phone contacts[],int *cntp) //删除菜单
- {
- int choise;
- do
- {
- system("cls");
- printf("\n\n\n\n **** Delete Menu ******\n");
- printf(" 1. Delete information by number \n");//按电话号码删除联系人信息
- printf(" 2. Delete information by name \n"); //按名字删除
- printf(" 3. Delete all \n");
- printf(" 4. Delete information by No \n");//按序号删除
- printf(" 0. *EXIT*\n\n"); //退出
- printf("\n Please your choise:(0~4):");
- do
- {
- scanf("%d",&choise);
- if(choise<0||choise>4)
- printf("\n input error !,please reinput(0~4):");
- }while(choise<0||choise>4);
- switch(choise)
- {
- case 1:deleteNumber(contacts,cntp);break;
- case 2:deleteNAME(contacts,cntp);break;
- case 3:deleteAll(contacts,cntp);break;
- case 4:deleteNo(contacts,cntp);break;
- case 0:break;
- }
- printf("\n");
- }while(choise!=0);
- }
- void deleteNumber(mobile_Phone contacts[],int *cntp) //按电话号码删除
- {
- int n,t,k,j;
- char num[12];
- do{
- printf("input number information :\t");
- scanf("%s",&num);
- for(k=0;k<*cntp;k++)
- {
- n=strcmp(num,contacts[k].number);
- if(n==0)
- break;
- }
- if(n!=0) printf("No find such person ,please again");
- }while(n!=0);
- j=k;
- for(j;(j+1)<*cntp;j++)
- {
- contacts[j].number[12]=contacts[j+1].number[12];
- for(t=0;t<12;t++)
- {
- contacts[j].name[t]=contacts[j+1].name[t];
- }
- }
- *cntp=*cntp-1;
- }
- void deleteAll(mobile_Phone contacts[],int *cntp)
- {
-
- *cntp=0;
-
- }
- void deleteNAME(mobile_Phone contacts[],int *cntp) //按名字删除
- {
- int n,t,k,j,x;
- char nam[12];
- do{
- printf("input Name information :\t");
- scanf("%s",&nam);
- for(k=0;k<*cntp;k++)
- {
- n=strcmp(nam,contacts[k].name);
- x=n;
- if(x==0)
- break;
- }
- if(n!=0) printf("No find such person ,please again");
- }while(n!=0);
- j=k;
- for(j;(j+1)<*cntp;j++)
- {
- contacts[j].number[12]=contacts[j+1].number[12];
- for(t=0;t<12;t++)
- {
- contacts[j].name[t]=contacts[j+1].name[t];
- }
- }
- *cntp=*cntp-1;
- }
- void deleteNo(mobile_Phone contacts[],int *cntp) //按手机联系人的序号删除
- {
- int no,i=0,j,t;
- printf("\n please input you want look up contact's No : "); //请输入你要删除的联系人在手机里的序号
- do{
- scanf("%d",&no);
- if(no<1||no>500)
- printf("input error ,Please reinput:");
- }while(no<1||no>500);
- j=no-1;
- for(j;(j+1)<*cntp;j++)
- {
- contacts[j].number[12]=contacts[j+1].number[12];
- for(t=0;t<12;t++)
- {
- contacts[j].name[t]=contacts[j+1].name[t];
- }
- }
- *cntp=*cntp-1;
- }
- void lookup(mobile_Phone contacts[],int *cntp) //查找联系人菜单
- {
- int choise;
- do
- {
- system("cls");
- printf("\n\n\n\n **** Search Menu ******\n");
- printf(" 1. input information by Delete's No\n");//按手机联系人的序号查找
- printf(" 2. input information by Delete's Number\n");//按联系人电话号码查找
- printf(" 3. input information by Delete's Name\n");//按名字查找
- printf(" 0. *EXIT*\n\n");
- printf("\n Please your choise:(0~3):");
- do
- {
- scanf("%d",&choise);
- if(choise<0||choise>3)
- printf("\n input error ,please reinput(0~3):");
- }while(choise<0||choise>3);
- switch(choise)
- {
- case 1:lookupNo(contacts,cntp);break;
- case 2:lookupNumber(contacts,cntp);break;
- case 3:lookupNAME(contacts,cntp);break;
- case 0:break;
- }
- printf("\n");
- }while(choise!=0);
- }
- void lookupNo(mobile_Phone contacts[],int *cntp) //按序号查找
- {
- int no,i=0;
- printf("\n please input you want look up contact's No : "); //请输入你要查找的联系人在手机里的序号
- do{
- scanf("%d",&no);
- if(no<1||no>100)
- printf("input error ,Please reinput:");
- }while(no<1||no>100);
- i=no;
- printf(" No Name telephone\n");
- printf(" %d %s %s \n",i,contacts[i-1].name,contacts[i-1].number);
- fflush(stdin);
- getchar();
- }
- void lookupNumber(mobile_Phone contacts[],int *cntp) //按电话号码查找联系人信息
- {
- int n,k;
- char num[12];
- do{
- printf(" input you want look up contact's telephone :\t\t");
- scanf("%s",&num);
- for(k=0;k<*cntp;k++)
- {
- n=strcmp(num,contacts[k].number);
- if(n==0)
- break;
- }
- if(n!=0) printf("No find such telephone number,please again ");
- }while(n!=0);
- printf(" No Name telephone \n");
- printf(" %3d %s %s \n",k+1,contacts[k].name,contacts[k].number);
- fflush(stdin);
- getchar();
- }
- void lookupNAME(mobile_Phone contacts[],int *cntp) //按名字查找
- {
- int n,k,x;
- char nam[12];
- do{
-
- printf("input you want look up contact's name :\t");
- scanf("%s",&nam);
- for(k=0;k<*cntp;k++)
- {
- n=strcmp(nam,contacts[k].name);
- x=n;
- if(x==0)
- break;
- }
- if(n!=0) printf("No find such person,please again");
- }while(n!=0);
- x=k;
- printf(" NO Name Telephone\n");
- printf(" %3d %s %s \n",x+1,contacts[x].name,contacts[x].number);
- fflush(stdin);
- getchar();
- }
复制代码
|