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多个晚上完毕毕业设计. 当然,仅仅是简单的实线了电子词典功能,自始至终没有考虑过性能等问题. 本电子词 ...
随机推荐
- python字符串加密与反解密
在生产中会遇到很多情况是需要加密字符串的(如访问或存储密码)这些需求造就了需要字符串加密,以及反解密的问题,推荐两种方法来实现,下附代码: #!/usr/bin/env python3 # -*- c ...
- 使用git快捷方便的保存代码
大家都在使用git保存和备份代码,下面我们就来学习下吧. 一.本地安装和配置git 1.安装git pacman -S git //如果没有问题的话就可以安装成功了 2.验证 git --versio ...
- 移动GIS技术在城市信息采集中的应用
1 引言 随着移动平板电脑和手机(以下简称移动终端)在软硬件上的更新换代,和3G.4G通讯网络的升级,传统测绘和和数据服务方式正在发生巨大变化.以城市中的外业踏勘和信息采集为例,移动终端正成为主要的外 ...
- Scrapy笔记:使用代理ip
scrapy框架使用代理ip的基本思路是修改请求对象中的meta['proxy']的值,将代理ip赋值给这个属性.遵循这个思路,只要是生成Request对象的地方都可以设置Request的值. dow ...
- HDU 1022 Train Problem I[给出两个长n的串,入栈和出栈顺序,判断入栈顺序是否可以匹配出栈顺序]
Train Problem I 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 As the new term comes, the Ignatius Train Sta ...
- 根据CPU核数合理设置线程池大小
一般来说池中总线程数是核心池线程数量两倍,只要确保当核心池有线程停止时,核心池外能有线程进入核心池即可. 我们所需要关心的主要是核心池线程的数量该如何设置. 自定义线程池代码 package com. ...
- Zabbix4.0安装与入门及常见配置
1.安装zabbix-server 环境: 10.0.0.50 zabbix-server 10.0.0.51 zabbix-web 10.0.0.52 zabbix-agent yum -y ins ...
- 聊聊、Zookeeper Linux 集群服务
今天是平安夜,先祝大家平安夜快乐.这篇文章我们来谈谈 Zookeeper Linux 集群. 为什么要集群呢?因为一台服务不够.集群是为了系统扩容,系统稳定.一台服务挂了,没关系,我还有其他的服务.集 ...
- Linux基础学习5
程序管理与SELinux初探 process&program 程序 (program):通常为 binary program ,放置在储存媒体中 (如硬盘.光盘.软盘.磁带等), 为实体档案 ...
- MyEclipse出错解决
错误信息: Deployment failure on Tomcat 6.x. Could not copy all resources to C:\Tomcat 6.0\webapps\JavaP ...