输入代码:

/*
* 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版电子词典的更多相关文章

  1. 第十四周(OOP版电子词典)

    /* *copyright(c) 2015,烟台大学计算机学院 *All rights reserved. *文件名:第十四周(OOP版电子词典) *作者:王忠 *完毕日期:2015.6.10 *版本 ...

  2. C++第15周(春)项目3 - OOP版电子词典(一)

    课程首页在:http://blog.csdn.net/sxhelijian/article/details/11890759.内有完整教学方案及资源链接 [项目3-OOP版电子词典](本程序中须要的相 ...

  3. C++第15周(春)项目3 - OOP版电子词典(二)

    课程首页在:http://blog.csdn.net/sxhelijian/article/details/11890759,内有完整教学方案及资源链接 [项目3-OOP版电子词典](本程序须要的相关 ...

  4. 第14周 项目三-OOP版电子词典

    做一个简单的电子词典.在文件dictionary.txt中,保存的是英汉对比的一个词典,词汇量近8000个,英文.中文释义与词性间用'\t'隔开. (1)编程序,由用户输入英文词.显示词性和中文释义. ...

  5. wxWidgets+wxSmith版电子词典

    课程首页在:http://blog.csdn.net/sxhelijian/article/details/11890759,内有完整教学方案及资源链接 [项目3-OOP版电子词典](本程序须要的相关 ...

  6. 吴裕雄--天生自然python学习笔记:python 用firebase实现英文电子词典

    Firebase 版电子词典 学英语是许多 人一辈子的麻烦 . 所以本例中,我们开发一个英汉词典,用户执 行程序后,单击“翻译”按钮即可显示该单词的中文翻译 . 英汉词典标准版 因为这个案例的数据必须 ...

  7. 电子词典的相关子函数db.c程序

    整个电子词典是分块做的:包含的Dic_Server.c,Dic_Client.c,db.c,query.c,xprtcl.c,dict.h,xprtcl.h,dict.txt(单词文件) 下面是db. ...

  8. OC4_电子词典

    // // MyDictionary.h // OC4_电子词典 // // Created by zhangxueming on 15/6/15. // Copyright (c) 2015年 zh ...

  9. 使用Android简单实现有道电子词典

    前言: 毕业设计的内容,仅仅有Java基础.没学过Android. 本着用到什么学什么.花费了10多个晚上完毕毕业设计. 当然,仅仅是简单的实线了电子词典功能,自始至终没有考虑过性能等问题. 本电子词 ...

随机推荐

  1. 通过ansible一键部署集群ntp时间同步

    环境准备 [root@server ~]# cat /etc/redhat-release CentOS Linux release (Core) [root@server ~]# uname -r  ...

  2. hdu 4908(思路题)

    BestCoder Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  3. CSU 1505: 酷酷的单词【字符串】

    Description 输入一些仅由小写字母组成的单词.你的任务是统计有多少个单词是“酷”的,即每种字母出现的次数都不同.比如ada是酷的,因为a出现2次,d出现1次,而1和2不同.再比如,banan ...

  4. TopCoder SRM 301 Div2 Problem 1000 CorrectingParenthesization(区间DP)

    题意  给定一个长度为偶数的字符串.这个字符串由三种括号组成. 现在要把这个字符串修改为一个符合括号完全匹配的字符串,改变一个括号的代价为$1$,求最小总代价. 区间DP.令$dp[i][j]$为把子 ...

  5. Codeforces 754A Lesha and array splitting (搜索)

    题目链接 Lesha and array splitting 设s[i][j]为序列i到j的和,当s[i][j]≠0时,即可从i跳到j+1.目标为从1跳到n+1,所以按照题意暴力即可. #includ ...

  6. 全局变量 全局函数vue 方法

    定义全局变量 原理: 设置一个专用的的全局变量模块文件,模块里面定义一些变量初始状态,用export default 暴露出去,在main.js里面使用Vue.prototype挂载到vue实例上面或 ...

  7. 解决百度ueditor配置上传目录为外部目录时,项目启动访问不到图片的问题。

    如图所示,公司项目用到了百度的ueditor,配置的上传目录并不在项目根目录下,而是在外部目录中.于是在上传图片时,出现了无法获取图片的问题. 解决方法:添加该目录至tomcat项目部署目录中,如下图 ...

  8. 书写一个程序,把变量n的初始值设置为1957,然后利用除法运算和取余运算把变量n的每一位数字都抽出来并打印

    class number { void num(){ int a,b,c,d; int n=1957; a=n/1000; b=n/100%10; c=n/10%10; d=n%10; System. ...

  9. oracle小知识点16-诊断事件diagnostic events

    http://blog.itpub.net/28539951/viewspace-1983919/

  10. MFC中 CString与int的转化

    int 转化为SCtring: int n = 123; CString str; str.Format("%d",n); 报错的话则改为:str.Format(_T(" ...