项目实践---字典
来源:互联网 发布:淘宝店图片轮播素材 编辑:程序博客网 时间:2024/06/07 17:30
//首先在C盘建个文件:
love 爱
I 我
choice 选择
//创建zidian.cpp
#include<iostream>
#include"dic.h"
using namespace std;
int main()
{
cout<<"--欢迎使用四六级字典--"<<endl;
cout<<"\t1:翻译单词"<<endl
<<"\t2:添加单词"<<endl
<<"\t3:每天一记"<<endl
<<"\t4:退出"<<endl;
cout<<"************************"<<endl;
dic zidian;
string word;
int choice;
do
{
cout<<"请选择你的操作:"<<endl;
cin>>choice;
switch(choice)
{
case 1:cout<<"输入你要翻译的单词:"<<endl;
cin>>word;
cout<<word<<": "<<zidian.EnglisttoChinese(word)<<endl;
break;
case 2:cout<<"输入你要添加的单词:"<<endl;
cin>>word;
cout<<word<<": "<<zidian.EnglisttoChinese(word)<<endl;
break;
case 4:cout<<"退出系统"<<endl;
exit(1);
break;
default:cout<<"输入错误!"<<endl;
exit(1);
break;
}
}while(choice==1 || choice==2 || choice==3 );
return 0;
}
//创建dic.h
#include<string>
#include<iostream>
#include<fstream>
#include<map>
using namespace std;// 这个不加就会出错
class dic
{
public:
dic();
string EnglisttoChinese(string str);
private:
map<string,string> EtoC;
};
dic::dic()
{
string Englishword;
string Chineseword;
ifstream ifile;
ifile.open("c:\\英汉对照.txt");
if(!ifile)
{
cout<<"ERROR!"<<endl;
exit(1);
}
while(ifile>>Englishword>>Chineseword)
{
EtoC.insert(map<string,string>::value_type(Englishword,Chineseword));
}
ifile.close();
}
string dic::EnglisttoChinese(string str)
{
map<string,string>::const_iterator //在字典里查找你要查的英文单词
iter=EtoC.find(str);
if(iter==EtoC.end())
return "没有这个单词";
else
return iter->second; //返回单词的翻译
}
- 项目实践---字典
- 项目实践一:如何在列表、字典中根据条件筛选数据?
- 项目实践
- 项目开发 - 数据字典
- 项目-汉语字典总结
- 汉语字典项目总结
- 汉语字典项目总结
- 项目开发 - 数据字典设计方案
- J2EE项目数据字典设计
- J2EE项目数据字典设计
- 某零售项目实践---项目
- 项目实践点点滴滴
- 我的实践项目
- 创新联盟实践项目
- 项目实践目的
- 项目开发实践1
- OS实践项目
- OPOA项目实践
- Error: Error parsing D:\new_android\Android SDK\system-images\android-25\android-wear\armeabi-v7a\de
- C++文件练习
- c#中,类的重写中,new和override的区别
- GIS就业参考系列之方向篇——条条大道通罗马
- ffmpeg 不能发送60帧视频问题分析
- 项目实践---字典
- 在使用hibernate进行数据操作时出现错误
- 深度学习初步了解
- 备忘录模式(设计模式_20)
- C#中Linq查询基本操作使用实例
- 简单Queue实现 python语言
- 安卓复习之旅—工厂模式(二)
- go错误处理——return,panic,defer
- 数据库的连接 java