您好,欢迎访问三七文档
1课程设计报告设计题目:单词及其释义的录入和读取学生姓名:专业:计算机科学与技术班级:10—01班学号:指导教师:完成日期:2011年07月01日合肥工业大学计算机与信息学院2(一)需求和规格说明设计一个程序,该程序输入一个英语单词和它的释义(应考虑一个单词可以有多个释义)。将单词和它的释义分别存放在文件word.dat和meaning.dat中。文件word.dat中存储的数据的结构为:classindex{public:charword[20];streamposoffset;};其中,数据成员offset用于记录单词word的释义在文件meaning.dat中的位置。用户输入一个单词,屏幕输出该单词的释义。(二)设计根据上述要求,该程序应分为两部分进行设计,主函数和被调用函数,而被调用函数中又可分为两部分:执行写入命令的write()函数、执行检查命令的check()函数。如图:choice1choice2(三)用户手册程序运行时,首先根据提示选择相关操作类型:录入单词或查询单词;若选择录入单词,则根据相关提示输入所要录入的单词及其释义,程序会自动将单词和释义分别保存在word.dat和meaning.dat中;若选择查询单词,则根据相关提示输入所要查询的单词:若程序事先保留有该单词的存档,则会出现其释义;若程序事先没有录入该单词的信息,则会出现“所查单词未录入”的提示。maincheckword.datatwritemeaning.dat3运行实例:进一步改进:目前程序中,不能进行输入释义而对单词的查询,而在大部分情况下,很多用户都需要英汉汉英双向功能的查询,所以在一定程度上限制了用户的需求。对于该问题可考虑在main函数中添加该功能的执行语气和重新定义一个可实现该功能的被调用函数。附录源程序#includeiostream#includefstream#includestringusingnamespacestd;classindex{public:charword[20];intoffset;4};intcount=0;voidwrite();voidcheck();voidmain(){ifstreamifs;stringtemp;ifs.open(word.dat);while(!ifs.eof()&&ifs){ifstemp;ifscount;}ifs.close();count++;while(1){intchoice;charyorn;cout请输入您的需求:1.录入单词2.查询单词endl;cinchoice;switch(choice){case1:write();break;case2:check();break;default:cout输入错误endl;}cout是否继续(Y/N)?endl;cinyorn;if(yorn=='n'||yorn=='N')break;}system(pause);}voidwrite(){charmeaning[50];charyorn;indexw;ofstreamofs;while(1){cout请输入单词:endl;cinw.word;w.offset=count;count++;ofstreamofs;ofs.open(word.dat,ostream::app);5ofsw.word;ofs;ofsw.offset;ofs\n;ofs.close();cout请输入单词释义,以;隔开endl;cinmeaning;ofs.open(meaning.dat,ostream::app);ofsmeaning;ofs\n;ofs.close();cout是否继续录入单词(Y/N)?endl;cinyorn;if(yorn=='n'||yorn=='N')break;}}voidcheck(){stringcheck;stringtemp;stringmeanning;intlocation=0;ifstreamifs;charyorn;while(1){cout请输入需要查找的单词endl;cincheck;ifs.open(word.dat);while(1){ifstemp;ifslocation;if(check==temp)break;if(ifs.eof()){location=-1;break;}}ifs.close();if(location==-1)cout所查单词未录入endl;else{ifs.open(meaning.dat);for(inti=0;ilocation;i++)6ifsmeanning;ifs.close();cout释义:meanningendl;}cout是否继续查询(Y/N)endl;cinyorn;if(yorn=='n'||yorn=='N')break;}}
本文标题:C++课程设计报告
链接地址:https://www.777doc.com/doc-6233813 .html