第十六周实验报告3
来源:互联网 发布:为什么c语言的头文件 编辑:程序博客网 时间:2024/05/17 08:12
作品名:电子词典
- 英文、中文释义与词性间用’\t’隔开。建一个表示词条的类Word,Word 类的一个对象可以描述一个词,
- 类对象数组可以存储词库。将文件中的内容读到对象数组中,由用户输入英文词,显示中文释义。
- 允许用户运行程序后,连续地查词典,直到输入”0000”结束
- * 程序头部的注释结束
#include <iostream>#include <string>#include <fstream>using namespace std;class Word{private:string word;string mean;string type;public:Word();Word(string wo, string me, string ty);friend void readfile(Word w[]);friend void findword(Word w[]);};Word::Word(){word = "NULL";mean = "NULL";type = "NULL";}Word::Word(string wo, string me, string ty){word = wo;mean = me;type = ty;}void readfile(Word w[]){ifstream infile("dictionary.txt",ios::in);if(! infile){cerr << "open cerror" << endl;exit(1);}for(int i = 0; i < 8000; i++){infile >> w[i].word >> w[i].mean >> w[i].type;}infile.close();}void findword(Word w[]){string wo;do{cout << "输入要查找的单词(0000结束):";cin >> wo;if(wo == "0000"){break;}int a = 0, b = 8000, mid;while(a <= b){mid = (a + b) / 2;if(w[mid].word == wo){cout << w[mid].word << '\t'<< "的汉语意思是:" << w[mid].mean << '\t'<<"词性是:" << w[mid].type << endl;break;}else{if(wo > w[mid].word){a = mid;}else{b = mid;}}}}while(1);}int main(){Word w[8000];readfile(w);findword(w);system("PAUSE");return 0;}
- 第十六周实验报告3
- 第十六周实验报告3
- 第十六周实验报告3
- 第十六周实验报告3
- 第十六周实验报告3
- 第十六周实验报告3
- 第十六周实验报告任务3--电子词典
- 第十六周实验报告2
- 第十六周实验报告1
- 第十六周实验报告1
- 第十六周实验报告2
- 第十六周实验报告2
- 第十六周实验报告1
- 第十六周实验报告2
- 第十六周实验报告2.0
- 第十六周实验报告1
- 第十六周实验报告1
- 第十六周实验报告2
- c语言中的 extern 和 static
- 【笔记】verilog 学习笔记(一)
- Android 日历提供器(一)
- adb no permissions问题
- Android 日历提供器(二)
- 第十六周实验报告3
- (转载)经典:从追MM谈Java的23种设计模式
- iPhone上实现Default.png动画
- 推荐个好用的开源SIP客户端STACK和一个开源SIP服务器端
- 2012.6.3显示接口枚举,结构体
- 第十六周上机任务3
- 找规律:1,1,2,3,5,8,13,21求第三十个数
- 2012.6.3ref 用法
- 黑马程序员_java学习笔记四