OOP版电子词典
输入代码:
- /*
- * Copyright (c) 2014, 烟台大学计算机学院
- * All rights reserved.
- * 文件名:sum123.cpp
- * 作 者:林海云
- * 完毕日期:2015年8月19日
- * 版 本 号:v2.0
- *
- * 问题描写叙述:做一个简单的电子词典。
- 在文件dictionary.txt中。保存的是英汉对比的一个词典,词汇量近8000个,英文、中文释义与词性间用’\t’隔开。
- * 输入描写叙述:文本输入;
- * 程序输出:输出翻译的单词中文意思。词性。中文:
- */
- #include<fstream>
- #include<iostream>
- #include<string>
- #include<cstdlib>
- using namespace std;
- //定义词条类
- class Word
- {
- public:
- void set(string e,string c,string wc);
- int compare(string );
- string getChinese();
- string getWord_class();
- private:
- string english;
- string chinese;
- string word_class;
- };
- void Word::set(string e,string c,string wc)
- {
- english=e;
- chinese=c;
- word_class=wc;
- }
- int Word::compare(string k )
- {
- return english.compare(k);
- }
- string Word::getChinese()
- {
- return chinese;
- }
- string Word::getWord_class()
- {
- return word_class;
- }
- //定义字典类
- class Dictionary
- {
- public:
- Dictionary();
- void searchWord(string k);
- private:
- int BinSeareh(int low, int high, string k);
- int wordsNum;
- Word words[8000];
- };
- Dictionary::Dictionary()
- {
- string e,c,wc;
- wordsNum=0;
- ifstream infile("dictionary.txt",ios::in);
- if(!infile)
- {
- cerr<<"dictionary open error!"<<endl;
- abort();
- }
- while(!infile.eof())
- {
- infile>>e>>c>>wc;
- words[wordsNum].set(e, c, wc);
- ++wordsNum;
- }
- infile.close();
- }
- void Dictionary::searchWord(string key)
- {
- int low=0,high=wordsNum-1;
- int index=BinSeareh(low, high, key);
- if(index>=0)
- cout<<key<<"<---"<<words[index].getWord_class()+"\t"<<words[index].getChinese();
- else
- cout<<"查无此词!"<<endl;
- cout<<endl;
- }
- int Dictionary::BinSeareh(int low, int high, string key)
- {
- int mid;
- while(low<=high)
- {
- mid=(low+high)/2;
- if(words[mid].compare(key)==0)
- {
- return mid;
- }
- if(words[mid].compare(key)>0)
- high=mid-1;
- else
- low=mid+1;
- }
- return -1;
- }
- int main()
- {
- Dictionary dic;
- string key;
- do
- {
- cout<<"请输入待查询的关键词(英文),0000结束:"<<endl;
- cin>>key;
- if(key!="0000")
- {
- dic.searchWord(key);
- }
- }
- while(key!="0000");
- return 0;
- }
执行结果:
dictionary.txt
OOP版电子词典的更多相关文章
- 第十四周(OOP版电子词典)
/* *copyright(c) 2015,烟台大学计算机学院 *All rights reserved. *文件名:第十四周(OOP版电子词典) *作者:王忠 *完毕日期:2015.6.10 *版本 ...
- C++第15周(春)项目3 - OOP版电子词典(一)
课程首页在:http://blog.csdn.net/sxhelijian/article/details/11890759.内有完整教学方案及资源链接 [项目3-OOP版电子词典](本程序中须要的相 ...
- C++第15周(春)项目3 - OOP版电子词典(二)
课程首页在:http://blog.csdn.net/sxhelijian/article/details/11890759,内有完整教学方案及资源链接 [项目3-OOP版电子词典](本程序须要的相关 ...
- 第14周 项目三-OOP版电子词典
做一个简单的电子词典.在文件dictionary.txt中,保存的是英汉对比的一个词典,词汇量近8000个,英文.中文释义与词性间用'\t'隔开. (1)编程序,由用户输入英文词.显示词性和中文释义. ...
- wxWidgets+wxSmith版电子词典
课程首页在:http://blog.csdn.net/sxhelijian/article/details/11890759,内有完整教学方案及资源链接 [项目3-OOP版电子词典](本程序须要的相关 ...
- 吴裕雄--天生自然python学习笔记:python 用firebase实现英文电子词典
Firebase 版电子词典 学英语是许多 人一辈子的麻烦 . 所以本例中,我们开发一个英汉词典,用户执 行程序后,单击“翻译”按钮即可显示该单词的中文翻译 . 英汉词典标准版 因为这个案例的数据必须 ...
- 电子词典的相关子函数db.c程序
整个电子词典是分块做的:包含的Dic_Server.c,Dic_Client.c,db.c,query.c,xprtcl.c,dict.h,xprtcl.h,dict.txt(单词文件) 下面是db. ...
- OC4_电子词典
// // MyDictionary.h // OC4_电子词典 // // Created by zhangxueming on 15/6/15. // Copyright (c) 2015年 zh ...
- 使用Android简单实现有道电子词典
前言: 毕业设计的内容,仅仅有Java基础.没学过Android. 本着用到什么学什么.花费了10多个晚上完毕毕业设计. 当然,仅仅是简单的实线了电子词典功能,自始至终没有考虑过性能等问题. 本电子词 ...
随机推荐
- check source code after macro expand
Some time I'd like check source code after macro expand. We can use -E option to stop after the prep ...
- python标准库:Configparser模块
配置文件test.conf [section1] name = tank age = 28 [section2] ip = 192.168.1.1 port = 8080 示例 # -* - codi ...
- python-rtslib 模块
Python library for configuring the Linux kernel-based multiprotocol SCSI target (LIO) A Python objec ...
- 点击添加按钮,使用ajax动态添加一行和移除一行,并且序号重新排序和数据不重复操作判断
<div class="control-group " style="top: -20px;position: relative;"> <la ...
- Django ModelChoiceField前台下拉菜单显示object的解决方法
在网上找了好半天都没找到,在model中添加即可,不加的话显示就是object def __str__(self): return self.name
- 长安大学第四届“迎新杯”程序设计竞赛 H 圣诞节糖果【二分】
时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 131072K,其他语言262144K64bit IO Format: %lld 题目描述 圣诞节临近,彩虹岛的黑心商人
- 洛谷 P1579 哥德巴赫猜想(升级版)【筛素数/技巧性枚举/易错】
[链接]:https://www.luogu.org/problemnew/show/P1579 题目背景 1742年6月7日哥德巴赫写信给当时的大数学家欧拉,正式提出了以下的猜想:任何一个大于9的奇 ...
- superagent-promise
var Promise = this.Promise || require('promise'); var agent = require('superagent-promise')(require( ...
- Jenkins插件HTML Publisher Plugin的使用
前提: 下载插件HTML Publisher plugin 一.安装 安装好HTML Publisher plugin之后,会在新建或者编辑项目时,在[增加构建后操作步骤]出现[Publish HTM ...
- oracle查询、删除表中相同的数据
delete FROM tablename a WHERE rowid > ( SELECT min(rowid) FROM tablename b WHERE b.id = a.id and ...