资源描述:
《通讯录管理软件c++编程》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#include#include#include#include#include//文本操作默认信息保存在工程文件夹下#defineN40//定义基本信息的长度intt;usingnamespacestd;charname[N];//全局变量定义charaddress[N];charphone[N];charcode[N];charemail[N];classhum{private:charname[N];//基础类的定义charaddress
2、[N];charphone[N];charcode[N];charemail[N];public:hum*next;hum(){}~hum(){}friendclassList;};classList:publichum//私有信息封装{private:hum*head,*tail;public:List();~List();voidCreatList();voidset(char*name=".",char*address=".",char*phone=".",char*code=".",char*email=".");voidDe
3、lete(intt);voidChange(char*name);voidFind(intx);voidfilecin();voidfileout();voidshowall();};List::List(){head=tail=NULL;}List::~List(){hum*p;if(head){p=head;head=head->next;deletep;}}voidList::set(char*name,char*address,char*phone,char*email,char*code)//文本导入时调用的构造函数{hum
4、*p=newhum;strcpy(p->name,name);strcpy(p->address,address);strcpy(p->phone,phone);strcpy(p->code,code);strcpy(p->email,email);p->next=NULL;if(head==NULL)head=p;elsetail->next=p;tail=p;}voidList::CreatList()//默认的构造函数{intflag=1;hum*p=newhum;strcpy(p->name,".");strcpy(p->ad
5、dress,".");strcpy(p->phone,".");strcpy(p->code,".");strcpy(p->email,".");getchar();cout<<"请输入学生姓名:";gets(name);if(strcmp(name,"")!=0)strcpy(p->name,name);cout<<"请输入家庭地址:";gets(address);if(strcmp(address,"")!=0)strcpy(p->address,address);cout<<"请输入联系电话:";gets(phone);if(s
6、trcmp(phone,"")!=0)strcpy(p->phone,phone);cout<<"请输入邮编:";gets(code);if(strcmp(code,"")!=0)strcpy(p->code,code);cout<<"请输入电子邮件:";gets(email);if(strcmp(email,"")!=0)strcpy(p->email,email);hum*q=head;while(q){//判断是否以存在相同的信息if(strcmp(q->name,name)==0&&strcmp(q->address,addr
7、ess)==0&&strcmp(q->phone,phone)==0&&strcmp(q->code,code)==0&&strcmp(q->email,email)==0){flag=0;cout<<"已存在相同信息!存入失败!";break;}q=q->next;}if(flag){ofstreamoutfile;outfile.open("cin.txt",ios::app);//将新数据添加的文本末尾if(!outfile)//调试期间怕出错添加的判断函数{cerr<<"Fileopenorcreateerror!"<
8、name<<""<address<<""<phone<<""<code<<""<email;outfile.close()