1、C+程序设计通讯录管理系统cpp C+信息管理#include#include#include#include#include/#includeusing namespace std;string ID;/具有唯一性class Personprotected: string No; /学号 string Age; char Name20; /姓名 char Sex10; /性别 string Tel; /联系方式 Person *next; public: Person(string ID,char *Name,char *Sex,string Age,string Tel) strcpy(t
2、his-Name,Name); strcpy(this-Sex,Sex); this-Tel=Tel; this-No=ID; this-Age=Age; friend class Manage;class Manageprivate: Person *person;public: Manage() person=0; Load(); Manage() Person *p; p=person; while(p) p=p-next; delete person; person=p; person=0; void Find(char Name20);/按姓名查找 void Find(string
3、ID);/按编号查找 void Add(); /添加加信息 void Delete(); /删除信息 void Modify(string ID); /修改信息 void Query(); /查询信息 void TJ(); /清除文件信息 void Save(); /保存数据 void Load(); /读入数据 void Look();/预览 void DesTory(); void Output(Person *p) couttt学号: Noendl; couttt姓名: Nameendl; couttt性别: Sexendl; couttt年龄: Ageendl; couttt联系电话:
4、 Telendl; coutendl; ;void Manage:Add() system(cls); Person *p,*p2; /新结点指针 string No,Age,Tel; char Name20,Sex10; char c; coutn* 新增学生通讯录 *n; /输入学生信息 coutNo; coutNo=No) break; else p1=p1-next; if(p1!=NULL) cout该学号已存在,是否修改该学生信息(Y/N) c; if(toupper(c)=Y) cout该学生信息为:endl; Find(No); coutendl; Modify(No); re
5、turn ; else return ; coutName; coutendl; coutSex; coutendl; coutAge; coutendl; coutTel; coutnext=0; /学生结点加入链表 if(person) /若已经存在结点 p2=person; while(p2-next) /查找尾结点 p2=p2-next; p2-next=p; /连接 else /若不存在结点(表空) person=p; /连接 system(cls); coutttt *添加成功*nendl; cout是否继续添加(Y/N) c; if(toupper(c)=Y) Add(); re
6、turn ; else return ;void Manage:Delete() /删除人员 system(cls); char c; string No; coutn* 删除信息 *n; coutNo; coutNo=No) break; else p2=p1; p1=p1-next; /删除结点 if(p1!=NULL)/若找到结点,则删除 cout所要删除的学生的信息如下:nendl; Output(p1); coutc; if(toupper(c)!=Y) return; / system(pause); if(p1=person) /若要删除的结点是第一个结点 person=p1-n
7、ext; delete p1; else /若要删除的结点是后续结点 p2-next=p1-next; delete p1; couttt*删除成功*n; cout是否继续删除(Y/N) c; if(toupper(c)=Y) Delete(); return ; else return ; else /未找到结点 coutNo=ID) break; else p1=p1-next; if(p1!=NULL)/若找到结点 system(cls); cout所要修改的学生的信息如下:nendl; Output(p1); do cout1. 修改姓名 2. 修改性别 3. 修改年龄 4. 修改联系
8、方式 5. 退出修改 nendl; cout请选择(1-5)要修改的信息nc; if(c!=5) coutp1-Name; break; case 2: cinp1-Sex; break; case 3: cinp1-Age; break; case 4: cinp1-Tel; break; default: break; while(c!=5); system(cls); coutt *修改成功*nendl; cout是否继续修改(Y/N): c; if(toupper(c)=Y) coutID; coutendl; Modify(ID); return ; else return ; el
9、se /未找到结点 cout未找到该学生!n; getch();/暂停 void Manage:Save() /数据写入到文件 ofstream fPerson(Person.txt,ios:out); char c; coutc; if(toupper(c)!=Y) return; Person *p=person; while(p) fPersonNo Name Sex Age Telnext; fPerson.close(); coutNoNameSexAgeTel; while(fPerson.good() p=new Person(No,Name,Sex,Age,Tel); p-ne
10、xt=0; /员工结点加入链表 if(person) /若已经存在结点 Person *p2; p2=person; while(p2-next) /查找尾结点 p2=p2-next; p2-next=p; /连接 else /若不存在结点(表空) person=p; /连接 fPersonNoNameSexAgeTel; fPerson.close(); void Manage:Find(string ID) Person *p1; p1=person; while(p1) if(p1-No=ID) break; else p1=p1-next; if(p1!=NULL) Output(p1
11、); else cout未找到该学生Name,Name)=0) count+; Output(p1); p1=p1-next; if(count) coutt查询成功!endl; coutn共找到 count 个名字为 Name 的同学nendl; else coutntt未找到该学生!nendl;void Manage:Query() char c; string ID,Tel; char Name20; do cout1. 按学号查找 2. 按名字查找 3. 按电话号码查找 4.退出查找c; / system(cls); coutendl; switch(c) case 1: coutID
12、; Find(ID); ; break; case 2: coutName; Find(Name); ; break; case 3: cout输入电话号码 TelTel; Find(Tel); ;break; case 4:break; default: cout输入有误 请重新输入!nendl; while(c!=1&c!=2&c!=3&c!=4); coutttt *查找成功*nendl; cout是否继续查找(Y/N) c; if(toupper(c)=Y) Query(); return ; else return ; system(pause);void Manage:Look()
13、 /设置字体颜色 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN); system(cls); Person *p1; int count=0; char c; p1=person; while(p1) coutID: Not姓名: Namenext; if(count!=0) coutntt预览成功! nendl; coutc; if(toupper(c)=Y) Query(); return; else retur
14、n ; else cout尚未创建通讯录,是否创建(Y/N)c; if(toupper(c)=Y) Add(); return; else return ; void Manage:DesTory() /设置字体为红色 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY | FOREGROUND_RED); char c; system(cls); coutnttt* 清除信息 *n; cout警告:n 清除通讯录信息会导致您保存的信息完全消失!nendl; cout是否决定清除通讯录信息(Y
15、/N): c; if(toupper(c)!=Y) return; cout请再次确认(Y/N)c; if(toupper(c)!=Y) return; else Person *p; p=person; while(p) p=p-next; delete person; person=p; person=0; / ofstream fPerson(person.txt); / fPerson.close(); system(pause);void Manage:TJ() Person *p1; int count=0,Boy=0,Girl=0; p1=person; while(p1) co
16、unt+; if(strcmp(p1-Sex,男)=0) Boy+; if(strcmp(p1-Sex,女)=0) Girl+; p1=p1-next; coutn总共有 count份通讯录nendl; cout男生: Boyt 女生: Girlnendl; system(pause);int main(void) Manage m; int c; do /设置字体为绿色 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY | FOREGROUND_GREEN); system(cls); c
17、out =endl; cout t 1.新增通讯录 t endl; cout t 2.删除通讯录 t endl; cout t 3.修改通讯录 t endl; cout t 4.查询详细信息 t endl; cout t 5.保存数据 t endl; cout t 6.预览信息 t endl; cout t 7.清除通讯录 t endl; cout t 8.统计 t endl; cout =endl; coutc; switch(c) case 1: m.Add(); break; case 2: m.Delete();break; case 3: system(cls); coutID; coutendl; m.Modify(ID); ;break; case 4: system(cls); m.Query(); ; break; case 5: m.Save(); break; case 6: m.Look(); break; case 7: m.DesTory(); break; case 8: m.TJ(); break; default: break; while(c!=0); char s; coutn是否要保存您的所有操作(Y/N): s; if(toupper(s)=Y) m.Save(); return 0;