1、通讯录管理软件C+编程#include #include #include #include #include /文本操作默认信息保存在工程文件夹下#define N 40 /定义基本信息的长度int t;using namespace std;char nameN; /全局变量定义char addressN;char phoneN;char codeN;char emailN;class hum private: char nameN; /基础类的定义 char addressN; char phoneN; char codeN; char emailN; public: hum *next
2、; hum() hum() friend class List;class List:public hum /私有信息封装private: hum *head,*tail;public: List(); List(); void CreatList(); void set(char *name= .,char *address= .,char *phone= .,char *code= .,char *email= .); void Delete(int t); void Change(char *name); void Find(int x); void filecin(); void fi
3、leout(); void showall();List:List() head=tail=NULL;List:List() hum *p; if(head) p=head; head=head-next; delete p; void List:set(char *name,char *address,char *phone,char *email,char *code) /文本导入时调用的构造函数 hum *p=new hum; strcpy(p-name,name); strcpy(p-address,address); strcpy(p-phone,phone); strcpy(p-c
4、ode,code); strcpy(p-email,email); p-next=NULL; if(head=NULL) head=p; else tail-next=p; tail=p;void List:CreatList() /默认的构造函数 int flag=1; hum *p=new hum; strcpy(p-name, .); strcpy(p-address, .); strcpy(p-phone, .); strcpy(p-code, .); strcpy(p-email, .); getchar(); coutname,name); coutaddress,address)
5、; coutphone,phone); coutcode,code); coutemail,email); hum *q=head; while(q) /判断是否以存在相同的信息 if(strcmp(q-name,name)=0&strcmp(q-address,address)=0&strcmp(q-phone,phone)=0&strcmp(q-code,code)=0&strcmp(q-email,email)=0) flag=0; coutnext; if(flag) ofstream outfile; outfile.open(cin.txt,ios:app); /将新数据添加的文本
6、末尾 if(!outfile) /调试期间怕出错添加的判断函数 cerrFile open or create error!endl; exit(1); outfileendlname address phone code email; outfile.close(); p-next=NULL; if(head=NULL) head=p; else tail-next=p; tail=p; cout信息已经存入通讯录。n; void List:Delete(int t) /删除函数 coutshuru; hum *p=head,*q; char flag; while(p) if(strcmp
7、(p-name,shuru)=0&t=1)|(strcmp(p-phone,shuru)=0&t=2)|(strcmp(p-code,shuru)=0)&t=3) cout确定要删除该信息y OR nflag; if(flag=Y|flag=y) if(p=head) head=p-next; else q-next=p-next; delete p; break; break; q=p; p=p-next; ofstream outfile; outfile.open(cin.txt,ios:trunc); if(!outfile) /调试期间怕出错添加的判断函数 cerrFile open
8、 or create error!next) /链表输出信息至文本 outfilename address phone code emailnext; /将删除后的信息存入cin.txt文件中保存 outfilename address phone code email; outfile.close(); system(cls); /每次程序的最终结果都清屏一次,并给出程序最后的结果,方便使用者查看 cout程序运行结果:n; if(flag=Y|flag=y) cout已删除成功!nendl; else if(flag!=Y|flag!=y) cout信息成员未删除.n; else cout
9、通讯录无此人!nname,name)=0) cout姓名: nname 地址: address 电话: phone 邮编: code E-mail:emailendl; getchar(); cout-无需修改选项直接回车!-n; /对于无需修改的项目不需要重复填入,方便使用者 cout输入要修改成的地址:; gets(address); cout输入要修改成的电话:; gets(phone); cout输入要修改成的邮编:; gets(code); coutaddress,address); if(strcmp(code,)!=0) strcpy(p-code,code); if(strcm
10、p(email,)!=0) strcpy(p-email,email); if(strcmp(phone,)!=0) strcpy(p-phone,phone); flag=1; coutnext; hum *q=head; ofstream outfile; outfile.open(cin.txt,ios:trunc); if(!outfile) /调试期间怕出错添加的判断函数 cerrFile open or create error!next) /链表输出信息至文本 outfilename address phone code emailnext; /将删除后的信息存入cin.txt文
11、件中保存 outfilename address phone code email; outfile.close(); system(cls); coutendl; if(flag=0) cout程序最终结果:n; cout通讯录不包含这个人!nendl; else cout程序最终结果:n; cout姓名: nameendl 地址: address 电话: phone 邮编: code E-mail:emailendl; cout信息修改成功!nendl; coutendlendl; void List:Find(int x) /1、按名字查找2、按电话查找3、按邮编查找4、按E-mail查
12、找 char shuruN; coutshuru; int flag=0; hum *p=head; while(p) /查找时4种条件,方便使用者。 if(strcmp(p-name,shuru)=0&x=1)|(strcmp(p-phone,shuru)=0&x=2)|(strcmp(p-code,shuru)=0)&x=3|(strcmp(p-email,shuru)=0&x=4) system(cls); coutendl; cout程序最终结果:n查找人:n; cout姓名: name 地址: address 电话: phone 邮编: code E-mail:emailnext;
13、coutendl; if(flag=0) system(cls); cout程序最终结果:n; cout通讯录不包含这个人!nendl; coutendlendl; void List:filecin() /默认导入文本信息至程序 ifstream txtfile; txtfile.open(cin.txt); if(!txtfile) cerrtxt open error!nameaddressphonecodeemail; List:set(name,address,phone,code,email); txtfile.close(); void List:fileout() /导出信息至
14、文本 fstream outfile; outfile.open(cout.txt,ios:out|ios:trunc); if(!outfile) /调试期间怕出错添加的判断函数 cerrFile open or create error!endl; exit(1); hum *p=head; while (p) /链表输出信息至文本 outfilename address phone code emailnext; system(cls); coutendl; cout程序最终结果:n; printf(导出信息至文本成功!n); outfile.close(); coutendl; voi
15、d List:showall() /链表输出各个成员信息 hum *p=head; while(p) cout姓名:nameendl 地址:address 电话:phone 邮编:email E-mail:codenext; int main() List TXL; int n=1; /n表示要输入的操作步骤 TXL.filecin(); /程序打开默认导入记录在cin.txt中的文件内容。 while(n) cout 欢迎使用通信簿!n; /用户友好界面 cout 请选择以下操作!n; cout !-1-添加通讯录信息n; cout !-2-修改通讯录信息n; cout !-3-删除通讯录信
16、息n; cout !-4-查找通讯录信息n; cout !-5-输出通讯录信息n; cout !-6-文本导出信息n; cout !-7-退出通讯录n; coutn; switch(n) case 1: TXL.CreatList(); /在程序运行时添加成员 break; case 2: coutname; TXL.Change(name); break; case 3: cout1-根据姓名删除信息n; /不同的删除方式。 cout2-根据电话删除信息n; coutt; TXL.Delete(t); break; case 4: cout查找方式endl; /不同的查找方式。 cout-1、按名字查找 n-2、按电话查找 n-3、按邮编查找 n-4、按E-mail查找endl; coutx; TXL.Find(x); break; case 5: TXL.showall(); break; case 6: TXL.fileout();break; /文件导出最终结果 case 7: n=0; break; default: cout操作错误!endl;break; coutendl; return 0;
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1