#include
using namespace std;
#define null 0
struct notelist
{
char num[5]; // 编号
char name[9]; // 姓名
char sex[3]; // 性别
char phone[13]; // 电话
char addr[31]; // 地址
notelist *next;
};
int n;
bool find1(notelist *head,char num[]);
notelist *creat()//通讯录的建立
{char i;
notelist *head;
notelist*p1,*p2;
n=0;
p1=p2=new notelist;
p1->next=null;
head=null;
/*cout<<"请输入通讯录信息的条数:";
cin>>i;*/
/*cin.clear(); //清空状态和缓冲区 ,判断输入正确与否
cin.sync();
for(int j=1;j<100000;j++)
k=i-j;
if(k==0)
cout<
{cout<<"输入错误"<
do
{
cout<<"请输入第"<
cin>>p1->num;
while(find1(head,p1->num))
{
cout<<"-----此编号已存在!请重新输入!-----"<
cout<<"请输入编号:";
cin>>p1->num;
}
cout<<"请输入姓名:";
cin>>p1->name;
cout<<"请输入性别:";
cin>>p1->sex;
cout<<"请输入电话号码:";
cin>>p1->phone;
cout<<"请输入地址:";
cin>>p1->addr;
n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=new notelist;
p1->next=null;
cout<<"是否继续输入通讯录讯息:(是请按y---否请按其它任意键)";
cin>>i;
}
while(i=='y'||i=='Y');
p2->next=null;
return(head);
}
bool find1(notelist *head,char num[])//查询相同编号
{notelist *p1,*p2;
if(head==null)
{return 0;}
p1=head;
while((strcmp(num,p1->num)!=0)&&p1->next!=null)
{p2=p1;p1=p1->next;}
if(strcmp(num,p1->num)==0)
{
return 1;
}
else return 0;
}
void print(notelist*head)//通讯录信息的输出
{
notelist *p;
cout<
if(head!=null)
do
{
cout<
}
while(p!=null);
}
void find(notelist *head,char num[])//查询
{notelist *p1,*p2;
if(head==null)
{cout<<"没记录"<
while((strcmp(num,p1->num)!=0)&&p1->next!=null)
{p2=p1;p1=p1->next;}
if(strcmp(num,p1->num)==0)
{
cout<<"编号"<<" "<<"姓名"<<" "<<"性别"<<" "<<"电话"<<" "<<"地址"<
else cout<<"找不到该编号:";
}
notelist *del(notelist *head,char num[])//通讯录信息的删除
{notelist *p1,*p2;
if(head==null)
{cout<<"没记录"<
while(strcmp(num,p1->num)!=0&&p1->next!=null)
{p2=p1;p1=p1->next;}
if(strcmp(num,p1->num)==0)
{if(p1==head)head=p1->next;
else p2->next=p1->next;
cout<<"编号为"<
}
else cout<<"找不到该编号:";
return(head);
}
notelist *insert(notelist *head,notelist *stud)//通讯录信息的添加
{
notelist *p0,*p1,*p2;
p1=head;
p0=stud;
if(head==null)
{head=p0;p0->next=null;}
else
{
while(strcmp(p0->num,p1->num)>0&&(p1->next!=null))
{
p2=p1;
p1=p1->next;}
if(strcmp(p0->num,p1->num)<0)
{if(head==p1)head=p0;
else p2->next=p0;
p0->next=p1;}
else
{p1->next=p0;p0->next=null;}
}
n=n+1;
return(head);
}
int main()
{
int s,d, a,j=0;
notelist *head,*stu;
char c, i,k[5],del_num[5];
char y;
do
{
cout<<"*****************请选择:******************"<
switch(c)
{case '1':
head=creat();
print(head);
break;
case '2':
cout<
do
{
find(head,k);
cout<
}
while(strcmp(k,"exit")!=0);
break;
case '3':
cout<
while(strcmp(del_num,"exit")!=0)
{head=del(head,del_num);
print(head);
cout<<"请输入要删除的编号:(结束请输入exit)";
cin>>del_num;
}
break;
case '4':
/*cout<
do
{
cout<
cout<<"请输入编号:";
cin>>stu->num;
while(find1(head,stu->num))//判断编号是否存在
{
cout<<"-----此编号已存在!请重新输入!-----"<
cout<<"请输入编号:";
cin>>stu->num;
}
cout<<"请输入姓名:";
cin>>stu->name;
cout<<"请输入性别:";
cin>>stu->sex;
cout<<"请输入电话号码:";
cin>>stu->phone;
cout<<"请输入地址:";
cin>>stu->addr;
head=insert(head,stu);
print(head);
j=j+1;
cout<<"是否继续输入通讯录讯息:(是请按y---否请按其它任意键)";
cin>>i;
}
while(i=='y'||i=='Y');
break;
case '5':break;
default: cout<<"输入错误!"<
cout<<"是否继续操作:(是请按y---退出请按其它任意键)"<
}
while(y=='y'||y=='Y');
return 0;
}
30分,也叫重金.
这点程序写个雏形也得写几个小时.
现在程序员同志们越来越便宜了.