KWIC实验总结报告大学计算机C++Word格式文档下载.docx

上传人:b****6 文档编号:17247700 上传时间:2022-11-29 格式:DOCX 页数:16 大小:69.06KB
下载 相关 举报
KWIC实验总结报告大学计算机C++Word格式文档下载.docx_第1页
第1页 / 共16页
KWIC实验总结报告大学计算机C++Word格式文档下载.docx_第2页
第2页 / 共16页
KWIC实验总结报告大学计算机C++Word格式文档下载.docx_第3页
第3页 / 共16页
KWIC实验总结报告大学计算机C++Word格式文档下载.docx_第4页
第4页 / 共16页
KWIC实验总结报告大学计算机C++Word格式文档下载.docx_第5页
第5页 / 共16页
点击查看更多>>
下载资源
资源描述

KWIC实验总结报告大学计算机C++Word格式文档下载.docx

《KWIC实验总结报告大学计算机C++Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《KWIC实验总结报告大学计算机C++Word格式文档下载.docx(16页珍藏版)》请在冰豆网上搜索。

KWIC实验总结报告大学计算机C++Word格式文档下载.docx

2isAbstractDataTypes"

endl;

intchoose=0;

choose;

if(1==choose)//主程序和子程序

{

MainSubroutinemainSub;

vector<

vector<

string>

>

lines=mainSub.readLines(filename);

LINE>

lineIndex=mainSub.shiftString(lines);

lineIndex=mainSub.firstAlphaSort(lineIndex,lines);

mainSub.outPut(lineIndex,lines);

}

else//抽象收据类型

Lines*lines=newLines;

Inputinput;

Shift*shift=newShift;

FirstAlphaSortalphaSort;

Outputoutput;

input.readLines(filename,*lines);

shift->

circularShift(*lines);

alphaSort.alphaSort(*shift);

output.print(alphaSort);

deleteshift;

deletelines;

return0;

}

(2)主程序、子程序结构实现类

//从文件中按行读取

MainSubroutine:

:

readLines(char*filename)

vector<

dst;

ifstreaminfile(filename,ios:

in);

if(!

infile)

cout<

openerror!

exit(0);

chartemp[100]="

//存储从文件中读取的行的临时变量

//按行读取

while(infile.getline(temp,100))

intk=0,j=0;

line;

line.swap(vector<

());

chars[20]="

//存储从行中取字符串的临时变量

while(temp[k]!

=0)

{

//每个单词的截取条件为下一个字符为空格或者为行的末尾

if((temp[k+1]=='

'

||temp[k+1]==0)&

&

temp[k]!

='

{

s[j]=temp[k];

s[j+1]='

\0'

stringss=s;

line.push_back(ss);

j=0;

}

elseif(temp[k]=='

else

j++;

k++;

}

dst.push_back(line);

//将从文件中中读出的行加入到dst中

infile.close();

for(inti=0;

i<

dst.size();

i++)

for(intj=0;

j<

dst.at(i).size();

j++)

cout<

dst[i][j]<

"

returndst;

//循环左移

shiftString(vector<

srcLines)

shiftLines;

for(introw=0;

row<

srcLines.size();

row++)

intcolnum=srcLines[row].size();

//获取每一行的字符串个数

//对第row行循环colnum(字符串个数)次,生成循环移位后的colnum行

for(intcol=0;

col<

colnum;

col++)

LINElinePos;

//声明存放一行的行标以及各列的列表的结构体

linePos.rowIndex=row;

//给行标赋值

//循环生成一行的列标

for(intcolshift=0;

colshift<

colshift++)

linePos.colIndex.push_back((col+colshift)%colnum);

//取模运算

shiftLines.push_back(linePos);

returnshiftLines;

//字母排序

firstAlphaSort(vector<

lineIndex,vector<

char>

firstChar;

dstIndex;

firstCharLine;

//逐行提取各个字符串的首字母

srcLines[row].size();

firstCharLine.push_back(srcLines[row][col][0]);

firstChar.push_back(firstCharLine);

//

introwPos=0;

intcolPos=0;

//外面的两层for循环是控制循环次数的

//内部的两层for循环是遍历所有的字符串首字母,寻找最小的字母

firstChar.size();

firstChar[row].size();

charmin='

z'

for(introw=0;

for(intcol=0;

{

if(min>

=firstChar[row][col]&

'

!

=firstChar[row][col])

{

rowPos=row;

colPos=col;

min=firstChar[row][col];

}

}

firstChar[rowPos][colPos]='

intlinePos=0;

//在原行矩阵中的位置

for(intline=0;

line<

rowPos;

line++)

linePos+=srcLines[line].size();

linePos=linePos+colPos;

dstIndex.push_back(lineIndex[linePos]);

returndstIndex;

//按照lineIndex中的字符串的行标和列标输出所有字符串

voidMainSubroutine:

outPut(vector<

lineIndex,vector<

lineIndex.size();

lineIndex[row].colIndex.size();

srcLines[lineIndex[row].rowIndex][lineIndex[row].colIndex[col]]<

(3)抽象数据类型结构实现

行存储类

//增加行

//参数:

line字符串向量列表

voidLines:

addLine(vector<

line)

lines.push_back(line);

//从存储结构中获取某一行

lineIndex为获取的行的序号,从0开始

//返回获取的行

Lines:

getLine(intlineIndex)

returnlines[lineIndex];

//增加字符串

instring为所添加字符串,lineIndex为字符串所在行的序号(从0开始)

addString(stringinstring,intlineIndex)

lines[lineIndex].push_back(instring);

//获取字符串

lineIndex为行序号,stringIndex为字符串在行中的序号

//返回获取的字符串

stringLines:

getString(intlineIndex,intstringIndex)

returnlines[lineIndex][stringIndex];

//增加字符

inchar为增加的字符,stringIndex为增加的字符所在的字符串的序号,lineIndex为增加的字符所在的行的序号

addChar(charinchar,intstringIndex,intlineIndex)

lines[lineIndex][stringIndex].push_back(inchar);

//获取字符

lineIndex为行序号,stringIndex为字符串的序号,charIndex为字符的序号

//返回获取的字符

charLines:

getChar(intlineIndex,intstringIndex,intcharIndex)

returnlines[lineIndex][stringIndex][charIndex];

//获取总的行数

intLines:

getLineNum(void)

returnlines.size();

//获取特定行的字符串个数

getStringNum(intlineIndex)

returnlines[lineIndex].size();

输入类

voidInput:

readLines(char*filename,Lines&

readLines)

//vector<

intlineIndex=0;

//行序号

readLines.addLine(line);

intstringIndex=0;

//字符串序号

readLines.addString(s,lineIndex);

if(temp[k]!

readLines.addChar(temp[k],stringIndex,lineIndex);

if(temp[k]=='

temp[k+1]!

//readLines.addChar(temp[k],stringIndex,lineIndex);

//将该字符串加入到指定行的指定字符串中

//readLines.addChar('

stringIndex,lineIndex);

s[0]='

//清空字符串

readLines.addString(s,lineIndex);

stringIndex++;

//字符串序号加1

lineIndex++;

//dst.push_back(line);

readLines.getLineNum();

readLines.getStringNum(i);

readLines.getString(i,j)<

循环左移类

//实现所有行的循环移位

voidShift:

circularShift(LinessrcLines)

srcLines.getLineNum();

intcols=srcLines.getStringNum(row);

cols;

vector<

newLine;

lineShift.addLine(newLine);

for(intnewcol=0;

newcol<

newcol++)

lineShift.addString(srcLines.getString(row,(col+newcol)%cols),lineIndex);

lineIndex++;

//获取所有行

LinesShift:

getLines(void)

returnlineShift;

//获取某一行

Shift:

returnlineShift.getLine(lineIndex);

//获取某一行中某一位置的字符串

stringShift:

returnlineShift.getString(lineIndex,stringIndex);

//获取某一行中某一个字符串中的某一位置的字符

charShift:

returnlineShift.getChar(lineIndex,stringIndex,charIndex);

//获取行数

intShift:

returnlineShift.getLineNum();

//获取某一行的字符串个数

returnlineShift.getStringNum(lineIndex);

排序类

//实现按首字母排序

voidFirstAlphaSort:

alphaSort(ShiftsrcShiftLines)

shiftLines=srcShiftLines;

//将传进得Shift对象赋值给成员变量

shiftLines.getLineNum();

firstChar.push_back(shiftLines.getChar(row,0,0));

//获取首字母

//首字母排序

for(intloop=0;

loop<

loop++)

charmin='

introwIndex=0;

for(introw=0;

if(min>

=firstChar[row]&

=firstChar[row])

min=firstChar[row];

rowIndex=row;

charSort.push_back(rowIndex);

firstChar[rowIndex]='

//将找到的最小的字母置为‘’,以便在下一次查找时不再保留

//首字母排序

int>

FirstAlphaSort:

getCharSort()

returncharSort;

intFirstAlphaSort:

returnshiftLines.getLineNum();

//按行的序号,将各字符串合并成一个字符串,然后获取一行

//lineIndex为行序号

stringFirstAlphaSort:

getLineAsString(intlineIndex)

stringlineString;

for(intstrCount=0;

strCount<

shiftLines.getStringNum(lineIndex);

strCount++)

lineString+=shiftLines.getString(lineIndex,strCount)+"

lineString+="

\0"

returnlineString;

输出类

//按字母表顺序输出

voidOutput:

print(FirstAlphaSortsortLines)

sortLines.getLineNum();

sortLines.getLineAsString(sortLines.getCharSort()[row])<

4、实验的例程

(1)主程序、子程序运行结果

(2)抽象收据类型

5、总结

通过本次实验,首先对软件体系结构有了更真切的了解,尤其是对管道过滤器结构,主程序、子程序结构,抽象数据类型结构,隐式调用这四种结构的理解更加透彻了。

同时还对KWIC有个一个认知的过程。

在实现的上述两种结构的过程中,对增强了数据结构的掌握,以及对面向对象概念的进一步理解。

编程时,遇到了各种大大小小的问题,尤其是数据结构定义方面的,深刻体会到了数据结构的重要性,同时发现了自己编写的代码移植性以及编码风格都不是很好,希望老师给予指点。

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 初中教育 > 科学

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

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