KWIC

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

KWIC
一.实验原理
基本面向对象方案:
该方案是个基本的面向对象方案,有四个基本功能类:input, shift, alphabetize 和output,将这些功能在主程序中串联起来,通过共享数据的方式组成整个系统。

流程很简单,首先通过input类获取需要处理的英文语句行,接着使用shift进行移位操作,得到一行行的结果,此时再采用alphabetizer 对这些行进行首字母排序,最后采用output类输出。

设计了一个Kwic类对上述类进行整合。

评价:将各个功能模块分开设计,并且利用权限控制保证了封装的特性,系统的扩展性和封装性增强。

二.实验代码
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
#define maxs 100
int N=0,A=0,Q=0;
int M=0,G=0,P=0;
struct sentence{
string str[maxs];
string str1[maxs];
int L;
int Q;
};
struct SS{
string STR;
};
int Menu(){
int i;
cout<<" KWIC算法"<<endl;
cout<<"1.输入(“#”结束输入) 2.移位 3.排序 4.退出"<<endl;
cout<<"你的选择(n>=1&&n<=4)请输入"<<endl;
cin>>i;
if(i<=0||i>4){
cout<<"输入错误,请重新输入i值:"<<endl;
cin>>i;
}
return i;
}
void input(sentence *p){
int i=0;
cin>>p[M].str[i];
while(p[M].str[i++]!="#"){
cin>>p[M].str[i];
}
p[M].L=i-2;
cout<<p[M].L<<endl;
M++;
}
void shift(sentence *p,SS *q){
int i=0,j,k=0,Z=1,l,a=0;
string s;
A=0;
while(a<M){
i=0;
for(j=0;j<=p[a].L;j++)
p[A].str1[j]=p[a].str[j];
p[A].Q=p[a].L;
cout<<endl;
A++;
while(i<p[a].L)
k=p[a].L;
s=p[A-1].str1[p[a].L];
while(k>0){
--k;
p[A].str1[k+1]=p[A-1].str1[k];
}
p[A].str1[0]=s;
p[A].Q=p[a].L;
i++;
A++;
}
a++;
}
for(l=0;l<=A;l++)
for(j=0;j<=p[l].Q;j++)
{
cout<<p[l].str1[j]<<" ";
if(j==p[l].Q)
cout<<endl;
}
cout<<endl;
}
void gether(sentence *p,SS *q)
{
int i,j;
for(j=0;j<A;j++)
for(i=0;i<=p[j].Q;i++)
{
q[j].STR=q[j].STR+" ";
q[j].STR=q[j].STR+p[j].str1[i];
}
}
void main(){
int i,j,n,x=0;
string ss[100];
sentence *p1=new sentence[maxs];
SS *q=new SS[maxs];
switch(Menu()){
case 1:
input(p1);
break;
case 2:
shift(p1,q);
break;
case 3:
gether(p1,q);
for(i=0;i<A;i++)
{
ss[i]=q[i].STR;
x++;
}
sort(ss,ss+x);
for(i=0;i<x;i++)
cout<<ss[i]<<endl;
break;
case 4:
cout<<"退出!"<<endl;
exit(0);
}
}。

相关文档
最新文档