數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì)文章編輯附錄中有全部代碼_第1頁(yè)
數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì)文章編輯附錄中有全部代碼_第2頁(yè)
數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì)文章編輯附錄中有全部代碼_第3頁(yè)
數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì)文章編輯附錄中有全部代碼_第4頁(yè)
數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì)文章編輯附錄中有全部代碼_第5頁(yè)
已閱讀5頁(yè),還剩20頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、課程設(shè)計(jì)任務(wù)書專業(yè)名稱:計(jì)算機(jī)科學(xué)與技術(shù)(軟件工程) 課程名稱:數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì)設(shè)計(jì)題目:文章編輯問(wèn)題起止時(shí)間:2013年6 月24 日至2013年7 月12 日問(wèn)題描述靜態(tài)存儲(chǔ)一頁(yè)文章,每行最多不超過(guò)80個(gè)字符,共n行,程序可以統(tǒng)計(jì)出文字、數(shù)字、空格的個(gè)數(shù),并且可以對(duì)文章中特定內(nèi)容進(jìn)行查找及替換,同時(shí)也可以刪除指定內(nèi)容。基本要求(1)分別統(tǒng)計(jì)出其中英文字母數(shù)和空格數(shù)及整篇文章總字?jǐn)?shù);(2)統(tǒng)計(jì)某一字符串在文章中出現(xiàn)的次數(shù),并輸出該次數(shù);(3)查找出文章中某一段文字,并用其他文字進(jìn)行替換;(4)刪除某一子串,并將后面的字符前移。輸出形式:(1)分行輸出用戶輸入的各行字符;(2)分4行輸出全部字

2、母數(shù)、數(shù)字個(gè)數(shù)、空格個(gè)數(shù)、文章總字?jǐn)?shù);(3)查找出指定字符串在文章中出現(xiàn)的所有地方并替換,輸出替換后結(jié)果;(4)輸出刪除某一字符串后的文章;實(shí)現(xiàn)提示存儲(chǔ)結(jié)構(gòu)使用線性表,分別用幾個(gè)子函數(shù)實(shí)現(xiàn)相應(yīng)的功能,并且使用菜單的形式,可以選擇所要進(jìn)行的操作(查找、替換、刪除、統(tǒng)計(jì)等)。文章編輯系統(tǒng)1概要設(shè)計(jì)本次課程設(shè)計(jì)的題目是文章編輯系統(tǒng),本系統(tǒng)的功能描述如下:用戶新建文本、瀏覽新建文本、文本字符統(tǒng)計(jì)、指定字符串統(tǒng)計(jì)、指定字符串刪除、指定字符串替換等操作。1. 新建文本2. 瀏覽輸入文本3. 文本字符統(tǒng)計(jì)4. 指定字符串統(tǒng)計(jì)5. 指定字符串刪除6. 指定字符串替換7. 退出系統(tǒng)本系統(tǒng)包含七個(gè)功能模塊,分別為

3、:新建文本模塊,瀏覽輸入文本模塊,指定字符串統(tǒng)計(jì)模塊,指定字符串刪除模塊,指定字符串刪除模塊,指定字符串替換模塊以退出系統(tǒng)模塊。新建文本模塊實(shí)現(xiàn)用戶錄入文本信息,并且系統(tǒng)自動(dòng)保存錄入信息。瀏覽輸入文本模塊實(shí)現(xiàn)了顯示用戶錄入信息的功能。指定字符串統(tǒng)模塊實(shí)現(xiàn)了對(duì)英文字母數(shù)和空格數(shù)及整篇文章總字?jǐn)?shù)的統(tǒng)計(jì)。指定字符串統(tǒng)計(jì)實(shí)現(xiàn)了統(tǒng)計(jì)用戶自定義字符串個(gè)數(shù)的功能。指定字符串刪除模塊實(shí)現(xiàn)了對(duì)用戶自定義字符串的刪除。指定字符串替換模塊實(shí)現(xiàn)了替換用戶自定義字符串為用戶定義的新字符功能。退出系統(tǒng)模塊實(shí)現(xiàn)了退出系統(tǒng)功能。文章編輯系統(tǒng)瀏覽輸入文本新建文本文本字符統(tǒng)計(jì)指定字符串刪除指定字符串替換指定字符串統(tǒng)計(jì)退出系統(tǒng)圖1

4、.1 系統(tǒng)功能模塊圖2詳細(xì)設(shè)計(jì)這部分詳細(xì)介紹了系統(tǒng)中主要部分的功能實(shí)現(xiàn),以及代碼功能說(shuō)明。void create(line * &head) printf (請(qǐng)輸入一頁(yè)文章,以ctrl+e為結(jié)尾(每行最多輸入80字符!):n); /以ctrl+e結(jié)束文本錄入,避免發(fā)生混淆line *p=new line; /*首先為鏈表 建立一個(gè)附加表頭結(jié)點(diǎn)*/ head=p; /*將p付給 表頭指針*/ char ch100; while(1) gets(ch); /*輸入字符串!*/ if(strlen(ch)80) printf(每行最多輸入80字符); break; if(ch0=5)break; /

5、*如果發(fā)現(xiàn)輸入 e,則退出輸入*/ p=p-next=new line; p-data=new charstrlen(ch)+1; /*為結(jié)點(diǎn)分配空間 */ strcpy(p-data,ch); if(chstrlen(ch)-1=5) /*除去最后一個(gè)控制符 e */ p-datastrlen(ch)-1=0; break; p-next=null; /*最后的一個(gè)指針為空 */ head=head-next;/*文本字?jǐn)?shù)統(tǒng)計(jì)*/int count_space(line* &head)/統(tǒng)計(jì)空格數(shù) line *p=head;int asc_space=32;int count=0;int i

6、;int len;dolen=strlen(p-data);for(i=0;idatai=asc_space)count+;while(p=p-next)!=null);return count;int count_num(line * &head)/統(tǒng)計(jì)數(shù)字個(gè)數(shù) line *p=head;int count=0;int len;int i;dolen=strlen(p-data);for(i=0;idatai=48 & p-datainext)!=null);return count; int count_all_word(line * &head)/統(tǒng)計(jì)文章的總字?jǐn)?shù) line *p=hea

7、d;int count=0;docount+=strlen(p-data);while(p=p-next)!=null);return count;int count_letter(line * &head)/統(tǒng)計(jì)字母數(shù) line *p=head;int count=0;int len;int i;dolen=strlen(p-data);for(i=0;idatai=a & p-dataidatai=a & p-datainext)!=null);return count;int find_word(line * &head,char *sch)/統(tǒng)計(jì) sch 在文章中出現(xiàn)的次數(shù)line *

8、p=head;int count=0;int len1=0;int len2=strlen(sch);int i,j,k;dolen1=strlen(p-data);/當(dāng)前行的字符數(shù)for(i=0;idatai=sch0)k=0;for(j=0;jdatai+j=schj)k=k+1;if(k=len2) count+;i=i+k-1;while(p=p-next)!=null);return count; /*特定字符串的刪除*/void del_string_word(char *s,char *sch) char *p=strstr(s,sch);char tmp80;int len=s

9、trlen(s);int k,kk;int i=len-strlen(p);int j=i+strlen(sch);int count=0;for(k=0;ki;k+)tmpcount+=sk;for(kk=j;kkdata,sch)!=null)del_string_word(p-data,sch);while(p=p-next)!=null);/*特定字符串的替換*/void replace_string_word(char *s,char *sch,char *reh) int stringlen; char canewstring100; char *findpos = strstr(

10、s, sch);/ if(!findpos) | (!sch) / return -1; while(findpos) memset(canewstring, 0, sizeof(canewstring);stringlen = findpos - s;strncpy(canewstring, s, stringlen);strcat(canewstring, reh);strcat(canewstring, findpos + strlen(sch);strcpy(s, canewstring);findpos = strstr(s, sch); /* return 0;*/void rep

11、lace_string(line * &head,char *sch,char *reh)/替換指定的字符串line *p=head;dowhile(strstr(p-data,sch)!=null)replace_string_word(p-data,sch,reh);while(p=p-next)!=null);/*打印輸入的文本*/void outputtxt(line * &head)/向屏幕輸出文章 line *p=head;printf(文本文件輸出如下:);doprintf(%sn,p-data);while(p=p-next)!=null);void count(line *

12、&head)printf(文章統(tǒng)計(jì)信息結(jié)果:n);printf(全部字母數(shù):%dn,count_letter(head);printf(數(shù)字個(gè)數(shù):%dn,count_num(head);printf(空格個(gè)數(shù): %d n,count_space(head);printf(文章總字?jǐn)?shù): %dn,(count_all_word(head)+count_num(head)+count_space(head)+count_letter(head)/2);printf(n);void main()line *head;char sch20;char reh20;char id10;char ch;cha

13、r tmp_sch20;char tmp_rch20;3調(diào)試報(bào)告在本次程序設(shè)計(jì)中,在編譯過(guò)程中,出現(xiàn)了幾次問(wèn)題(1)錯(cuò)誤提示:error c2660: search : function does not take 1 parameters 錯(cuò)誤類型: search函數(shù)參數(shù)錯(cuò)誤 改正方法:將case語(yǔ)句后加break語(yǔ)句進(jìn)行返回。(2)錯(cuò)誤提示: error c2228: left of .search must have class/struct/union type錯(cuò)誤類型:指針?lè)?hào)使用錯(cuò)誤改正方法:將s.search(stu,s)更改為s-search(stu,s)(3)錯(cuò)誤提示:err

14、or c2676: binary : class std:basic_ofstreamchar,struct std:char_traits does not define this operator or a conversion to a type acceptable to the predefined operator錯(cuò)誤類型:文件流輸入輸出符號(hào)使用錯(cuò)誤,錯(cuò)誤使用作為文件寫入操作符。改正方法:將改為。4測(cè)試結(jié)果測(cè)試項(xiàng)目測(cè)試數(shù)據(jù)測(cè)試結(jié)果登陸界面1.新建文本2.瀏覽輸入文本3.文本字符統(tǒng)計(jì)4.指定字符串統(tǒng)計(jì)5.指定字符串刪除6.指定字符串替換7.退出顯示:1.新建文本2.瀏覽輸入文本3.文

15、本字符統(tǒng)計(jì)4.指定字符串統(tǒng)計(jì)5.指定字符串刪除6.指定字符串替換7.退出新建功能輸入1:新建文本abcdefg 1234567顯示:abcdefg 1234567顯示功能輸入2:瀏覽輸入文本 顯示用戶錄入結(jié)果:abcdefg 1234567 統(tǒng)計(jì)功能輸入3:文本字符統(tǒng)計(jì)文章統(tǒng)計(jì)信息結(jié)果:全部字母數(shù):7數(shù)字個(gè)數(shù):7空格個(gè)數(shù):1文章總字?jǐn)?shù):15指定字符串統(tǒng)計(jì)功能輸入4:指定字符串刪除 輸入要統(tǒng)計(jì)字符串:ab出現(xiàn)次數(shù):1指定字符串刪除功能輸入5:指定字符串刪除輸入要?jiǎng)h除字符串:ab刪除后文本文件如下:cdefg 1234567指定字符串替換功能輸入6:指定字符串替換 要替換掉的字符串:cdefg要替

16、換成的字符串:!替換后文本文件如下:! 12345675 使用說(shuō)明本系統(tǒng)開始時(shí)顯示所有選擇項(xiàng)。選擇項(xiàng)采用文字提示,數(shù)字選擇進(jìn)行選擇操作。圖5.1 顯示運(yùn)行界面錄入選項(xiàng):輸入1:新建文本圖5.2 新建文本界面輸入2:瀏覽輸入文本圖5.3 瀏覽輸入文本界面輸入3:文本字符統(tǒng)計(jì)圖5.4 文本字符統(tǒng)計(jì)界面輸入4:指定字符串統(tǒng)計(jì)圖5.5 指定字符串統(tǒng)計(jì)界面輸入5:指定字符串刪除圖5.6 指定字符串刪除界面輸入6:指定字符串替換圖5.7 指定字符串替換界面輸入7:退出圖5.8 退出界面6總結(jié)感謝老師的指導(dǎo)和講解。通過(guò)老師的講解,讓我對(duì)這門課程有了深刻的認(rèn)識(shí)和了解,也讓我對(duì)這門課程有了重新的認(rèn)識(shí)。通過(guò)近兩周

17、的課程設(shè)計(jì)中,我學(xué)到了數(shù)據(jù)結(jié)構(gòu)程序設(shè)計(jì)中對(duì)類的設(shè)計(jì)方法,及對(duì)磁盤文件的操作,從中理解了數(shù)據(jù)結(jié)構(gòu)中的設(shè)計(jì)思想。經(jīng)過(guò)這次集中上機(jī)實(shí)習(xí),我充分意識(shí)到了數(shù)據(jù)結(jié)構(gòu)的用途是非常廣的,功能也非常強(qiáng)大,是學(xué)計(jì)算機(jī)不可缺少的知識(shí);更重要的是,在這次編程中熟悉了編寫一個(gè)比較復(fù)雜程序的流程,以及發(fā)現(xiàn)問(wèn)題、解決問(wèn)題的能力,為了下一次學(xué)習(xí)一門新的計(jì)算機(jī)語(yǔ)言做了充分準(zhǔn)備。在之前感覺(jué)還是遙不可及的功能,現(xiàn)在可以實(shí)現(xiàn)了,這自然要感謝老師和同學(xué)們的熱心幫助,這是我得以及時(shí)完成這個(gè)程序的重要因素。最后還是要感謝老師對(duì)我們孜孜不倦的教導(dǎo)。成績(jī):預(yù)習(xí)報(bào)告 分,系統(tǒng) 分,課設(shè)報(bào)告 分,總分 分,總評(píng): 評(píng)語(yǔ):批閱教師簽字: 年 月 日

18、附錄:全部代碼 #include #include #include #include typedef struct linechar *data;struct line *next;line;void create(line * &head) printf (請(qǐng)輸入一頁(yè)文章,以ctrl+e為結(jié)尾(每行最多輸入80字符!):n);line *p=new line; /*首先為鏈表 建立一個(gè)附加表頭結(jié)點(diǎn)*/ head=p; /*將p付給 表頭指針*/ char ch100; while(1) gets(ch); /*輸入字符串!*/ if(strlen(ch)80) printf(每行最多輸入8

19、0字符); break; if(ch0=5)break; /*如果發(fā)現(xiàn)輸入 e,則退出輸入*/ p=p-next=new line; p-data=new charstrlen(ch)+1; /*為結(jié)點(diǎn)分配空間 */ strcpy(p-data,ch); if(chstrlen(ch)-1=5) /*除去最后一個(gè)控制符 e */ p-datastrlen(ch)-1=0; break; p-next=null; /*最后的一個(gè)指針為空 */ head=head-next;/*文本字?jǐn)?shù)統(tǒng)計(jì)*/int count_space(line* &head)/統(tǒng)計(jì)空格數(shù) line *p=head;int

20、asc_space=32;int count=0;int i;int len;dolen=strlen(p-data);for(i=0;idatai=asc_space)count+;while(p=p-next)!=null);return count;int count_num(line * &head)/統(tǒng)計(jì)數(shù)字個(gè)數(shù) line *p=head;int count=0;int len;int i;dolen=strlen(p-data);for(i=0;idatai=48 & p-datainext)!=null);return count; int count_all_word(line

21、 * &head)/統(tǒng)計(jì)文章的總字?jǐn)?shù) line *p=head;int count=0;docount+=strlen(p-data);while(p=p-next)!=null);return count;int count_letter(line * &head)/統(tǒng)計(jì)字母數(shù) line *p=head;int count=0;int len;int i;dolen=strlen(p-data);for(i=0;idatai=a & p-dataidatai=a & p-datainext)!=null);return count;int find_word(line * &head,cha

22、r *sch)/統(tǒng)計(jì) sch 在文章中出現(xiàn)的次數(shù)line *p=head;int count=0;int len1=0;int len2=strlen(sch);int i,j,k;dolen1=strlen(p-data);/當(dāng)前行的字符數(shù)for(i=0;idatai=sch0)k=0;for(j=0;jdatai+j=schj)k=k+1;if(k=len2) count+;i=i+k-1;while(p=p-next)!=null);return count; /*特定字符串的刪除*/void del_string_word(char *s,char *sch) char *p=strs

23、tr(s,sch);char tmp80;int len=strlen(s);int k,kk;int i=len-strlen(p);int j=i+strlen(sch);int count=0;for(k=0;ki;k+)tmpcount+=sk;for(kk=j;kkdata,sch)!=null)del_string_word(p-data,sch);while(p=p-next)!=null);/*特定字符串的替換*/void replace_string_word(char *s,char *sch,char *reh) int stringlen; char canewstri

24、ng100; char *findpos = strstr(s, sch);/ if(!findpos) | (!sch) / return -1; while(findpos) memset(canewstring, 0, sizeof(canewstring);stringlen = findpos - s;strncpy(canewstring, s, stringlen);strcat(canewstring, reh);strcat(canewstring, findpos + strlen(sch);strcpy(s, canewstring);findpos = strstr(s

25、, sch); /* return 0;*/void replace_string(line * &head,char *sch,char *reh)/替換指定的字符串line *p=head;dowhile(strstr(p-data,sch)!=null)replace_string_word(p-data,sch,reh);while(p=p-next)!=null);/*打印輸入的文本*/void outputtxt(line * &head)/向屏幕輸出文章 line *p=head;printf(文本文件輸出如下:);doprintf(%sn,p-data);while(p=p-n

26、ext)!=null);void count(line * &head)printf(文章統(tǒng)計(jì)信息結(jié)果:n);printf(全部字母數(shù):%dn,count_letter(head);printf(數(shù)字個(gè)數(shù):%dn,count_num(head);printf(空格個(gè)數(shù): %d n,count_space(head);printf(文章總字?jǐn)?shù): %dn,(count_all_word(head)+count_num(head)+count_space(head)+count_letter(head)/2);printf(n);void main()line *head;char sch20;ch

27、ar reh20;char id10;char ch;char tmp_sch20;char tmp_rch20;printf( n);printf( n);printf( 文章編輯系統(tǒng) n);printf( n);printf( n);printf( 學(xué)號(hào):2012023301267 n);while(1)printf( n);printf( n);printf( 1. 新 建 文 本 n);printf( n);printf( 2. 瀏 覽 輸 入 文 本 n);printf( n);printf( 3. 文 本 字 符 統(tǒng) 計(jì) n);printf( n);printf( 4. 指 定 字 符 串 的 統(tǒng) 計(jì) n);printf( n);printf( 5. 指 定 字 符 串 的 刪 除 n);printf( n);printf( 6. 指 定 字 符 串 的 替 換 n);printf( n);printf( 7. 退 出 n);printf( n);printf( *n);printf(請(qǐng) 輸 入 功 能 序 號(hào):);scanf(%s,id);while(1)if(strcmp(id,1)=0)printf(新建文本要覆蓋已有文本,是否繼續(xù)輸入?(y/n)n);getchar();scanf(%

溫馨提示

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

評(píng)論

0/150

提交評(píng)論