數(shù)據(jù)結(jié)構(gòu)上機實驗報告8_第1頁
數(shù)據(jù)結(jié)構(gòu)上機實驗報告8_第2頁
數(shù)據(jù)結(jié)構(gòu)上機實驗報告8_第3頁
數(shù)據(jù)結(jié)構(gòu)上機實驗報告8_第4頁
全文預覽已結(jié)束

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

廣東工業(yè)大學實驗報告___自動化_學院___網(wǎng)絡工程__專業(yè)_3__班學號_3111001381_姓名__何宇航___成績評定_______教師簽名許亮實驗__八__題目___文學研究助手______________課程名稱數(shù)據(jù)結(jié)構(gòu)APAGE一.實驗目的文學研究人員需要統(tǒng)計某篇英文小說中某些形容詞的出現(xiàn)次數(shù)和位置,試寫出一個實現(xiàn)這一目標的文字統(tǒng)計系統(tǒng),成為“文學研究助手”。二.實驗內(nèi)容英文小說存放在一個文本文件中;帶統(tǒng)計的額詞匯集合要以此輸入完畢,即統(tǒng)計工作必須在程序的以此運行后全部完成;程序的輸出結(jié)果是每個詞的出現(xiàn)次數(shù)和出現(xiàn)位置所在的行號。三.實驗步驟(可選)詳細程序設(shè)計:#include<iostream>#include<string>usingnamespacestd;#include<stdio.h>//包含標準輸入輸出函數(shù)structword{ intline; inttime; word*next;};structwords{ charword_re[20]; intcheck; inttime_t; words*next_s; word*next;};words*input(words*head);//比較并存貯信息時候所用的函數(shù)words*output(words*head);//單純輸出直觀數(shù)據(jù)時所使用的函數(shù)words*input(words*head){intcount=0;intline=0;//記錄行數(shù)所使用的變量inttime_words=0;head->next_s=newwords;intcheck=1;words*insert=newwords;word*insert_word=newword;insert=head->next_s;cout<<"請輸入需要查詢的單詞"<<endl;while(check){ cin>>insert->word_re; insert->time_t=0; insert->check=0; insert->next=newword; cout<<"還希望搜索其他的單詞么,1繼續(xù),0停止"<<endl; cin>>check; if(check>=1) { insert->next_s=newwords; insert=insert->next_s; } } insert->next_s=NULL; insert=head->next_s; while(insert!=NULL) { cout<<insert->word_re<<endl; insert=insert->next_s; } insert=NULL; inttime=0; inttime_gk=0,time_wt=0; charcompare[3]="@"; chargetkey[32]; char*word_tair; FILE*getword; if((getword=fopen("英文文件.txt","r"))==NULL) { cout<<"error"; return0; } charword_c[80]; while(fgets(word_c,80,getword)!=NULL)//讀取一行中的8個字符 { line++; time_words=0;//尋找的字符出現(xiàn)的次數(shù) time_gk=0;//儲存用來比較的字符串所使用的變量 time_wt=0;//在儲存行字符串的變量中定位 word_tair=NULL; word_tair=word_c; time=strlen(word_tair); cout<<time; cout<<word_tair<<endl; while(word_tair[time_wt]!='\n') { time_gk=0; if((word_tair[time_wt]<='z'&&word_tair[time_wt]>='a')||(word_tair[time_wt]<='Z'&&word_tair[time_wt]>='A')||word_tair[time_wt]=='-') { while((word_tair[time_wt]<='z'&&word_tair[time_wt]>='a')||(word_tair[time_wt]<='Z'&&word_tair[time_wt]>='A')||word_tair[time_wt]=='-') { getkey[time_gk]=word_tair[time_wt]; time_wt++; time_gk++; }//讀取出一個單詞,并儲存在新的變量中 getkey[time_gk++]='\0'; insert=head->next_s; while(insert!=NULL) { if(!strcmp(insert->word_re,getkey)) { count=insert->check; insert->check++; insert_word=insert->next;//判斷是否是相同的單詞 while(count>0) { insert_word=insert_word->next; count--; } insert_word->line=line; insert_word->time=time_words; insert_word->next=NULL; insert_word->next=newword; break; }//儲存相應的信息 insert=insert->next_s; } time_words++; } if(word_tair[time_wt++]=='\n') break; } } cout<<endl; returnhead;}//輸出函數(shù)words*output(words*head){ inttime=0; words*first=head->next_s; words*insert=first; word*insert_word=newword; while(insert!=NULL) { cout<<insert->word_re<<"單詞共出現(xiàn)了"<<insert->check<<"次"<<endl; insert_word=insert->next; while(insert->check>time) { time++; cout<<"第"<<time<<"次出現(xiàn)在"<<insert_word->line<<"行,第"<<insert_word->time+1<<"個單詞"<<endl; insert_word=insert_word->next; } insert=insert->next_s; time=0; } returnhead;}intmain(){words*head_emp=newwords;strcpy(head_emp->word_re,"thisisempty");//母鏈的頭賦空head_emp->check=-1;head_emp

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論