第十五周项目3-简易中英词典
2014-06-03 12:23
190 查看
/* *程序的版权和版本声明部分: *Copyright(c)2014,烟台大学计算机学院学生 *All rights reserved. *文件名称: *作者:田成琳 *完成日期:2014 年 6 月 3 日 *版本号:v1.0 *对任务及求解方法的描述部分: *输入描述: 英语单词 *问题描述:输出英语单词对应的意思 *程序输出:单词意思 *问题分析: *算法设计: */ #include <iostream> #include <cstdlib> #include <fstream> #include <string> using namespace std; class Word { public: Word() {} string getEnglish(); string getChinese(); string getWord_Class(); friend istream & operator >>(istream &in,Word &w); friend ostream & operator <<(ostream &out,Word &w); private: string english; string chinese; string word_class; }; string Word::getEnglish() { return english; } string Word::getChinese() { return chinese; } string Word::getWord_Class() { return word_class; } istream & operator >>(istream &in,Word &w) { in>>w.english>>w.chinese>>w.word_class; return in; } ostream & operator <<(ostream &out,Word &w) { out<<w.getChinese()<<"\t"<<w.getWord_Class()<<endl; return out; } int main() { Word word[8000]; string english; int i=0,head,end,middle; ifstream infile ("D:\\dictionary.txt",ios::in); if(!infile) { cerr<<"Open Error!"<<endl; exit(1); } while(!infile.eof()) infile>>word[i++]; infile.close(); while(cin>>english&&english!="0000") { head=0; end=i; middle=(head+end)/2; while(head<end&&word[middle].getEnglish()!=english) { if(word[middle].getEnglish()<english)//要查的词在后半部分 head=middle+1; if(word[middle].getEnglish()>english)//要查的词在前半部分 end=middle-1; middle=(head+end)/2;//继续二分 } if(word[middle].getEnglish()!=english) cout<<"查无此词!"<<endl; else cout<<word[middle]; } return 0; }
运行结果:
心得体会:。
相关文章推荐
- 第十五周项目5--中英词典
- 第十五周项目五电子词典
- 第十五周上机任务项目2-杨辉三角
- 用STL做的简易英汉词典(VS2005下编写)
- 搭建简易MVVM项目
- 第十五周项目3—成绩单
- 第十五周项目2 洋灰三角
- 第十五周上机项目1:折腾二维数组
- 搭建简易MVVM项目
- 第十五周项目1——二维数组初体验
- 第十五周项目1 折腾二维数组
- 用STL做的简易英汉词典(VS2005下编写)
- [PySide]在简易在线词典中使用多线程
- Android 项目开发 基于Web Service 服务的中英翻译软件(四)使用Sqlite “辅助” Web Service
- 从零开始做基于 SharePoint 的简易项目管理应用
- Android 项目开发 基于Web Service 服务的中英翻译软件(一)功能介绍
- MOSS项目开发 周记(第十五周)
- 简易电话薄的项目
- 开源项目之跨平台的词典软件 GoldenDict
- 第十五周上机项目3:带姓名的成绩单