您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 管理学资料 > C++课程设计电话簿
C++课程设计设计一个利用文件处理方式实现电话号码薄的C++程序系别电子信息系专业计算机科学与技术学号4080522姓名龚敏指导教师党群2010年6月22日东北大学秦皇岛分校毕业设计(论文)第页设计一个利用文件处理方式实现电话号码薄的C++程序!一.课程设计基本要求1功能选择可以用菜单实现请您选择1增加数据2修改数据3查询数据4删除数据0推出用户通过不同的数字进入不同的菜单2电话号码薄结构:序号、姓名、电话号码二、设计的思路1.建立ifstream/ofstream/fstream、输入、输出、输入输出流对象,建立ifndef,define预编命令,STRUCT数据。2.建立TelephoneBook类,构建PRIVATE私有成员和PUBLIC公有成员3.建TelephoneBook函数,建立输入输出文件,如何打开文件4.建立AddData函数,请输入序号、名字、电话号码构建电话号码本5.建立UpdateData函数,可以更改序号、名字、电话号码本功能项6.建立SearchData函数,制作输入查询电话号码的序号功能项7.建立DeleteData函数,制作输入可以删除的电话号码的序号8.建立Pack函数,写入电话号码二进制文件,写入电话号码本9.建立Run函数,用do.while界面制作界面10.建立一个主函数main(),#includetelephone_book.hvoidmain(void){TelephoneBookobj;obj.run();}11.运行主函数main,程序运行就可以了三、设计步骤1源代码#includeiostream#includestring#includeiomanip#includefstream#includecstdlibusingnamespacestd;classbook{public:book();//默认构造函数charinter_face();//首页voidadd_person();//添加数据东北大学秦皇岛分校毕业设计(论文)第页voiddel_person();//删除数据voidshow_all();//显示所有联系人voidalter();//修改数据voidselect();//查询数据voidsave_new();//保存新增加的联系人private:stringname;//姓名stringnumber;//电话号码stringstunum;//学号};book::book(){stunum=\0;name=\0;number=\0;}//首页charbook::inter_face(){system(cls);coutendl;cout\t\t★★★★★★★★★★★★★★★★★★★★★★★★★★endl\t\t※※endl\t\t※电话号码簿※endl\t\t※※endl\t\t※1.添加数据.4.修改数据.※endl\t\t※※endl\t\t※2.删除数据.5.查询数据.※endl\t\t※※endl\t\t※3.显示所有联系人.6.退出.※endl\t\t※※endl\t\t★★★★★★★★★★★★★★★★★★★★★★★★★★endlendl\t\t\t选择:;charchoose;cinchoose;fflush(stdin);returnchoose;}东北大学秦皇岛分校毕业设计(论文)第页//添加联系人voidbook::add_person(){coutendl根据下面提示输入新联系人信息endlendl学号:;cinstunum;fflush(stdin);cout姓名:;cinname;fflush(stdin);cout电话:;cinnumber;fflush(stdin);save_new();coutendlendl新联系人信息已经保存好!!!!!endlendl;system(pause);}//删除联系人voidbook::del_person(){ofstreamoutData(temp.txt,ios::out);ifstreaminData(pbook.txt,ios::in);//if(!outData||!inData){coutendl对不起!!!!找不到文件!!!!endl;system(pause);return;}stringsign;coutendl你要删除输入姓名或学号:;cinsign;stringstr1;boolflag=true;stringstr;while(inDatanamestunum){getline(inData,str);东北大学秦皇岛分校毕业设计(论文)第页if((sign==name)||(sign==stunum)){coutendl你想删除的联系人:endlendl;coutstr1endl;coutsetiosflags(ios::left)setw(17)namestunumstrendl;flag=false;break;}outDatasetiosflags(ios::left)setw(17)namestunumstrendl;}if(flag){coutendl对不起!!!联系人中没你找的人!!!!endlendl;}else{while(getline(inData,str)){outDatastrendl;}outData.close();inData.close();ofstreamout(pbook.txt,ios::out);ifstreamin(temp.txt,ios::in);if(!out||!in){coutendl对不起不能打开文件!!!endlendl;system(pause);return;}while(getline(in,str)){outstrendl;}东北大学秦皇岛分校毕业设计(论文)第页out.close();//in.close();coutendl这个人的信息已经从你的通迅录中删除!!!endlendl;}system(pause);}//显示所有联系人voidbook::show_all(){ifstreaminData(pbook.txt,ios::in);if(!inData){coutendl对不起!!!!没有找到文件!!!!!endl;system(pause);return;}boolflag=true;stringrecord;while(getline(inData,record)){if(flag){coutendl所有联系人信息如下:endl;}coutrecordendl;flag=false;}if(flag){coutendl你的通迅录中没有联系人!!!!!endlendl;}else{coutendl所有联系人已经全部显示出来!!!!!endlendl;}system(pause);东北大学秦皇岛分校毕业设计(论文)第页}//修改信息voidbook::alter(){ofstreamoutData(temp.txt,ios::out);ifstreaminData(pbook.txt,ios::in);//if(!outData||!inData){coutendl对不起!!!!找不到文件!!!!endl;system(pause);return;}stringsign;coutendl你要修改输入姓名或电话号:;cinsign;stringstr1;boolflag=true;stringstr;while(inDatanamestunum){getline(inData,str);if((sign==name)||(sign==stunum)){coutendl你想修改的联系人:endlendl;coutstr1endl;coutsetiosflags(ios::left)setw(17)namestunumstrendl;coutendl请根据下面提示修改信息:endl;cout学号:;cinstunum;fflush(stdin);cout姓名:;cinname;fflush(stdin);cout电话号:;cinnumber;fflush(stdin);save_new();flag=false;break;}东北大学秦皇岛分校毕业设计(论文)第页outDatasetiosflags(ios::left)setw(17)namenumberstrendl;}if(flag){coutendl对不起!!!联系人中没你找的人!!!!endlendl;}else{while(getline(inData,str)){outDatastrendl;}outData.close();inData.close();ofstreamout(pbook.txt,ios::out);ifstreamin(temp.txt,ios::in);if(!out||!in){coutendl对不起不能打开文件!!!endlendl;system(pause);return;}while(getline(in,str)){outstrendl;}out.close();in.close();coutendl这个人的信息已经在你的通迅录中修改!!!endlendl;}system(pause);}//查询联系人voidbook::select()东北大学秦皇岛分校毕业设计(论文)第页{ifstreaminData(pbook.txt,ios::in);if(!inData){coutendl对不起!!!!文件找不到!!!!endl;system(pause);return;}stringsign;coutendl输入你想查找的联系人的姓名或电话号码:;cinsign;fflush(stdin);stringstr1;boolflag=true;stringstr;while(inDatanamestunum){getline(inData,str);if((name==sign)||(stunum==sign)){coutendl你要查找的联系人是:endlendl;coutstr1endl;coutsetiosflags(ios::left)setw(17)namestunumstrendl;flag=false;system(pause);break;}}}voidbook::save_new(){ofstreamoutData(pbook.txt,ios::app);if(!outData){coutendl对不起!!!打开文件失败!!!!endlendl;system(pause);return;东北大学秦皇岛分校毕业设计(论文)第页}outDatasetiosflags(ios::left)setw(17)stunumsetw(16)namesetw(18)numberendl;outData.close();}enumpower{ADD='1',DEL='2',SHOW='3',Alter='4',Select='5',EN
本文标题:C++课程设计电话簿
链接地址:https://www.777doc.com/doc-3534774 .html