用C++编写通讯录
来源:优易学  2011-12-18 11:50:48   【优易学:中国教育考试门户网】   资料下载   IT书店

  #include<iostream.h>
   #include<string>
  #include<string.h>
  #include<fstream.h>
  #include<stdlib.h>
  struct Address
  {
  char name[20];
  char tel[20];
  char email[50];
  char relation[10];
  Address*next;
  };
  //判断email
  int Doe(char * s)
  {
  int a=1;
  if(*s!=’_’&&*s!=’/’&&*s!=’\\’&&*s!=’.’)
  {
  while(*s)
  {
  if(*s==’@’)
  {
  a=0;
  break;
  }
  s++;
  }
  if(*s==’\0’)
  {
  a=1;
  cout<<"没有@!"<<endl;
  }
  }
  else cout<<"首字母不能是:_、/、\\、.\n";
  return a;
  }
  //添加记录
  void CreatList(Address*&head) //引用参数是表头指针
  {
  Address*s,*p;
  cout<<"(添加记录一直到输入人名为0时结束。)"<<endl;
  s=new Address;
  cout<<"name :";
  cin>>s->name;
  cout<<"tel :";
  cin>>s->tel;
  do
  {
  cout<<"email :"<<endl;
  cin>>s->email;
  }
  while(Doe(s->email));
  cout<<"relation :";
  cin>>s->relation;
  while(strcmp(s->name,"0\0"))
  {
  if(head==NULL) //判断列表是否已经存在。若不存在,则首先自动新建一个链表。
  {
  cout<<"列表不存在,新建一个链表。"<<endl;
  head=s;
  }else
  {
  p->next=s;
  }
  p=s;
  s=new Address;
  cout<<"name :";
  cin>>s->name;
  cout<<"tel :";
  cin>>s->tel;
  do
  {
  cout<<"email :"<<endl;
  cin>>s->email;
  }
  while(Doe(s->email));
  cout<<"relation :";
  cin>>s->relation;
  }
  p->next=NULL;
  delete s; //释放名字为0的结点。
  return;
  }
  //显示记录
  void ShowList(Address*head)
  {
  cout<<"显示当前所有记录:\n";
  while(head)
  {
  cout<<head->name<<’\t’<<head->tel<<’\t’<<head->email<<’\t’<<head->relation<<’\n’;
  head=head->next;
  }
  cout<<endl;
  }
  //查询记录
  void FindPerson(Address*head)
  {
  char in_name[20];
  cout<<"输入要查询的名字:";
  cin>>in_name;

[1] [2] [3] 下一页

责任编辑:小草

文章搜索:
 相关文章
热点资讯
资讯快报
热门课程培训