




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、软件体系结构上机实验报告书中国石油大学(北京)信息学院计算机科学与技术系制 订 人:周新学 号:2008082207指导教师:朱雪峰 博士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=mainSub.firstA
3、lphaSort(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);delete shift;delete l
4、ines;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 line;line.swap(vector();char s20=;/存
5、储从行中取字符串的临时变量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;elsesj=tempk;j+; k+;dst.push_back(line);/将从文件中中读出的行加入到dst中infile.close();for(int i=0;idst.size();i+)for(int j=0;jdst.at(i).size();j+)coutdstij
6、 ;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(int col=0;colcolnum;col+) LINE linePos;/声明存放一行的行标以及各列的列表的结
7、构体 linePos.rowIndex=row;/给行标赋值 /循环生成一行的列标 for(int colshift=0;colshiftcolnum;colshift+) linePos.colIndex.push_back(col+colshift)%colnum);/取模运算 shiftLines.push_back(linePos); return shiftLines;/字母排序vector MainSubroutine:firstAlphaSort(vector lineIndex,vectorvector srcLines)vectorvector firstChar;vecto
8、r 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循环是遍历所有的字符串首字母,寻找最小的字母for(int row=0;rowfirst
9、Char.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;linerowPos;line+)linePos+=srcLine
10、sline.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.size();col+)coutsrcLineslineIndexro
11、w.rowIndexlineIndexrow.colIndexcol ;coutendl;coutendl;(3)抽象数据类型结构实现行存储类/增加行/参数:line字符串向量列表void Lines:addLine(vector line)lines.push_back(line);/从存储结构中获取某一行/参数:lineIndex为获取的行的序号,从0开始/返回获取的行vector Lines:getLine(int lineIndex)return lineslineIndex;/ 增加字符串/参数:instring为所添加字符串,lineIndex为字符串所在行的序号(从0开始)voi
12、d Lines:addString(string instring, int lineIndex)lineslineIndex.push_back(instring);/获取字符串/参数:lineIndex为行序号,stringIndex为字符串在行中的序号/返回获取的字符串string Lines:getString(int lineIndex,int stringIndex)return lineslineIndexstringIndex;/增加字符/参数:inchar为增加的字符,stringIndex为增加的字符所在的字符串的序号,lineIndex为增加的字符所在的行的序号void
13、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 lineslineIndexstringIndexcharIndex;/获取总的行数int Lines:getLineNu
14、m(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(0);char temp100=;/存储从文件中读取的行的临时变量int lineIndex=0;/行
15、序号/按行读取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(tempk,stringIndex,lineIndex);/每个单词的截取条件为下一个字符为空格或者为行的末尾if(tempk= &tem
16、pk+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);/将从文件中中读出的行加入到dst中infile.close();for(int i=0;ireadLines.getLineNum();i+)for(int
17、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=srcLines.getStringNum(row);for(int col=0;colcols;col+)vector newLine;lineShift.addLine(ne
18、wLine);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(int lineIndex)return lineShift.getLine(lineIndex);/获取某一行中某一位置的字符串string Shift:getString(int lineI
19、ndex,int stringIndex)return lineShift.getString(lineIndex,stringIndex);/获取某一行中某一个字符串中的某一位置的字符char Shift:getChar(int lineIndex, int stringIndex, int charIndex)return lineShift.getChar(lineIndex,stringIndex,charIndex);/获取行数int Shift:getLineNum(void)return lineShift.getLineNum();/获取某一行的字符串个数int Shift:g
20、etStringNum(int lineIndex)return lineShift.getStringNum(lineIndex);排序类/实现按首字母排序void FirstAlphaSort:alphaSort(Shift srcShiftLines)shiftLines=srcShiftLines;/将传进得Shift对象赋值给成员变量vector firstChar;for(int row=0;rowshiftLines.getLineNum();row+)firstChar.push_back(shiftLines.getChar(row,0,0);/获取首字母/首字母排序for(
21、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= ;/将找到的最小的字母置为 ,以便在下一次查找时不再保留/首字母排序vector FirstAlphaSort:getCharSort()return charSort;/获取行数int FirstAlphaSort:getLineNum(void)return shiftLines.getLineNum();/按行的序号,将各字符串合并成一个字符串,然后获取一行/lin
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 华图教师面试说课课件
- 贵港高考数学试卷
- 槐荫区教师小学数学试卷
- 杭州文晖中学数学试卷
- 2025年广东省深圳建文外国语学校物理高一第二学期期末考试模拟试题含解析
- 2025年地板行业市场专项调研及投资前景可行性预测报告
- 2025年中国海参养殖行业市场调研分析及投资战略咨询报告
- 中国激光振镜控制系统行业市场发展监测及投资潜力预测报告
- 健康研究视频课件下载网
- 水利审计报告
- 关于中学生课余生活的调研报告
- 全国普通高等学校毕业生就业协议书
- 皖2015s209 混凝土砌块式排水检查井
- 2023火力发电厂热工开关量和模拟量控制系统设计规程
- 史记《孔子世家》原文
- 妊娠高血压综合征眼底病变
- 宿州市国企招聘考试真题及答案
- 国开大学2023年01月11237《物流管理基础》期末考试答案
- 2023年探月与航天工程中心招聘笔试备考试题及答案解析
- 胃癌常见手术方式
- 中国新闻社 笔试 综合知识(有标准答案)
评论
0/150
提交评论