第十四周项目四:电子词典

来源:互联网 发布:斯普特尼克恋人 知乎 编辑:程序博客网 时间:2024/06/02 08:17
/**copyright (c) 2014, 烟台大学计算机学院.*All rights reserved.*文件名称:test.cpp *作者:陆云杰*完成日期:2014年11月30日 *版本号:v1.0* **问题描述:电子词典*程序输入:英文单词*程序输出:解释*/ #include <fstream>#include <iostream>#include <cstdlib>const int size=8000;using namespace std;int main(){    string C[size],E[size],key;    ifstream infile("dictionary.txt",ios::in);    if(!infile)    {        cerr<<"open error!"<<endl;        exit(1);    }    int i;    for(i=0; i<size; i++)    {        infile>>E[size];        if(infile!=" ")            infile>>C[size];    }    infile.close();    do    {        int low=0,high=size-1,mid,index=-1;        cout<<"请输入要查找的词(输入0000结束):";        cin>>key;        while(low<=high)        {            mid=(low+high)/2;            if(E[mid]==key)            {                index=mid;                break;            }            else if(E[mid]>key)            {                high=mid-1;            }            else low=mid+1;        }        if(index>=0)        {            cout<<E[index]<<"的中文意思是:"<<C[index]<<endl;        }        else        {            cout<<"没有找到!"<<endl;        }    }        while(key!="0000");        cout<<"谢谢使用!"<<endl;        return 0;    }

学习心得:可以编一个电子词典啦!

0 0
原创粉丝点击