C++编写通讯录,实现录入、显示、删除记录、查询记录
设一个通信录由以下几项数据信息构成:数据项类型姓名字符串地址字符串邮政编码字符串电话号码字符串电子邮件字符串实现一个通讯录程序。实现功能:录入、显示、删除记录、查询记录等...
设一个通信录由以下几项数据信息构成:
数据项 类型
姓名 字符串
地址 字符串
邮政编码 字符串
电话号码 字符串
电子邮件 字符串
实现一个通讯录程序。实现功能:录入、显示、删除记录、查询记录等功能。 展开
数据项 类型
姓名 字符串
地址 字符串
邮政编码 字符串
电话号码 字符串
电子邮件 字符串
实现一个通讯录程序。实现功能:录入、显示、删除记录、查询记录等功能。 展开
展开全部
#include<iostream.h>
#include<string.h>
#include <fstream.h>
#include <stdlib.h>
#include<conio.h>
struct Address //说明结构
{
char name[20];
char Tel[20];
char Email[20];
char Relation[20];
Address *next ;
} ;
Address allone[3] ;
void Createlist(Address *&head) //建立链表函数
{ Address *s,*p;
s=new Address;
int a=1;
while ( a==1)
{
cout<<"请输入姓名:";
cin>>s->name;
cout<<"请输入电话号:";
cin>>s->Tel;
cout<<"请输入Email:";
cin>>s->Email;
cout<<"请输入与您关系:";
cin>>s->Relation;
{
if ( head == NULL ) head = s ;
else p->next = s ;
}
p = s ;
s = new Address ;
cout<<"是否继续输入,输入按1不输入按0 :"; //判断是否继续输入
cin>>a;
}
p->next = NULL;
delete s;
return ;
}
void showlist( Address *head ) //显示链表
{ cout << "您的通信录为: "<< '\n';
while( head )
{
cout << head->name << '\t';
cout <<head->Tel<<'\t';
cout << head->Email << '\t';
cout << head->Relation << '\n';
head = head->next ;
}
cout << endl ;
}
void Chayuelist(Address *head) //查阅链表
{
char chayue[20];
cout<<"请输入你所要查阅的姓名:";
cin>>chayue;
while( head )
{
if(strcmp(head->name,chayue)==0)
{
cout << head->name << '\t';
cout <<head->Tel<<'\t';
cout << head->Email << '\t';
cout << head->Relation << '\n';
}
head = head->next ;
}
cout << endl ;
}
void baocun(Address *head)//保存
{
ofstream outstuf ;
outstuf.open("c:\\save.txt", ios::out ) ;
if ( !outstuf )
{
cerr << "File could not be open." << endl ;
abort();
}
while( head )
{
outstuf << head->name << ' '<< head->Tel<<' '<< head->Email << ' '<< head->Relation << '\n' ;
cout << "? " ;
head = head->next ;
}
}
void tianjia(Address *&head) //添加
{
Address *s;
s=new Address;//生成新结点
cout<<"\n\t\t请输入姓名:";
cin>>s->name;
cout<<"\n\t\t请输入电话号:";
cin>>s->Tel;
cout<<"\n\t\t请输入Email:";
cin>>s->Email;
cout<<"\n\t\t请输入与您关系:";
cin>>s->Relation;
cout<<"\n\t\t你已经添加成功";
s->next=head;
head=s;
return ;
}
void main() //主函数
{ system("cls");
int gongnenghao;
Address*head = NULL ;
cout<<"*************************本程序为通讯录管理系统***********************"<<endl;
while(gongnenghao<=11)
{ system("cls");
cout<<" 请选择你所要实现的功能的编号"<<endl;
cout<<"\n\t\t1.写记录"<<endl;
cout<<"\n\t\t2.显示记录"<<endl;
cout<<"\n\t\t3.查阅记录"<<endl;
cout<<"\n\t\t5.删除记录"<<endl;
cout<<"\n\t\t8.保存记录"<<endl;
cout<<"\n\t\t9.添加记录"<<endl;
cout<<"\n\t\t111.退出"<<endl;
cin>>gongnenghao;
if(gongnenghao==1)
{
Createlist(head);
}
if (gongnenghao==2)
{
showlist(head);
}
if (gongnenghao==3)
{
Chayuelist(head);
}
if (gongnenghao==8)
{
baocun(head);
}
if(gongnenghao>9)
{
cout<<"退出";
}
if (gongnenghao==9)
{
tianjia(head);
}
}
}
#include<string.h>
#include <fstream.h>
#include <stdlib.h>
#include<conio.h>
struct Address //说明结构
{
char name[20];
char Tel[20];
char Email[20];
char Relation[20];
Address *next ;
} ;
Address allone[3] ;
void Createlist(Address *&head) //建立链表函数
{ Address *s,*p;
s=new Address;
int a=1;
while ( a==1)
{
cout<<"请输入姓名:";
cin>>s->name;
cout<<"请输入电话号:";
cin>>s->Tel;
cout<<"请输入Email:";
cin>>s->Email;
cout<<"请输入与您关系:";
cin>>s->Relation;
{
if ( head == NULL ) head = s ;
else p->next = s ;
}
p = s ;
s = new Address ;
cout<<"是否继续输入,输入按1不输入按0 :"; //判断是否继续输入
cin>>a;
}
p->next = NULL;
delete s;
return ;
}
void showlist( Address *head ) //显示链表
{ cout << "您的通信录为: "<< '\n';
while( head )
{
cout << head->name << '\t';
cout <<head->Tel<<'\t';
cout << head->Email << '\t';
cout << head->Relation << '\n';
head = head->next ;
}
cout << endl ;
}
void Chayuelist(Address *head) //查阅链表
{
char chayue[20];
cout<<"请输入你所要查阅的姓名:";
cin>>chayue;
while( head )
{
if(strcmp(head->name,chayue)==0)
{
cout << head->name << '\t';
cout <<head->Tel<<'\t';
cout << head->Email << '\t';
cout << head->Relation << '\n';
}
head = head->next ;
}
cout << endl ;
}
void baocun(Address *head)//保存
{
ofstream outstuf ;
outstuf.open("c:\\save.txt", ios::out ) ;
if ( !outstuf )
{
cerr << "File could not be open." << endl ;
abort();
}
while( head )
{
outstuf << head->name << ' '<< head->Tel<<' '<< head->Email << ' '<< head->Relation << '\n' ;
cout << "? " ;
head = head->next ;
}
}
void tianjia(Address *&head) //添加
{
Address *s;
s=new Address;//生成新结点
cout<<"\n\t\t请输入姓名:";
cin>>s->name;
cout<<"\n\t\t请输入电话号:";
cin>>s->Tel;
cout<<"\n\t\t请输入Email:";
cin>>s->Email;
cout<<"\n\t\t请输入与您关系:";
cin>>s->Relation;
cout<<"\n\t\t你已经添加成功";
s->next=head;
head=s;
return ;
}
void main() //主函数
{ system("cls");
int gongnenghao;
Address*head = NULL ;
cout<<"*************************本程序为通讯录管理系统***********************"<<endl;
while(gongnenghao<=11)
{ system("cls");
cout<<" 请选择你所要实现的功能的编号"<<endl;
cout<<"\n\t\t1.写记录"<<endl;
cout<<"\n\t\t2.显示记录"<<endl;
cout<<"\n\t\t3.查阅记录"<<endl;
cout<<"\n\t\t5.删除记录"<<endl;
cout<<"\n\t\t8.保存记录"<<endl;
cout<<"\n\t\t9.添加记录"<<endl;
cout<<"\n\t\t111.退出"<<endl;
cin>>gongnenghao;
if(gongnenghao==1)
{
Createlist(head);
}
if (gongnenghao==2)
{
showlist(head);
}
if (gongnenghao==3)
{
Chayuelist(head);
}
if (gongnenghao==8)
{
baocun(head);
}
if(gongnenghao>9)
{
cout<<"退出";
}
if (gongnenghao==9)
{
tianjia(head);
}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询