ImageVerifierCode 换一换
格式:DOCX , 页数:16 ,大小:67.24KB ,
资源ID:7497519      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/7497519.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(KWIC实验报告C.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

KWIC实验报告C.docx

1、KWIC实验报告C软件体系结构上机实验报告书中国石油大学(北京)信息学院计算机科学与技术系制 订 人:周新学 号:07指导教师:朱雪峰 博士2011年10月27日 1、课程实验目的通过KWIC(Key Word in Context)检索系统,对软件体系结构有更加深入的了解和认识。通过运用几种体系结构,熟悉常见的软件体系结构,并对这几种结构有进一步了解。2、任务概述用管道过滤器,主程序、子程序,抽象数据类型,隐式调用这四种结构来分别实现KWIC检索系统。3、实现方法用C+主要实现了两种结构:主程序、子程序结构,抽象数据类型。(1)KWIC1工程的入口函数int _tmain(int argc,

2、 _TCHAR* argv) /界面,结构选择 coutfilename; coutChoose KWIC functionendl1 is Main Program/Subroutine with Shared Dataendl2 is Abstract Data Typeschoose; if(1=choose)/主程序和子程序 MainSubroutine mainSub; vectorvector lines=mainSub.readLines(filename); vector lineIndex=mainSub.shiftString(lines); lineIndex=mainS

3、ub.firstAlphaSort(lineIndex,lines); mainSub.outPut(lineIndex,lines); else/抽象收据类型 Lines *lines=new Lines; Input input; Shift *shift=new Shift; FirstAlphaSort alphaSort; Output output; input.readLines(filename,*lines); shift-circularShift(*lines); alphaSort.alphaSort(*shift); output.print(alphaSort);

4、delete shift; delete lines; return 0;(2)主程序、子程序结构实现类/从文件中按行读取vectorvector MainSubroutine:readLines(char* filename) vectorvector dst; ifstream infile(filename,ios:in); if(!infile) coutopen error!endl; exit(0); char temp100=;/存储从文件中读取的行的临时变量 /按行读取 while(infile.getline(temp,100) int k=0,j=0; vector lin

5、e; line.swap(vector(); char s20=;/存储从行中取字符串的临时变量 while(tempk!=0) /每个单词的截取条件为下一个字符为空格或者为行的末尾 if(tempk+1= |tempk+1=0)&tempk!= ) sj=tempk; sj+1=0; string ss=s; line.push_back(ss); j=0; else if(tempk= ) j=0; else sj=tempk; j+; k+; dst.push_back(line);/将从文件中中读出的行加入到dst中 infile.close(); for(int i=0;idst.s

6、ize();i+) for(int j=0;jdst.at(i).size();j+) coutdstij ; coutendl; coutendlendl; return dst;/循环左移vector MainSubroutine:shiftString(vectorvector srcLines) vector shiftLines; for(int row=0;rowsrcLines.size();row+) int colnum=srcLinesrow.size();/获取每一行的字符串个数 /对第row行循环colnum(字符串个数)次,生成循环移位后的colnum行 for(in

7、t col=0;colcolnum;col+) LINE linePos;/声明存放一行的行标以及各列的列表的结构体 linePos.rowIndex=row;/给行标赋值 /循环生成一行的列标 for(int colshift=0;colshiftcolnum;colshift+) ;/取模运算 shiftLines.push_back(linePos); return shiftLines;/字母排序vector MainSubroutine:firstAlphaSort(vector lineIndex,vectorvector srcLines) vectorvector firstC

8、har; vector dstIndex; for(int row=0;rowsrcLines.size();row+) vector firstCharLine; /逐行提取各个字符串的首字母 for(int col=0;colsrcLinesrow.size();col+) firstCharLine.push_back(srcLinesrowcol0); firstChar.push_back(firstCharLine);/ int rowPos=0; int colPos=0; /外面的两层for循环是控制循环次数的 /内部的两层for循环是遍历所有的字符串首字母,寻找最小的字母 f

9、or(int row=0;rowfirstChar.size();row+) for(int col=0;colfirstCharrow.size();col+) char min=z; for(int row=0;rowfirstChar.size();row+) for(int col=0;col=firstCharrowcol& !=firstCharrowcol) rowPos=row; colPos=col; min=firstCharrowcol; firstCharrowPoscolPos= ; int linePos=0;/在原行矩阵中的位置 for(int line=0;li

10、nerowPos;line+) linePos+=srcLinesline.size(); linePos=linePos+colPos; dstIndex.push_back(lineIndexlinePos); return dstIndex;/按照lineIndex中的字符串的行标和列标输出所有字符串void MainSubroutine:outPut(vector lineIndex, vectorvector srcLines) for(int row=0;rowlineIndex.size();row+) for(int col=0;collineIndexrow.colIndex

11、.size();col+) coutsrcLineslineIndexrow.rowIndexlineIndexrow.colIndexcol ; coutendl; coutendl;(3)抽象数据类型结构实现行存储类/增加行/参数:line字符串向量列表void Lines:addLine(vector line) lines.push_back(line);/从存储结构中获取某一行/参数:lineIndex为获取的行的序号,从0开始/返回获取的行vector Lines:getLine(int lineIndex) return lineslineIndex;/ 增加字符串/参数:ins

12、tring为所添加字符串,lineIndex为字符串所在行的序号(从0开始)void Lines:addString(string instring, int lineIndex) lineslineIndex.push_back(instring);/获取字符串/参数:lineIndex为行序号,stringIndex为字符串在行中的序号/返回获取的字符串string Lines:getString(int lineIndex,int stringIndex) return lineslineIndexstringIndex;/增加字符/参数:inchar为增加的字符,stringIndex

13、为增加的字符所在的字符串的序号,lineIndex为增加的字符所在的行的序号void Lines:addChar(char inchar, int stringIndex, int lineIndex) lineslineIndexstringIndex.push_back(inchar);/获取字符/参数:lineIndex为行序号,stringIndex为字符串的序号,charIndex为字符的序号/返回获取的字符char Lines:getChar(int lineIndex, int stringIndex, int charIndex) return lineslineIndexst

14、ringIndexcharIndex;/获取总的行数int Lines:getLineNum(void) return lines.size();/获取特定行的字符串个数int Lines:getStringNum(int lineIndex) return lineslineIndex.size();输入类void Input:readLines(char* filename, Lines &readLines)/ vectorvector dst; ifstream infile(filename,ios:in); if(!infile) coutopen error!endl; exit

15、(0); char temp100=;/存储从文件中读取的行的临时变量 int lineIndex=0;/行序号 /按行读取 while(infile.getline(temp,100) int k=0,j=0; vector line; line.swap(vector(); readLines.addLine(line); char s20=;/存储从行中取字符串的临时变量 int stringIndex=0;/字符串序号 readLines.addString(s,lineIndex); while(tempk!=0) if(tempk!= ) readLines.addChar(tem

16、pk,stringIndex,lineIndex); /每个单词的截取条件为下一个字符为空格或者为行的末尾 if(tempk= &tempk+1!= ) / readLines.addChar(tempk,stringIndex,lineIndex);/将该字符串加入到指定行的指定字符串中 / readLines.addChar(0,stringIndex,lineIndex); s0=0;/清空字符串 readLines.addString(s,lineIndex); stringIndex+;/字符串序号加1 k+; lineIndex+; / dst.push_back(line);/将

17、从文件中中读出的行加入到dst中 infile.close(); for(int i=0;ireadLines.getLineNum();i+) for(int j=0;jreadLines.getStringNum(i);j+) coutreadLines.getString(i,j) ; coutendl; coutendlendl;循环左移类/实现所有行的循环移位void Shift:circularShift(Lines srcLines) int lineIndex=0; for(int row=0;rowsrcLines.getLineNum();row+) int cols=sr

18、cLines.getStringNum(row); for(int col=0;colcols;col+) vector newLine; lineShift.addLine(newLine); for(int newcol=0;newcolcols;newcol+) lineShift.addString(srcLines.getString(row,(col+newcol)%cols),lineIndex); lineIndex+; /获取所有行Lines Shift:getLines(void) return lineShift;/获取某一行vector Shift:getLine(in

19、t lineIndex) return lineShift.getLine(lineIndex);/获取某一行中某一位置的字符串string Shift:getString(int lineIndex,int stringIndex) return lineShift.getString(lineIndex,stringIndex);/获取某一行中某一个字符串中的某一位置的字符char Shift:getChar(int lineIndex, int stringIndex, int charIndex) return lineShift.getChar(lineIndex,stringInd

20、ex,charIndex);/获取行数int Shift:getLineNum(void) return lineShift.getLineNum();/获取某一行的字符串个数int Shift:getStringNum(int lineIndex) return lineShift.getStringNum(lineIndex);排序类/实现按首字母排序void FirstAlphaSort:alphaSort(Shift srcShiftLines) shiftLines=srcShiftLines;/将传进得Shift对象赋值给成员变量 vector firstChar; for(int

21、 row=0;rowshiftLines.getLineNum();row+) firstChar.push_back(shiftLines.getChar(row,0,0);/获取首字母 /首字母排序 for(int loop=0;loopfirstChar.size();loop+) char min=z; int rowIndex=0; for(int row=0;row=firstCharrow& !=firstCharrow) min=firstCharrow; rowIndex=row; charSort.push_back(rowIndex); firstCharrowIndex

22、= ;/将找到的最小的字母置为 ,以便在下一次查找时不再保留 /首字母排序vector FirstAlphaSort:getCharSort() return charSort;/获取行数int FirstAlphaSort:getLineNum(void) return shiftLines.getLineNum();/按行的序号,将各字符串合并成一个字符串,然后获取一行/lineIndex为行序号string FirstAlphaSort:getLineAsString(int lineIndex) string lineString; for(int strCount=0;strCoun

23、tshiftLines.getStringNum(lineIndex);strCount+) lineString+=shiftLines.getString(lineIndex,strCount)+ ; lineString+=0; return lineString;输出类/按字母表顺序输出void Output:print(FirstAlphaSort sortLines) for(int row=0;rowsortLines.getLineNum();row+) coutsortLines.getLineAsString(sortLines.getCharSort()row)endl; coutendl;4、实验的例程(1)主程序、子程序运行结果(2)抽象收据类型5、总结通过本次实验,首先对软件体系结构有了更真切的了解,尤其是对管道过滤器结构,主程序、子程序结构,抽象数据类型结构,隐式调用这四种结构的理解更加透彻了。同时还对KWIC有个一个认知的过程。在实现的上述两种结构的过程中,对增强了数据结构的掌握,以及对面向对象概念的进一步理解。编程时,遇到了各种大大小小的问题,尤其是数据结构定义方面的,深刻体会到了数据结构的重要性,同时发现了自己编写的代码移植性以及编码风格都不是很好,希望老师给予指点。

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1