第十四周项目3-OOP版电子词典
2015-06-08 15:20
399 查看
/* *Copyright (c) 2014, 烟台大学计算机学院 *All rights reserved. *文件名称:week14-3.cpp *作者:高赞 *完成日期: 2015 年 6 月 8 日 *版本号:v1.0 * */ #include <iostream> #include <cstring> #include <fstream> #include <cstdlib> using namespace std; class Word { private: string english; string chinese; string wordclass; public: Word() {} void getWord(string a,string b,string c) { english=a; chinese=b; wordclass=c; } string getenglish() { return english; } string getchinese() { return chinese; } string getwordclass() { return wordclass; } }; int main() { string word,a,b,c; Word w[8000]; int i=0,sum=0; ifstream infile("dictionary.txt",ios::in); if(!infile) { cerr<<"未找到该文件!"<<endl; exit(1); } while (!infile.eof()) { infile>>a>>b>>c; w[i].getWord(a,b,c); ++i; ++sum; } infile.close(); do { int middle, low=0,high=sum; cout << "输入要查询的单词:" << endl; cin >> word; getchar(); middle=(low+high)/2; while(word!=w[middle].getenglish()) { if(word>w[middle].getenglish()) { low=middle+1; middle=(low+high)/2; } else { high=middle-1; middle=(low+high)/2; } if (low>high) { cout << "对不起,查无此词。" << endl; break; } } if(low<=high) cout <<w[middle].getwordclass() <<" " <<w[middle].getchinese() << endl; cout << endl << "回车键继续或其他任意键退出..." << endl << endl; } while (getchar()=='\n'); return 0; }
相关文章推荐
- centos7 通过kvm+vnc 实现远程桌面虚拟化和创建windows、Linux虚拟机
- OpenGL glLightfv 函数的应用以及光源的相关知识
- 使用Apache Commons-email邮件客户端发邮件
- linux的日志管理
- Linux 设备模型之 (kobject、kset 和 Subsystem)(二)
- Linux环境数据备份Python脚本
- 如何开始学习ADF和Jdeveroper 11g
- 对视图有时为什么使用select top 100 percent * 而不使用 select * 呢?
- centos7下配置postfix
- Linux 文件查找命令find,xargs详述
- linux -- Ubuntu network-manager
- 菜鸟学Linux
- Properties文件不在项目目录下的一种读取方法
- Intel CPU 历代微架构名称
- Hadoop 实现Rackawareness
- Centos 6.5 install caffe+Nvidia driver+cuda 6.5
- linux下overcommit_memory的问题
- 将ImageMagic库编译进nginx
- 分布式网站架构后续:zookeeper技术浅析
- Linux中cp和scp命令详解