[优秀毕业设计精品] 简单通讯录程序.doc

上传人:仙人指路1688 文档编号:3932549 上传时间:2023-03-28 格式:DOC 页数:46 大小:76KB
返回 下载 相关 举报
[优秀毕业设计精品] 简单通讯录程序.doc_第1页
第1页 / 共46页
[优秀毕业设计精品] 简单通讯录程序.doc_第2页
第2页 / 共46页
[优秀毕业设计精品] 简单通讯录程序.doc_第3页
第3页 / 共46页
[优秀毕业设计精品] 简单通讯录程序.doc_第4页
第4页 / 共46页
[优秀毕业设计精品] 简单通讯录程序.doc_第5页
第5页 / 共46页
点击查看更多>>
资源描述

《[优秀毕业设计精品] 简单通讯录程序.doc》由会员分享,可在线阅读,更多相关《[优秀毕业设计精品] 简单通讯录程序.doc(46页珍藏版)》请在三一办公上搜索。

1、 C+语言程序设计课程设计设计题目 简单通讯录程序 专 业 计算机科学与技术 班 级 2010级 姓 名 学 号 指导教师 2011年6月20日目 录1. 设计目标32.设计思想33.类的设计34.程序源代码55.遇到的问题及解决方法56.调试运行结果67.总结8简单通讯录程序1.设计目标:1.1设计题目描述本程序能够针对用户所要查询的联系人,显示输出普通通讯录所能显示的部分信息,比如查找联系人,增加联系人,删除联系人,显示所有联系人 ,保存记录等。1.2设计目标本设计要求实现如下功能:(1)有对用户的输入信息进行判断,排除不合理输入信息的能力。(2)能显示所查联系人的所有信息。(3)能够删除

2、联系人,是删除一个还是所有人。(4)能够让用户多次查询,按照姓名或者号码。(5)修改联系人信息,可以选择自己想要修改的内容。(6)保存的信息显示在文本文件中。2.设计思想在本程序中, 因为所有的处理数据函数都是围绕着用户所输入的内容展开的。所以可以定义一个txl类,来包含用户所输入的信息,然后围绕这个类再来设定处理它的函数。因为要用到生日,所以程序又加了一个生日类。在程序设计初期,我首先使它能够基本完成部分的任务,然后针对各项任务再在细节上增强它的健壮性,可行性以及它的全面性。3.类的设计3.1 类的定义本程序定义了一个txl类。并将其定义放在了tongxunlu.h头文件中。在类中,包含私有

3、成员变量多个:name,address,number,sex,qq,year,bitth,month,day,Y,a,b。分别用于存储用户所要姓名,地址,电话号码,性别,QQ号,生日,年,月,日等信息;另外,定义了部分公共成员函数,用于实现特定的功能,具体如下:1char inter_face();/首页 2. void add_person();/添加联系人 3. void dels();/删除联系人 4. void del_all();/删除所有联系人 5. void del_sigle();/删除一个联系人 6. void show_all();/显示所有联系人 7. void alte

4、r();/修改信息 8void select();/查询联系人 9. void sel_name();/按姓名查找 10.void sel_number();/按号码查找 11.void save_new();/保存新增加的联系人 3.2 类的实现在此只涉及部分函数的实现细节,其他函数详看程序源代码:1、在添加联系人void add_person()中,通过将姓名,地址,QQ号,性别,电话号码,生日字符串,数组字符串,整型,从而可以通过多个if语句判断输入的准确性,来排除错误的或者是不存在的日期等不合理输入信息,并通过while语句允许用户重新输入原先输入错误的信息。等确定输入正确后,程序继续

5、。2、在删除联系人void dels()中,通过选择菜单进入所需要的内容中,删除一个联系人void del_sigle()和删除所有联系人void del_all(),由这些函数实现具体的功能。3、在查询联系人void select()中,通过选择菜单进入所要选的内容:按姓名查找void sel_name()和按号码查找void sel_number(),并由它们实现功能。4.在修改信息void alter()中,运用while,if,switch等语句对程序进行循环。同时还可以根据自己所要修改的信息进行修改,这样就比较简单和方便操作。4.程序源代码 #include #include #in

6、clude #include using namespace std; /出生日期类class birthdaypublic: birthday();/默认构造 int get_year();/获得出生的年份 int get_month();/获得出生的月份 int get_day();/获得出生的日 void set_birth();/设置出生日期private: int year; int month; int day;class txlpublic: int d; txl();/默认构造函数 char inter_face();/首页 void add_person();/添加联系人 v

7、oid dels();/删除联系人 void del_all();/删除所有联系人 void del_sigle();/删除一个联系人 void show_all();/显示所有联系人 void alter();/修改信息 void select();/查询联系人 void sel_name();/按姓名查找 void sel_number();/按号码查找 void save_new();/保存新增加的联系人 private: string name;/姓名 string address;/地址 string number;/电话号码 string sex;/性别 string qq;/QQ

8、号 string birth;/生日 int year; / int month; int day; char Y; / char a; char b;/生日类构造函数birthday:birthday() year = 0; month = 0; day = 0;/得到年份 int birthday:get_year() return year;/得到月份int birthday:get_month() return month;/得到日int birthday:get_day() return day;/设置出生日期void birthday:set_birth() coutyear; c

9、outendl; coutmonth; coutendl; coutday; coutendl;txl:txl():birth()/初始化 name = 0; address = 0; number = 0; sex = 0; qq = 0; year =0; month =0; day =0;/首页char txl:inter_face() system(cls); cout endl; sign1: coutt endl t | | endl t 通 讯 录 管 理 系 统 endl t | | endl t 1. 添加联系人 endl t | | endl t 2. 删除联系人 endl

10、 t | | endl t 3. 显示所有联系人 endl t | | endl t 4. 修改信息 endl t | | endl t 5. 查询联系人 endl t | | endl t 6.关闭系统 endl t | | endl t endl choose; fflush(stdin); return choose;/添加联系人void txl:add_person() cout endl 根据下面提示输入新联系人信息 endl endl name; fflush(stdin); coutendl; cout number; fflush(stdin); while(1) if(num

11、ber200000000000) cout该号码错误,请核对后重新输入。endl; cout number; fflush(stdin); coutendl; cout qq; fflush(stdin); coutendl; cout sex; fflush(stdin); coutendl; cout address; coutendl; fflush(stdin); coutyear; fflush(stdin); coutendl; coutmonth; fflush(stdin); while(1) if(month=13) cout该月份错误,请检查核对后重新输入。endl; co

12、utmonth; fflush(stdin); coutendl; coutday; fflush(stdin); while(1) if (day=32) cout该日期错误,请检查核对后重新输入。endl; coutday; fflush(stdin); cout确定要保存吗(Y/N)a; if(a=Y|a=y) save_new(); cout endl endl 新联系人信息已经保存好! endl; else cout没有保存endl; system(pause); /删除联系人 void txl:dels() char xz; while (1) system(cls); cout

13、endl t联系人信息 endl endl; cout endl tt1. 删除除一个联系人信息 endl endl tt2. 删除所有联系人信息 endl endl tt3. 返回首页 xz; switch (xz) case 1: del_sigle();/删除一个联系人信息 break; case 2: del_all();/删除所有联系人信息 break; case 3: return; exit(0); default: break; system(pause); void txl:del_sigle() /删除一个联系人 ofstream outData(temp.txt, ios

14、:out);/文件输入流 ifstream inData(pbook.txt, ios:in); /文件输出流 if (!outData | !inData) cout对不起!找不到文件! endl; system(pause); return; string sign; cout endl sign; string str1; string str3; bool flag = true; string str; while (inData name number) getline(inData, str);/从输入流中读取字符 if (sign=name) | (sign=number) c

15、out endl 你想删除的联系人 ; cout确定要删除吗(Y/N)a; if(a=Y|a=y) cout str1 endl; cout setiosflags(ios:left) setw(17) name number str endl; cout 联系人已经删除好! endl; flag=false; else cout没有删除endl; system(pause); break; outData setiosflags(ios:left) setw(17) name number str endl; while (getline(inData, str) outData str e

16、ndl; outData.close(); inData.close(); ofstream out(pbook.txt, ios:out); ifstream in(temp.txt, ios:in); if (!out | !in)/不是输入或不是输出流的 cout endl 对不起不能打开文件! endl endl; system(pause); return; while (getline(in, str) out str namenumber) cout此操作不可恢复,确定要全部删除吗(Y/N)b; if(b=Y|b=y) cout all endl; cout setiosflag

17、s(ios:left) setw(17) name number allendl; cout 联系人已经完全删除! endl; flag1=false; else cout没有删除endl; system(pause); break; return ; outData setiosflags(ios:left) setw(17) name number allendl; ofstream out(pbook.txt, ios:out); ifstream in(temp.txt, ios:in); while (getline(in,all) out allendl; out.close();

18、 in.close(); system(pause); /显示所有联系人void txl:show_all() ifstream inData(pbook.txt,ios:in); if (!inData) cout endl 对不起!没有找到文件! endl; system(pause); return; bool flag = true; string record; while (getline(inData, record) if (flag) cout endl 所有联系人信息如下: endl; cout setw(4)姓名 setw(11)地址 setw(13)QQ号 setw(1

19、3)电话号 setw(9)性别 setw(15) 生日的年 月 日 endl; coutrecordendl; flag = false; if (flag) cout endl 你的通迅录中没有联系人! endl endl; else cout endl 所有联系人已经全部显示出来! endl endl; system(pause);/修改信息void txl:alter() char choice; ofstream outData(temp.txt, ios:out); ifstream inData(pbook.txt, ios:in); if (!outData | !inData)

20、 cout endl 对不起!找不到文件! endl; system(pause); return; string sign; cout endl sign; string str1; bool flag = true; string str; while (inData name number) getline(inData, str); if (sign=name) | (sign=number) cout endl 你想修改的联系人: endl endl; cout str1 endl; cout setiosflags(ios:left) setw(17) name number st

21、r endl; sign: cout endl 请根据下面提示修改信息 : endl; coutntt & 1 姓名 & endl; coutntt & 2 电话号码 & endl; coutntt & 3 QQ & endl; coutntt & 4 性别 & endl; coutntt & 5 地址 & endl; coutntt & 6 生日 & endl; coutntt & 0 退出 & choice; system(cls); switch (choice) case 1: cout 姓名: name; fflush(stdin); break; case 2: cout 电话号码

22、: number; fflush(stdin); break; case 3: cout QQ: qq; fflush(stdin); break; case 4: cout 性别: sex; fflush(stdin); break; case 5: cout地址:address; fflush(stdin); break; case 6: coutyear; fflush(stdin); coutendl; coutmonth; fflush(stdin); coutendl; coutday; fflush(stdin); coutendl; break; case 0: return;

23、 exit(0); default: break; save_new(); flag = false; cout确定要修改吗(Y/N)a; if(a=Y|a=y) cout endl endl 联系人已经修改好! endl; outData setiosflags(ios:left) setw(17) name number str endl; goto sign; else cout没有修改endl; goto sign; system(pause); if (flag) cout endl 对不起!联系人中没你找的人! endl endl; else while (getline(inDa

24、ta, str) outData str endl; outData.close(); inData.close(); ofstream out(pbook.txt, ios:out); ifstream in(temp.txt, ios:in); if (!out | !in) cout endl 对不起不能打开文件! endl endl; system(pause); return; while (getline(in, str) out str endl; out.close(); in.close(); system(pause); /查询联系人void txl:select() char yz; while (1)

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 办公文档 > 其他范文


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号