给我看看这个有关电话号码查询的程序
#include<iostream>#include<string>
#define M 5
using namespace std;
typedef struct AddBook{
char name[10];
char num[20];
//int Num;
}AddBook;
int IntoNum(AddBook *l,int count)//输入函数
{
AddBook *head;
cout<<"请输入姓名:";
cin>>l[0].name;
cout<<"请输入电话号码:";
cin>>l[0].num;
count++;
head=&l[0];
return count;
}
int EraseNum( AddBook *l,int count)//删除函数
{
char Num[20];
AddBook *head;
if(count==0)
{
cout<<"电话本已空!"<<endl;
cin.get();//按任意键退出
}
else if(count!=0){
cout<<"请输入您要删除的电话号码:";
cin>>Num;
for(int i=0;i<count&& strcmp(Num,l[i].num)!=1;i++) ;
for( int j=i+1;j<count;j++)
l[j-1]=l[j];
cout<<"已经删除:"<<Num<<endl;
count--;
}
else {
cout<<"该电话号码不存在!"<<endl;
cin.get();
}
head=&l[0];
return count;
}
int FindNum( AddBook *l,int count)//查找函数
{
char Num[20];
AddBook *head;
if(count==0)
{
cout<<"电话本已空!"<<endl;
cin.get();//按任意键退出
}
else if(count!=0){
cout<<"请输入您要删除的电话号码:";
cin>>Num;
for(int i=0;i<count&&strcmp(Num,l[i].num)!=1;i++) ;
cout<<"姓名:"<<l[i].name<<" "<<l[i].num<<endl;
}
else {
cout<<"该电话号码不存在!"<<endl;
cin.get();
}
head=&l[0];
return count;
}
void OutBook(AddBook *l,int count)//打印函数
{
if (count==0)
cout<<"电话本已空!"<<endl;
else {
cout<<" 姓名 号码 "<<endl;
for(int i=0;i<count;i++)
cout<<l[i].name<<" "<<l[i].num<<endl;
}
}
int menu_select( )
{
char c;
cout<<"==================="<<endl;
cout<<"1.存入电话号码"<<endl;
cout<<"2.删除电话号码"<<endl;
cout<<"3.查找电话号码"<<endl;
cout<<"4.打印电话号码"<<endl;
cout<<"5.退出"<<endl;
cout<<"==================="<<endl;
cout<<endl<<"\3 请输入(1~5):";
do{
cin.get(c);
}while(c<'1'||c>'5');
return c-48;
}
int main( )
{
int choice;
AddBook L[M],*Head;
//*Head.Num=0;
//Head=&L[0];
int Count=0;
while(1){
choice=menu_select( );
{
switch(choice){
case 1: Count=IntoNum(Head,Count);
break;
case 2: Count=EraseNum(Head,Count);
break;
case 3: Count=FindNum(Head,Count);
break;
case 4: OutBook(Head,Count);
break;
case 5:exit(0);
}
}
}
return 0;
}