c大作業(yè)字符串類解讀_第1頁
c大作業(yè)字符串類解讀_第2頁
c大作業(yè)字符串類解讀_第3頁
c大作業(yè)字符串類解讀_第4頁
c大作業(yè)字符串類解讀_第5頁
已閱讀5頁,還剩46頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

面向?qū)ο蟪绦蛟O(shè)計(jì)大作業(yè)------字符串類學(xué)院名稱信息科學(xué)與工程學(xué)院專業(yè)班級數(shù)學(xué)類11-2學(xué)生姓名吳亞洲學(xué)號201101051327指導(dǎo)教師完成時間:年代日字符串類編程目的編寫一個能完成標(biāo)準(zhǔn)庫函數(shù)string類的主要功能的字符串類,使我們在不調(diào)用string類庫函數(shù)的情況下正常使用string類的常用構(gòu)造函數(shù)、操作符、常用成員函數(shù)以及特別輸入輸出的實(shí)現(xiàn)。系統(tǒng)簡介系統(tǒng)共包括string類的28個常用構(gòu)造函數(shù)、操作符、常用常用成員函數(shù)以及其他四個輸入輸出的實(shí)現(xiàn)。一、構(gòu)造函數(shù)(1)string();其為默認(rèn)構(gòu)造函數(shù),功能為建立一個長度為0的串。(2)string(conststring&rhs);其為復(fù)制構(gòu)造函數(shù),功能為將rhs的字符串復(fù)制給另string類的對象。(3)string(constchar*s);其功能為用指針s所指向的字符串常量初始化string類的對象。(4)string(conststring&rhs,unsignedintpos,unsignedintn);其功能為將對象rhs中的串從地址pos開始取n個字符,用來初始化string類的對象。注:串的第一個字符的地址為0。(5)string(constchar*s,unsignedintn)其功能為用指針s所指向的字符串中的前n個字符初始化string1類的對象。(6)string(unsignedintn,charc)其功能為將參數(shù)c中的字符重復(fù)n次,用來初始化string類的對象。二、string類的操作符+示例:s+t其功能為將串s和t連接成一個新串。=示例:s=t其功能為將t更新s。+=示例:s+=t其功能等價于s=s+t。==示例:s==t其功能為判斷s與t可否相等。!=示例:s!=t其功能為判斷s與t可否不同樣。<示例:s<t其功能為判斷s可否小于t。<=示例:s<=t其功能為判斷s可否小于或等于t。>示例:s>t其功能為判斷s可否大于t>=示例:s>=t2其功能為判斷s可否大于或等于t。[]示例:s[i]其功能為接見串中下標(biāo)為i的字符。三、常用成員函數(shù)(1)Stringappend(constchar*s);其功能為將字符串s增加在本串尾。(2)Stringappend(constchar*s);其功能為將s所指向的字符串賦值給本對象。(3)intcompare(conststring&str)const;其功能為比較本串與str中串的大小,當(dāng)本串<str串時,返回負(fù)數(shù);當(dāng)本串>str串時,返回正數(shù);兩串相等時,返回0。(4)String&insert(unsignedintp0,constchar*s);其功能為將s所指向的字符串插入在本串地址p0從前。(5)Stringsubstr(unsignedintpos,unsignedintn)const;其功能為取子串,取本串中地址pos開始的n個字符,構(gòu)成新的String類對象作為返回值。(6)unsignedintfind(constString&str)const;其功能為查找并返回str在本串中第一次出現(xiàn)的地址。(7)unsignedintlength()const;其功能為返回串的長度(字符個數(shù))。(8)voidswap(string&str);其功能為將本串與str中的字符串進(jìn)行交換。3四、特別輸入輸出(1)friendistream&operator>>(istream&cin,String&t)其功能為輸入對象的字符串。(2)friendostream&operator<<(ostream&cout,constString&t)其功能為輸出對象的字符串。(3)friendvoidgetline(istream&cin,String&t)其功能為輸入對象的字符串。(4)friendvoidgetline(istream&cin,String&t,charas)其功能為輸入對象的字符串,直到輸入as字符時結(jié)束。編程思路經(jīng)過利用char字符串過分來完成string類對象的所有操作,以及主要利用for、while循環(huán)來完成字符串之間的賦值以及字符串的長度、截取等。整體設(shè)計(jì)(附類圖)利用多文件構(gòu)造分別將類、類的實(shí)現(xiàn)、主函數(shù)放在三個不同樣的文件里,以便其簡單易懂、可分解。充分利用已知char種類的性質(zhì),經(jīng)過char和循環(huán)體實(shí)現(xiàn)String類的各種string類常用字符串辦理函數(shù)。利用構(gòu)造函數(shù)的重載來實(shí)現(xiàn)String類的各種常用初始化。利用主函數(shù)和標(biāo)準(zhǔn)string類檢驗(yàn)自己創(chuàng)立的類可否吻合string類的要求并改正。4類圖String-s[MAXLEN]:char*-len:int+operator+(String&s11):String+operator=(String&s22):String&+operator+=(String&s33):String&+operator==(String&s44):bool+operator!=(String&s55):bool+operator<(String&s66):bool+operator<=(String&s66):bool+operator>(String&s77):bool+operator>=(String&s77):bool+operator[](inta):char&+append(constchar*s88):String+assign(constchar*s99):String+compare(constString&saa)const:int+insert(unsignedintpo,constchar*tt):String&+substr(unsignedintpos,unsignedintn)const:String+find(constString&str)const:unsignedint+length()const:unsignedint+swap(String&str):void要點(diǎn)技術(shù)說明經(jīng)過成員函數(shù)和成員函數(shù)的重載,構(gòu)造函數(shù)和構(gòu)造函數(shù)的重載,友元函數(shù),運(yùn)算符的重載來完成所有string類的所有需完成成員函數(shù)。5源代碼#ifndef__STRINGC_H__#define__STRINGC_H__#include<iostream>usingnamespacestd;constintMAXLEN=1000;classString{public:String();//1String(constString&rhs);//2String(char*ss);//3String(constString&rhs,unsignedintpos,unsignedintn);//4String(constchar*sbbb,unsignedintn);//5String(unsignedintn,charc);//6Stringoperator+(String&s11);//7String&operator=(String&s22);//8String&operator+=(String&s33);//9booloperator==(String&s44);//10booloperator!=(String&s55);//11booloperator<(String&s66);///12booloperator<=(String&s66);///13booloperator>(String&s77);//14booloperator>=(String&s77);//15char&operator[](inta);///16Stringappend(constchar*s88);///17Stringassign(constchar*s99);////18intcompare(constString&saa)const;////19String&insert(unsignedintpo,constchar*tt);//20Stringsubstr(unsignedintpos,unsignedintn)const;///21unsignedintfind(constString&str)const;//////22unsignedintlength()const;////23voidswap(String&str);///246friendistream&operator>>(istream&cin,String&t)////25{chara[1000];cin>>a;inti=0,j=0;while(a[i]){t.s[j++]=a[i];i++;}t.len=j;t.s[j]=0;returncin;}friendostream&operator<<(ostream&cout,constString&t)////26{cout<<t.s;returncout;}friendvoidgetline(istream&cin,String&t);////27friendvoidgetline(istream&cin,String&t,charas);/////28private:chars[MAXLEN];intlen;};#endif#include"stringc.h"#include<iostream>usingnamespacestd;String::String(){s[0]=0;len=0;}7String::String(constString&rhs)//2{inti=0;while(rhs.s[i]){s[i]=rhs.s[i];i++;}len=rhs.len;s[len]=0;}String::String(char*ss)//3{inti=0;while(ss[i]){s[i]=ss[i];i++;}len=i;s[len]=0;}String::String(constString&rhs,unsignedintpos,unsignedintn)//4{inti,j=pos;for(i=0;i<n&&rhs.s[j]!=0;i++){s[i]=rhs.s[j];j++;}len=i;s[i]=0;}String::String(constchar*sbbb,unsignedintn)//58{inti=0,j;for(j=0;j<n;j++){s[i++]=sbbb[j];}len=i;s[i]=0;}String::String(unsignedintn,charc)//6{inti=0,j=0;for(i;i<n;i++){s[j++]=c;}len=j;s[len]=0;}StringString::operator+(String&s11)//7{Strings1;inti,j,xia=0;for(i=0;i<len;i++){s1.s[xia++]=s[i];}for(j=0;j<s11.len;j++){s1.s[xia++]=s11.s[j];}s1.s[xia]=0;s1.len=len+s11.len;returns1;9}String&String::operator=(String&s22)//8{Strings2;inti,j=0;for(i=0;i<s22.len;i++){s[j++]=s22.s[i];}s[j]=0;len=s22.len;returnString(s);}String&String::operator+=(String&s33)//9{Strings3;inti=len,j;for(j=0;j<s33.len;j++){s[len++]=s33.s[j];}s[len]=0;returnString(s);}boolString::operator==(String&s44)//10{if(len!=s44.len)returnfalse;else{for(inti=0;i<len;i++){if(s[i]!=s44.s[i])returnfalse;10}returntrue;}}boolString::operator!=(String&s55)//11{if(len!=s55.len)returntrue;else{for(inti=0;i<len;i++){if(s[i]!=s55.s[i])returntrue;}returnfalse;}}boolString::operator<(String&s66)///12{if(len<s66.len){for(inti=0;i<len;i++){if(s[i]<s66.s[i])returntrue;if(s[i]>s66.s[i])returnfalse;}returntrue;}if(len>=s66.len){for(inti=0;i<s66.len;i++)11{if(s[i]>s66.s[i])returnfalse;if(s[i]<s66.s[i])returntrue;}returnfalse;}}boolString::operator<=(String&s66)///13{if(len<s66.len){for(inti=0;i<len;i++){if(s[i]<s66.s[i])returntrue;if(s[i]>s66.s[i])returnfalse;}returntrue;}if(len>s66.len){for(inti=0;i<s66.len;i++){if(s[i]>s66.s[i])returnfalse;if(s[i]<s66.s[i])returntrue;}returnfalse;}if(len==s66.len)12{for(inti=0;i<s66.len;i++){if(s[i]>s66.s[i])returnfalse;if(s[i]<s66.s[i])returntrue;}returntrue;}}boolString::operator>(String&s77)//14{if(len<=s77.len){for(inti=0;i<len;i++){if(s[i]<s77.s[i])returnfalse;if(s[i]>s77.s[i])returntrue;}returnfalse;}if(len>s77.len){for(inti=0;i<s77.len;i++){if(s[i]>s77.s[i])returntrue;if(s[i]<s77.s[i])returnfalse;}returntrue;13}}boolString::operator>=(String&s77)//15{if(len<s77.len){for(inti=0;i<len;i++){if(s[i]<s77.s[i])returnfalse;if(s[i]>s77.s[i])returntrue;}returnfalse;}if(len==s77.len){for(inti=0;i<len;i++){if(s[i]<s77.s[i])returnfalse;if(s[i]>s77.s[i])returntrue;}returntrue;}if(len>s77.len){for(inti=0;i<s77.len;i++){if(s[i]>s77.s[i])returntrue;if(s[i]<s77.s[i])returnfalse;14}returntrue;}}char&String::operator[](inta)///16{returns[a];}StringString::append(constchar*s88)///17{inti=0;while(s88[i]){s[len++]=s88[i];i++;}s[len]=0;returnString(s);}StringString::assign(constchar*s99)////18{inti=0;while(s99[i]){s[i]=s99[i];i++;}s[i]=0;len=i;returnString(s);}intString::compare(constString&saa)const////19{if(len==saa.len)15{for(inti=0;i<saa.len;i++){if(s[i]>saa.s[i])return1;if(s[i]<saa.s[i])return-1;}return0;}if(len>saa.len){for(inti=0;i<saa.len;i++){if(s[i]>saa.s[i])return1;if(s[i]<saa.s[i])return-1;}return1;}if(len<saa.len){for(inti=0;i<len;i++){if(s[i]>saa.s[i])return1;if(s[i]<saa.s[i])return-1;}return-1;}}String&String::insert(unsignedintpo,constchar*tt)//2016{chara[1000];inti,j=0,k=0,l=0,m=po;for(i=po;i<len;i++){a[j++]=s[i];}a[j]=0;while(tt[k]){s[m++]=tt[k];k++;}while(a[l]){s[m++]=a[l];l++;}s[m]=0;len=m;returnString(s);}StringString::substr(unsignedintpos,unsignedintn)const///21{Stringt;inti=0,j=pos;for(j=pos;j<pos+n;j++){t.s[i++]=s[j];}t.len=i;t.s[i]=0;returnt;}17unsignedintString::find(constString&str)const//////22{intm=0,j;for(j=0;j<len;){intk=j,i=0,xxx=0;for(j;j<k+str.len;j++){if(s[j]!=str.s[i++]){xxx=1;break;}}if(xxx==0){m++;j=k+str.len;}elsej++;}returnm;}unsignedintString::length()const////23{returnlen;}voidString::swap(String&str)///24{charaaa[1000];inti=0,j=0,l=str.len;while(s[i]){18aaa[j++]=s[i];i++;}aaa[j]=0;i=0;j=0;while(str.s[i]){s[j++]=str.s[i];i++;}s[j]=0;i=0;j=0;while(aaa[i]){str.s[j++]=aaa[i];i++;}str.s[j]=0;str.len=len;len=l;}voidgetline(istream&cin,String&t)////27{chara[1000];cin>>a;inti=0,j=0;while(a[i]){t.s[j++]=a[i];i++;}t.len=j;19t.s[j]=0;}voidgetline(istream&cin,String&t,charas)/////28{inti=0;chara;for(;;){cin>>a;if(a==as)break;elset.s[i++]=a;}t.s[i]=0;t.len=i;}#include"stringc.h"#include<iostream>usingnamespacestd;intmain(){cout<<"String()的實(shí)現(xiàn)"<<endl;Stringa1;cout<<"a1字符串及其長度"<<endl;cout<<"字符串為:"<<a1<<endl<<"字符長度為:"<<a1.length()<<endl;cout<<"String(constString&rhs)的實(shí)現(xiàn)"<<endl;Stringa2="asdf",a3(a2);cout<<"a2字符串及其長度"<<endl;cout<<"字符串為:"<<a2<<endl<<"字符長度為:"<<a2.length()<<endl;cout<<"a3(a2)字符串及其長度"<<endl;cout<<"字符串為:"<<a3<<endl<<"字符長度20為:"<<a3.length()<<endl;cout<<"String(char*ss)的實(shí)現(xiàn)"<<endl;charb1[10]="abcde";cout<<"b1字符串"<<endl;cout<<b1<<endl;Stringa4(b1);cout<<"a4(b1)字符串及其長度"<<endl;cout<<"字符串為:"<<a4<<endl<<"字符長度為:"<<a4.length()<<endl;cout<<"String(constString&rhs,unsignedintpos,unsignedintn)的實(shí)現(xiàn)"<<endl;Stringa5="abcdef",a6(a5,1,4),a7(a5,3,3),a8(a5,3,5);cout<<"a5字符串及其長度"<<endl;cout<<"字符串為:"<<a5<<endl<<"字符長度為:"<<a5.length()<<endl;cout<<"a6(a5,1,4)字符串及其長度"<<endl;cout<<"字符串為:"<<a6<<endl<<"字符長度為:"<<a6.length()<<endl;cout<<"a7(a5,3,3)字符串及其長度"<<endl;cout<<"字符串為:"<<a7<<endl<<"字符長度為:"<<a7.length()<<endl;cout<<"a8(a5,3,5)字符串及其長度"<<endl;cout<<"字符串為:"<<a8<<endl<<"字符長度為:"<<a8.length()<<endl;cout<<"String(constchar*sbbb,unsignedintn)的實(shí)現(xiàn)"<<endl;charb2[10]="abcdef";Stringa9(b2,4),a10(b2,8);cout<<"a9(b2,4)字符串及其長度"<<endl;cout<<"字符串為:"<<a9<<endl<<"字符長度為:"<<a9.length()<<endl;cout<<"a10(b2,8)字符串及其長度"<<endl;cout<<"字符串為:"<<a10<<endl<<"字符長度為:"<<a10.length()<<endl;cout<<"String(unsignedintn,charc)的實(shí)現(xiàn)"<<endl;21charb3='d';Stringa11(5,b3);cout<<"b3的字符:"<<b3<<endl;cout<<"a11字符串及其長度"<<endl;cout<<"字符串為:"<<a11<<endl<<"字符長度為:"<<a11.length()<<endl;cout<<"+的實(shí)現(xiàn)"<<endl;Stringa12="abcd",a13="efg",a14;a14=a12+a13;cout<<"a12字符串及其長度"<<endl;cout<<"字符串為:"<<a12<<endl<<"字符長度為:"<<a12.length()<<endl;cout<<"a13字符串及其長度"<<endl;cout<<"字符串為:"<<a13<<endl<<"字符長度為:"<<a13.length()<<endl;cout<<"a14=a12+a13字符串及其長度"<<endl;cout<<"字符串為:"<<a14<<endl<<"字符長度為:"<<a14.length()<<endl;cout<<"=的實(shí)現(xiàn)"<<endl;Stringa15="asdfg",a16;a16=a15;cout<<"a15字符串及其長度"<<endl;cout<<"字符串為:"<<a15<<endl<<"字符長度為:"<<a15.length()<<endl;cout<<"a16=a15字符串及其長度"<<endl;cout<<"字符串為:"<<a16<<endl<<"字符長度為:"<<a16.length()<<endl;cout<<"+=的實(shí)現(xiàn)"<<endl;Stringa17="abcde",a18="fgh";cout<<"a17字符串及其長度"<<endl;cout<<"字符串為:"<<a17<<endl<<"字符長度為:"<<a17.length()<<endl;cout<<"a18字符串及其長度"<<endl;cout<<"字符串為:"<<a18<<endl<<"字符長度22為:"<<a18.length()<<endl;a17+=a18;cout<<"a17+=a18字符串及其長度"<<endl;cout<<"字符串為:"<<a17<<endl<<"字符長度為:"<<a17.length()<<endl;cout<<"==的實(shí)現(xiàn)"<<endl;Stringa19="abcde",a20="abcde",a21="abcdef";cout<<"a19字符串為:"<<a19<<endl;cout<<"a20字符串為:"<<a20<<endl;cout<<"a21字符串為:"<<a21<<endl;cout<<"a19與a20可否相等"<<endl;if(a19==a20)cout<<"是"<<endl;elsecout<<"否"<<endl;cout<<"a19與a21可否相等"<<endl;if(a19==a21)cout<<"是"<<endl;elsecout<<"否"<<endl;cout<<"!=的實(shí)現(xiàn)"<<endl;cout<<"a19與a20可否不相等"<<endl;if(a19!=a20)cout<<"是"<<endl;elsecout<<"否"<<endl;cout<<"a19與a21可否不相等"<<endl;if(a19!=a21)cout<<"是"<<endl;elsecout<<"否"<<endl;cout<<"<的實(shí)現(xiàn)"<<endl;cout<<"a19可否小于a20"<<endl;if(a19<a20)23cout<<"是"<<endl;elsecout<<"否"<<endl;cout<<"a19可否小于a21"<<endl;if(a19<a21)cout<<"是"<<endl;elsecout<<"否"<<endl;cout<<"<=的實(shí)現(xiàn)"<<endl;cout<<"a19可否小于等于a20"<<endl;if(a19<=a20)cout<<"是"<<endl;elsecout<<"否"<<endl;cout<<"a19可否小于等于a21"<<endl;if(a19<=a21)cout<<"是"<<endl;elsecout<<"否"<<endl;cout<<">的實(shí)現(xiàn)"<<endl;cout<<"a19可否大于a20"<<endl;if(a19>a20)cout<<"是"<<endl;elsecout<<"否"<<endl;cout<<"a19可否大于a21"<<endl;if(a19>a21)cout<<"是"<<endl;elsecout<<"否"<<endl;cout<<">=的實(shí)現(xiàn)"<<endl;cout<<"a19可否大于等于a20"<<endl;if(a19>=a20)cout<<"是"<<endl;24elsecout<<"否"<<endl;cout<<"a19可否大于等于a21"<<endl;if(a19>=a21)cout<<"是"<<endl;elsecout<<"否"<<endl;cout<<"[]的實(shí)現(xiàn)"<<endl;Stringa22="abcd";cout<<"a22字符串為:"<<a22<<endl;cout<<"a22[2]的字符:"<<a22[2]<<endl;Stringa23="abcd";charb4[10]="efg";cout<<"Stringappend(constchar*s88)的實(shí)現(xiàn)"<<endl;cout<<"b4字符串"<<endl<<b4<<endl;cout<<"a23字符串及其長度"<<endl;cout<<"字符串為:"<<a23<<endl<<"字符長度為:"<<a23.length()<<endl;a23.append(b4);cout<<"a23.append(b4)字符串及其長度"<<endl;cout<<"字符串為:"<<a23<<endl<<"字符長度為:"<<a23.length()<<endl;Stringa24;charb5[10]="efgh";cout<<"Stringassign(constchar*s99)的實(shí)現(xiàn)"<<endl;cout<<"b5字符串"<<endl<<b5<<endl;cout<<"a24字符串及其長度"<<endl;a24.assign(b5);cout<<"字符串為:"<<a24<<endl<<"字符長度為:"<<a24.length()<<endl;Stringa25="efgh",a26="efgh",a27="efgi",a28="efgg";cout<<"Stringassign(constchar*s99)的實(shí)現(xiàn)"<<endl;cout<<"a25字符串:"<<a25<<endl;cout<<"a26字符串:"<<a26<<endl;25cout<<"a27字符串:"<<a27<<endl;cout<<"比較a25與a26的大小"<<endl;cout<<pare(a26)<<endl;cout<<"比較a25與a27的大小"<<endl;cout<<pare(a27)<<endl;cout<<"比較a25與a28的大小"<<endl;cout<<pare(a28)<<endl;Stringa29="abcde";charb6[10]="hij";cout<<"String&insert(unsignedintpo,constchar*tt)的實(shí)現(xiàn)"<<endl;cout<<"b6字符串:"<<b6<<endl;cout<<"a29字符串及其長度"<<endl;cout<<"字符串為:"<<a29<<endl<<"字符長度為:"<<a29.length()<<endl;a29.insert(2,b6);cout<<"a29.insert(2,b6)字符串及其長度"<<endl;cout<<"字符串為:"<<a29<<endl<<"字符長度為:"<<a29.length()<<endl;Stringa30="abcdefg",a31;cout<<"Stringsubstr(unsignedintpos,unsignedintn)const的實(shí)現(xiàn)"<<endl;cout<<"a29字符串及其長度"<<endl;cout<<"字符串為:"<<a30<<endl<<"字符長度為:"<<a30.length()<<endl;a31=a30.substr(2,4);cout<<"a31=a30.substr(2,4)字符串及其長度"<<endl;cout<<"字符串為:"<<a31<<endl<<"字符長度為:"<<a31.length()<<endl;Stringa32="abcdefgabcdefg",a33="bc",a34="fg";cout<<"unsignedintfind(constString&str)const的實(shí)現(xiàn)"<<endl;cout<<"a32字符串:"<<a32<<endl;cout<<"a33字符串:"<<a33<<endl;cout<<"a34字符串:"<<a34<<endl;cout<<"a33在a32首次出現(xiàn)的地址"<<endl;26cout<<a32.find(a33)<<endl;cout<<"a34在a32首次出現(xiàn)的地址"<<endl;cout<<a32.find(a34)<<endl;Stringa35="abcdef",a36="bc",a37;cout<<"unsignedintlength()const的實(shí)現(xiàn)"<<endl;cout<<"a35字符串:"<<a35<<endl;cout<<"a36字符串:"<<a36<<endl;cout<<"a37字符串:"<<a37<<endl;cout<<"a35的長度"<<endl;cout<<a35.length()<<endl;cout<<"a36的長度"<<endl;cout<<a36.length()<<endl;cout<<"a37的長度"<<endl;cout<<a37.length()<<endl;Stringa38="abcdefg",a39="abc";cout<<"voidswap(String&str)的實(shí)現(xiàn)"<<endl;cout<<"a38字符串及其長度"<<endl;cout<<"字符串為:"<<a38<<endl<<"字符長度為:"<<a38.length()<<endl;cout<<"a39字符串及其長度"<<endl;cout<<"字符串為:"<<a39<<endl<<"字符長度為:"<<a39.length()<<endl;a38.swap(a39);cout<<"經(jīng)過swap()交換后的a38與a39的字符串及其長度"<<endl;cout<<"a38字符串及其長度"<<endl;cout<<"字符串為:"<<a38<<endl<<"字符長度為:"<<a38.length()<<endl;cout<<"a39字符串及其長度"<<endl;cout<<"字符串為:"<<a39<<endl<<"字符長度為:"<<a39.length()<<endl;Stringa40,a41;cout<<"cin>>的實(shí)現(xiàn)"<<endl;cout<<"請輸入a40的字符串"<<endl;cin>>a40;27cout<<"請輸入a41的字符串"<<endl;cin>>a41;cout<<"cout<<的實(shí)現(xiàn)"<<endl;cout<<"a40的輸出"<<endl;cout<<a40<<endl;cout<<"a41的輸出"<<endl;cout<<a41<<endl;Stringa42;cout<<"getline(istream&cin,String&t)的實(shí)現(xiàn)"<<endl;cout<<"請輸入a42的字符串"<<endl;getline(cin,a42);cout<<"a42字符串及其長度"<<endl;cout<<"字符串為:"<<a42<<endl<<"字符長度為:"<<a42.length()<<endl;Stringa43,a44;cout<<"getline(istream&cin,String&t,charas)的實(shí)現(xiàn)"<<endl;charb7=',',b8='f';cout<<"b7的字符:"<<b7<<endl;cout<<"請輸入a43的字符串"<<endl;getline(cin,a43,b7);cout<<"a42字符串及其長度"<<endl;cout<<"字符串為:"<<a43<<endl<<"字符長度為:"<<a43.length()<<endl;cout<<"b8的字符:"<<b8<<endl;cout<<"請輸入a44的字符串"<<endl;getline(cin,a44,b8);cout<<"a42字符串及其長度"<<endl;cout<<"字符串為:"<<a44<<endl<<"字符長度為:"<<a44.length()<<endl;return0;}測試(主界面及各功能模塊的運(yùn)行圖及說明)的實(shí)現(xiàn)28cout<<"String()的實(shí)現(xiàn)"<<endl;Stringa1;cout<<"a1字符串及其長度"<<endl;cout<<"字符串為:"<<a1<<endl<<"字符長度為:"<<a1.length()<<endl;的實(shí)現(xiàn)cout<<"String(constString&rhs)的實(shí)現(xiàn)"<<endl;Stringa2="asdf",a3(a2);cout<<"a2字符串及其長度"<<endl;cout<<"字符串為:"<<a2<<endl<<"字符長度為:"<<a2.length()<<endl;cout<<"a3(a2)字符串及其長度"<<endl;cout<<"字符串為:"<<a3<<endl<<"字符長度為:"<<a3.length()<<endl;的實(shí)現(xiàn)cout<<"String(char*ss)的實(shí)現(xiàn)"<<endl;charb1[10]="abcde";cout<<"b1字符串"<<endl;cout<<b1<<endl;Stringa4(b1);cout<<"a4(b1)字符串及其長度"<<endl;cout<<"字符串為:"<<a4<<endl<<"字符長度29為:"<<a4.length()<<endl;的實(shí)現(xiàn)cout<<"String(constString&rhs,unsignedintpos,unsignedintn)的實(shí)現(xiàn)"<<endl;Stringa5="abcdef",a6(a5,1,4),a7(a5,3,3),a8(a5,3,5);cout<<"a5字符串及其長度"<<endl;cout<<"字符串為:"<<a5<<endl<<"字符長度為:"<<a5.length()<<endl;cout<<"a6(a5,1,4)字符串及其長度"<<endl;cout<<"字符串為:"<<a6<<endl<<"字符長度為:"<<a6.length()<<endl;cout<<"a7(a5,3,3)字符串及其長度"<<endl;cout<<"字符串為:"<<a7<<endl<<"字符長度為:"<<a7.length()<<endl;cout<<"a8(a5,3,5)字符串及其長度"<<endl;cout<<"字符串為:"<<a8<<endl<<"字符長度為:"<<a8.length()<<endl;的實(shí)現(xiàn)30cout<<"String(constchar*sbbb,unsignedintn)的實(shí)現(xiàn)"<<endl;charb2[10]="abcdef";Stringa9(b2,4),a10(b2,8);cout<<"a9(b2,4)字符串及其長度"<<endl;cout<<"字符串為:"<<a9<<endl<<"字符長度為:"<<a9.length()<<endl;cout<<"a10(b2,8)字符串及其長度"<<endl;cout<<"字符串為:"<<a10<<endl<<"字符長度為:"<<a10.length()<<endl;的實(shí)現(xiàn)cout<<"String(unsignedintn,charc)的實(shí)現(xiàn)"<<endl;charb3='d';Stringa11(5,b3);cout<<"b3的字符:"<<b3<<endl;cout<<"a11字符串及其長度"<<endl;cout<<"字符串為:"<<a11<<endl<<"字符長度為:"<<a11.length()<<endl;的實(shí)現(xiàn)cout<<"+的實(shí)現(xiàn)"<<endl;Stringa12="abcd",a13="efg",a14;a14=a12+a13;31cout<<"a12字符串及其長度"<<endl;cout<<"字符串為:"<<a12<<endl<<"字符長度為:"<<a12.length()<<endl;cout<<"a13字符串及其長度"<<endl;cout<<"字符串為:"<<a13<<endl<<"字符長度為:"<<a13.length()<<endl;cout<<"a14=a12+a13字符串及其長度"<<endl;cout<<"字符串為:"<<a14<<endl<<"字符長度為:"<<a14.length()<<endl;的實(shí)現(xiàn)cout<<"=的實(shí)現(xiàn)"<<endl;Stringa15="asdfg",a16;a16=a15;cout<<"a15字符串及其長度"<<endl;cout<<"字符串為:"<<a15<<endl<<"字符長度為:"<<a15.length()<<endl;cout<<"a16=a15字符串及其長度"<<endl;cout<<"字符串為:"<<a16<<endl<<"字符長度為:"<<a16.length()<<endl;329的實(shí)現(xiàn)cout<<"+=的實(shí)現(xiàn)"<<endl;Stringa17="abcde",a18="fgh";cout<<"a17字符串及其長度"<<endl;cout<<"字符串為:"<<a17<<endl<<"字符長度為:"<<a17.length()<<endl;cout<<"a18字符串及其長度"<<endl;cout<<"字符串為:"<<a18<<endl<<"字符長度為:"<<a18.length()<<endl;a17+=a18;cout<<"a17+=a18字符串及其長度"<<endl;cout<<"字符串為:"<<a17<<endl<<"字符長度為:"<<a17.length()<<endl;的實(shí)現(xiàn)cout<<"==的實(shí)現(xiàn)"<<endl;Stringa19="abcde",a20="abcde",a21="abcdef";cout<<"a19字符串為:"<<a19<<endl;cout<<"a20字符串為:"<<a20<<endl;cout<<"a21字符串為:"<<a21<<endl;cout<<"a19與a20可否相等"<<endl;if(a19==a20)cout<<"是"<<endl;elsecout<<"否"<<endl;cout<<"a19與a21可否相等"<<endl;33if(a19==a21)cout<<"是"<<endl;elsecout<<"否"<<endl;的實(shí)現(xiàn)cout<<"!=的實(shí)現(xiàn)"<<endl;cout<<"a19與a20可否不相等"<<endl;if(a19!=a20)cout<<"是"<<endl;elsecout<<"否"<<endl;cout<<"a19與a21可否不相等"<<endl;if(a19!=a21)cout<<"是"<<endl;elsecout<<"否"<<endl;的實(shí)現(xiàn)cout<<"<的實(shí)現(xiàn)"<<endl;cout<<"a19可否小于a20"<<endl;if(a19<a20)cout<<"是"<<endl;34elsecout<<"否"<<endl;cout<<"a19可否小于a21"<<endl;if(a19<a21)cout<<"是"<<endl;elsecout<<"否"<<endl;的實(shí)現(xiàn)cout<<"<=的實(shí)現(xiàn)"<<endl;cout<<"a19可否小于等于a20"<<endl;if(a19<=a20)cout<<"是"<<endl;elsecout<<"否"<<endl;cout<<"a19可否小于等于a21"<<endl;if(a19<=a21)cout<<"是"<<endl;elsecout<<"否"<<endl;的實(shí)現(xiàn)cout<<">的實(shí)現(xiàn)"<<endl;35cout<<"a19可否大于a20"<<endl;if(a19>a20)cout<<"是"<<endl;elsecout<<"否"<<endl;cout<<"a19可否大于a21"<<endl;if(a19>a21)cout<<"是"<<endl;elsecout<<"否"<<endl;的實(shí)現(xiàn)cout<<">=的實(shí)現(xiàn)"<<endl;cout<<"a19可否大于等于a20"<<endl;if(a19>=a20)cout<<"是"<<endl;elsecout<<"否"<<endl;cout<<"a19可否大于等于a21"<<endl;if(a19>=a21)cout<<"是"<<endl;elsecout<<"否"<<endl;36的實(shí)現(xiàn)cout<<"[]的實(shí)現(xiàn)"<<endl;Stringa22="abcd";cout<<"a22字符串為:"<<a22<<endl;cout<<"a22[2]的字符:"<<a22[2]<<endl;的實(shí)現(xiàn)Stringa23="abcd";charb4[10]="efg";cout<<"Stringappend(constchar*s88)的實(shí)現(xiàn)"<<endl;cout<<"b4字符串"<<endl<<b4<<endl;cout<<"a23字符串及其長度"<<endl;cout<<"字符串為:"<<a23<<endl<<"字符長度為:"<<a23.length()<<endl;a23.append(b4);cout<<"a23.append(b4)字符串及其長度"<<endl;cout<<"字符串為:"<<a23<<endl<<"字符長度為:"<<a23.length()<<endl;37的實(shí)現(xiàn)Stringa24;charb5[10]="efgh";cout<<"Stringassign(constchar*s99)的實(shí)現(xiàn)"<<endl;cout<<"b5字符串"<<endl<<b5<<endl;cout<<"a24字符串及其長度"<<endl;a24.assign(b5);cout<<"字符串為:"<<a24<<endl<<"字符長度為:"<<a24.length()<<endl;的實(shí)現(xiàn)Stringa25="efgh",a26="efgh",a27="efgi",a28="efgg";cout<<"Stringassign(constchar*s99)的實(shí)現(xiàn)"<<endl;cout<<"a25字符串:"<<a25<<endl;cout<<"a26字符串:"<<a26<<endl;cout<<"a27字符串:"<<a27<<endl;cout<<"比較a25與a26的大小"<<endl;cout<<pare(a26)<<endl;cout<<"比較a25與a27的大小"<<endl;cout<<pare(a27)<<endl;cout<<"比較a25與a28的大小"<<endl;cout<<pare(a28)<<endl;38的實(shí)現(xiàn)Stringa29="abcde";charb6[10]="hij";cout<<"String&insert(unsignedintpo,constchar*tt)的實(shí)現(xiàn)"<<endl;cout<<"b6字符串:"<<b6<<endl;cout<<"a29字符串及其長度"<<endl;cout<<"字符串為:"<<a29<<endl<<"字符長度為:"<<a29.length()<<endl;a29.insert(2,b6);cout<<"a29.insert(2,b6)字符串及其長度"<<endl;cout<<"字符串為:"<<a29<<endl<<"字符長度為:"<<a29.length()<<endl;的實(shí)現(xiàn)Stringa30="abcdefg",a31;cout<<"Stringsubstr(unsignedintpos,unsignedintn)const的實(shí)現(xiàn)"<<endl;cout<

溫馨提示

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

評論

0/150

提交評論