【C++面向对象程序设计】20170327英汉词典
来源:互联网 发布:怎么玩转淘宝千人千面 编辑:程序博客网 时间:2024/06/06 20:27
/*This is a c++ homework author@19160209*/#include<iostream>#include<stdio.h>#include<fstream>#include<cstdlib>#include<iomanip>#include<string>#include<sstream>using namespace std;class info{ public: string han; string eng; info*next;};void menus(info *head);void print(int a,info* p);void freep(info *head);void order(int pt,info*head);void choose_to_do(info *head);info* findword(string tmp,int a,info *head);void freep(info* head){ info*p=head,*q=NULL; do { q=p->next; delete p; p=q; }while(p!=NULL);}void print(int a,info *p){ if(a==1||a==3) cout<<p->eng<<' '; else cout<<p->han<<' ';}info* findword(string tmp,int a,info *head){ info *p;p=head; if(a==1||a==3){ while(p!=NULL){ if(p->han==tmp) return p; p=p->next; } } else { while(p!=NULL){ if(p->eng==tmp) return p; p=p->next; } } return NULL;}void menus(info *head){ int pt; cout<<"FUNCTIONS:Please input your requirement."<<endl; cout<<setw(10)<<1<<":(word) CHN---ENG"<<endl; cout<<setw(10)<<2<<":(word) ENG---CHN"<<endl; cout<<setw(10)<<3<<":(sentence) CHN---ENG"<<endl; cout<<setw(10)<<4<<":(sentence) ENG---CHN"<<endl; cin>>pt; order(pt,head);}void order(int pt,info*head){ info*result; switch(pt) { case 1:{ string tmp; int c=1; do{ cin>>tmp; getche(c); result=findword(tmp,pt,head); if(result!=NULL) print(pt,result); else cout<<"CAN'T FIND!"<<endl; }while(c!='\n'); break; } case 2:{ string tmp; cin>>tmp; result=findword(tmp,pt,head); if(result!=NULL) print(pt,result); else cout<<"CAN'T FIND"<<endl; break; } case 3:{ int k;string tmp; cout<<"请您输入句子中包含的词汇个数。"<<endl; cin>>k; cout<<"请您输入句子(词汇以空格分开)。"<<endl; for(int j=0;j<k;j++) { cin>>tmp; result=findword(tmp,pt,head); if(result!=NULL) cout<<result->eng<<" "; else cout<<"***"<<" "; } cout<<endl; break; } default:{ int k; cout<<"Please input the NUMBER of words contained in a sentence."<<endl; cin>>k;string tmp; cout<<"Please input your sentence."<<endl; for(int j=0;j<k;j++) { cin>>tmp; result=findword(tmp,pt,head); if(result!=NULL) cout<<result->han; else cout<<"***"<<endl; }cout<<endl; break; } }}void choose_to_do(info *head){ int q=1; while (q==1) { cout<<"DO you want to continue? Yes input '1'/No input '0'."<<endl; cin>>q; if (q!=0&&q!=1) {cout<<"Wrong order!"<<endl; q=1;} else if(q==1) { menus(head);choose_to_do(head); } if(q==0) q=0; }}int main(){ cout<<"Welcome to the easy dictionary."<<endl; ifstream fin("data.txt"); if(!fin) { cout<<"ERROR!"<<endl; exit(0); } //cout<<"1"<<endl; string s,str1,str2; info *head; head=new info; info *p;p=head; while(getline(fin,s)) { istringstream sin(s); sin>>str1>>str2; info *newp;newp=new info; newp->han=str1; newp->eng=str2; cout<<newp->han<<" "<<newp->eng<<endl; p->next=newp; p=newp; } p->next=NULL; head=head->next; //cout<<"2"<<endl; menus(head); choose_to_do(head); freep(head); return 0;}
阅读全文
0 0
- 【C++面向对象程序设计】20170327英汉词典
- C 面向对象程序设计
- C++(面向对象程序设计)
- 面向对象程序设计--C++/Java
- 面向对象程序设计--C++/Java
- Objective-C:面向对象程序设计
- 面向对象的程序设计(C#)
- 面向对象程序设计(C++)教学资源[2009]
- c++primer要点-面向对象程序设计
- C/C++程序设计06(面向对象)
- 面向对象程序设计三个基本特征(C++)
- C++_面向对象程序设计基本概念
- 《面向对象程序设计-C++》学习笔记1
- 《面向对象程序设计-C++》学习笔记2
- C++primer阅读笔记---------------面向对象程序设计
- C++OOP程序设计读书笔记之一:面向对象的程序设计简介
- C++面向对象程序设计
- 面向对象程序设计
- html相关问题汇总
- Java面向对象基础
- mysql windows64位zip安装
- egret如何编译ts为js
- Java编程实现Math.sqart(开根号)方法
- 【C++面向对象程序设计】20170327英汉词典
- 使用idea新建spingboot+mybatis项目
- SOAP:简单对象访问协议
- android项目开发总结
- TCP UDP
- STM32学习笔记(一):起笔,从GPIO开始
- Windows编译下MDL的anroid端库
- C语言中的字符串拷贝函数strcpy和内存拷贝函数memcpy的区别与实现
- xml简单知识