freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

c++第五章習(xí)題解答-預(yù)覽頁(yè)

 

【正文】 s指針。因?yàn)閍是指針常量。實(shí)參為數(shù)組時(shí),只能用指針而不能用引用,因?yàn)閿?shù)組的引用不存在。 設(shè)有語(yǔ)句char *ps=”It’s a book.”。后一條語(yǔ)句要求把字符串賦給不可寫的字符串空間是錯(cuò)的。int main(){ int a[10][11]={0,1},i,j。j=i+1。i++){ for(j=1。 coutendl。include iostreaminclude iomanipusing namespace std。int main(){ int middle[6*3], result[6*4]。 inverse(matrix1,middle,3,6)。 output(result,6,4)。ia。 return。i++){ for (j=0。kb。ia。 cout39。 } 編寫函數(shù)int atoi(char s[ ]),將字符串s轉(zhuǎn)化為整型數(shù)返回。includeiostreamusing namespace std。amp。amp。||s[i]39。39。039。//串非法時(shí),輸出提示,返回0 while(s[i]=39。s[i]=39。 } return f*temp。\n39。double *dp。 *ip=ival。ip=amp。 *dp=*ip。ival=ip。但語(yǔ)法對(duì)。ival。 對(duì),地址賦給指針型。 錯(cuò),賦值類型錯(cuò),整型不能賦給指針型。解:注意:字符指針輸出是字符串,必須強(qiáng)制轉(zhuǎn)換為無(wú)類型指針includeiostreamusing namespace std。A39。dval。\t39。sizeof(*ip)endl。*dp39。\t39。sizeof(*cp)endl。*cp39。\t39。sizeof(ip)endl。dp39。\t39。sizeof(cp)endl。 分別編寫下列字符串處理函數(shù) (1)char *strcat1(char *s,const char *ct)。求字符串長(zhǎng)度的函數(shù),返回串長(zhǎng)(不包括串結(jié)束符)。查找字符c在串cs中第一次出現(xiàn)的位置,返回指向該字符的指針,若沒(méi)有出現(xiàn)則返回NULL。反置字符串函數(shù),從串兩頭的指針同時(shí)向中間移動(dòng),重合或交錯(cuò)時(shí)停止。在使用++運(yùn)算符時(shí)一定要單用,如本例中:while(*temp==*temp1amp。}。*temp1)。char* strcat1(char* s,const char* ct){ char* st=s。}int strlen1(const char* s){ int i=0。 while(*temp2) temp2++。 *temp2=temp。}char* strchr( const char*cs,char c){ while(*cs!=camp。 //未找到返回NALL return (char*)cs。*cs1) cs1++。amp。 if(*temp1==0) return (char*)cs1。 char b[20]=是東南大學(xué)學(xué)生。 coutbendl。 //打印字符數(shù)組a cout字符串長(zhǎng)度為:strlen1(a)endl。)。A39。 coutreverse(c)endl。 cp=strstr(a, 大學(xué)生)。} 使用遞歸和非遞歸的兩種方法編寫函數(shù)char *itoa (int n,char *string)。難度大,可用圖解法:每次調(diào)用除以10,以去除最后一位,以n=3657為例。//字符,ASCII碼 return string。 }if(n/10)string=itoal(n/10,string)。}注意:因?yàn)橹羔槻粩嗪笠?,最后指向串結(jié)束符,所以設(shè)計(jì)一個(gè)驅(qū)動(dòng)函數(shù)itoa0()以保證返回指向串起始位置的指針。 temp2。 temp1++。 if(n0){ *temp++=39。 }while(n=n/10)。39。//個(gè)位放到后面 return string。 } if(n/10) string=itoa1(n/10,string)。 return string。 char st[20]。 cout輸出數(shù)字串:itoa0(num,st)endl。 //分 int tm_hour。 //年,實(shí)際放的是與1970年的差,如1990年為20 int tm_wday。函數(shù) time_t time(time_t *tp)是提取當(dāng)前時(shí)間,time_t即長(zhǎng)整型,代表從1970年1月1日00:00:00開(kāi)始計(jì)算的秒數(shù)(格林尼治時(shí)間),放在首地址為tp的單元內(nèi)。 long allsecond。 timedata=localtime(amp。 } void gettime(){ allsecond=time(NULL)。 couttmpendl。 cout需要知道現(xiàn)在的日期和時(shí)間嗎?(Y或N)endl。|| ch==39。} 完善自定義字符串類mystring,函數(shù)包括:構(gòu)造函數(shù)、拷貝構(gòu)造函數(shù)、析構(gòu)函數(shù),并重載運(yùn)算符[ ],=(分別用mystring和C字符串拷貝),+(strcat),+=,==(strcmp)。對(duì)比成員函數(shù)與獨(dú)立函數(shù)構(gòu)造上有何不同?解:這四個(gè)函數(shù)因mystring內(nèi)部有串長(zhǎng),又要求下標(biāo)索引,再加上str字符數(shù)組可直接使用,構(gòu)造大不相同。 //存放字符串的數(shù)組容器 int maxsize。 str[0]=39。 maxsize=n。\039。 str[last] =39。 ms){ last=1。 }while(last)。 } int strlen(){return last。 int strstr (mystring str1)。 } mystring amp。 operator=(char * ms)。 operator+=(mystring amp。 bool operator==(mystring amp。 char temp。 i++。i!=last。 while(str[i]!=39。str[i]!=39。\039。//字符串結(jié)束符不比較 if(k==) return i。 //未找到返回1}mystring amp。 str[last]=[last]。 mystring::operator=(char* ms){ //這里返回值為引用,不調(diào)用拷貝構(gòu)造函數(shù) last=1。\039。 str[last] =39。 ms){//注意+和+=的不同 mystring temp(*this)。 i++。 maxsize1)。//拷貝的臨時(shí)變量生命期在調(diào)用它的表達(dá)式中}mystring amp。//串的結(jié)尾是結(jié)束符,連接時(shí)要覆蓋掉 do{ last++。amp。 //截尾處理時(shí),必須加串結(jié)束符 return *this。 i++。amp。amp。 ms){ int i=0,k。 }while(k==0amp。 else return true。//ms1,ms2,ms3是用構(gòu)造函數(shù)生成 mystring ms4(ms3),ms5=ms3,ms6。 ()。 ()。//+=返回引用,不用拷貝構(gòu)造函數(shù) ()。cout之前endl。cout之后endl。 i=0。//讀出 coutendl。\039。 coutms1串長(zhǎng):()endl。 ms2=ing。 return 0。 s=amp。sksi[2]=0x6e69。}仿照上述程序,編寫一個(gè)輸出字符串為“puter!”的程序。}。 sksi[0] = 0x6f63。 sksi[4] = 0x0021。}
點(diǎn)擊復(fù)制文檔內(nèi)容
試題試卷相關(guān)推薦
文庫(kù)吧 www.dybbs8.com
備案圖鄂ICP備17016276號(hào)-1