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多个晚上完毕毕业设计. 当然,仅仅是简单的实线了电子词典功能,自始至终没有考虑过性能等问题. 本电子词 ...
随机推荐
- android基本控件学习-----RadioButton&CheckBox
RadioButton(单选框)和CheckBox(复选框)讲解: 一.基本用法和事件处理 (1)RadioButton单选框,就是只能选择其中的一个,我们在使用的时候需要将RadioButton放到 ...
- Android系统启动过程【转】
转自:http://www.cnblogs.com/bastard/archive/2012/08/28/2660389.html Android系统启动过程 首先Android框架架构图:(来自网上 ...
- [SaltStack] Salt高可用和负载均衡部署
Saltstack HA部署 Salt官网是有HA/Rebalance/failover解决方案的, 但版本必须是2014.7, 目前该版本还没有release, 从官网下载的源码包安装使用测试起来一 ...
- 学习环境配置:Manjaro、MSYS2以及常见软件
0.前言 在说Manjaro之前,要先说一下Linux发行版.对于各大发行版而言,内核只有版本的差异,最重要的区别就是包管理系统.常见的包管理系统包括:Pacman,Apt , Yum和Portage ...
- jquery的toggle动画效果显示隐藏
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- AC日记——仙岛求药 openjude 2727
仙岛求药 思路: bfs: 来,上代码: #include <cstdio> #include <cstring> #include <iostream> #inc ...
- ios 地图,系统升级为12后,进入地图,大头针全部默认展开问题,以及在选择不同距离的情况下,如何刷新地图的区域范围
1.第一个问题,大头针在ios12,默认展开问题,需要设置大头针视图的默认选中属性为NO - (MKAnnotationView *)mapView:(MKMapView *)mapView view ...
- 使用 Jmeter 做 Web 接口测试-详解
接口测试概述 定义 WIKI定义:接口测试作为集成测 试的一部分,通过直接控制API来判断系统的功能性,可靠性,性能与安全性.API测试是没有界面的,执行在通讯 层.API 测试在自动化测试中有着重要 ...
- 洛谷——1115 最大子段和(区间DP)
题目描述 给出一段序列,选出其中连续且非空的一段使得这段和最大. 输入输出格式 输入格式: 输入文件maxsum1.in的第一行是一个正整数N,表示了序列的长度. 第2行包含N个绝对值不大于10000 ...
- CentOS 7下安装配置FTP
安装vsftpd yum install -y vsftpd 编辑ftp配置文件 vi /etc/vsftpd/vsftpd.conf anonymous_enable=NO #anonymous_e ...