云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 《C%2B%2B数组与指针习题》

《C%2B%2B数组与指针习题》

  • 62 次阅读
  • 3 次下载
  • 2025/6/7 16:56:26

数组与指针习题 13

mystring ms1(sp1),ms2(sp2),ms3(sp3),ms4(ms3),ms5=ms3,ms6; ms1.show(); ms2.show(); ms3.show(); ms4.show(); ms5.show(); ms6.show(); ms4=ms1+ms3; ms4.show(); ms1+=ms2; ms1.show();

if(ms1

else {ms1.show();cout<<\应排在\之后\ ms6=ms1;

if(ms1==ms6) cout<<\串ms1与串ms6相同\}

5.12 将习题5.8中的字符串处理函数移植到mystring类中,其中strcat已重载为+运算符, 请将其它4个转为成员函数。对比成员函数与独立函数构造上有何不同? #include

char* strcat(char* s,const char* ct){ while(*s) s++;//*S作为条件,等效*S!=0 while(*s++=*ct++); return s; }

int strlen(const char* s){ int i=0;

while(*s++) i++; return i; }

char* reverse (char* s){

char temp,* temp1=s,* temp2=s; while(*temp2) temp2++; temp2--;//指针移回串尾 while(temp2-temp1>0){

//注意此处,从串两头的指针同时向中间移动,重合或交错时停止 temp=*temp1; *temp1=*temp2; *temp2=temp; temp1++; temp2--;

数组与指针习题 14

}

return s; }

char* strchr( const char*cs,char c){ while(*cs!=c&&*cs) cs++;

if(*cs==0) cs=NULL; //未找到返回NALL return (char*)cs; }

char *strstr (const char *cs1,const char *cs2){ char *temp;

char *temp1=(char*)cs2;

while(*cs1){//只要主串还有字符未查,则继续 while(*cs1!=*cs2&&*cs1) cs1++;//找到主串含有子串的第一个字符,或主串查完停止

temp=(char*)cs1; temp1=(char*)cs2;

if(*cs1){//核对子串其他字符

while(*cs1++==*temp1++||*temp1);

if(*temp1==0) return temp;//找到子串返回 } }

return NULL; //未找到返回NAL }

void main(){

char a[40]=\李明\

char b[20]=\是东南大学学生\

char c[40]=\ char *cp;

cout<

cout<<\字符串连接后:\ cout<

cout<<\字符串长度为:\ cout<

if(cp==NULL) cout<<\未找到\

else cout<

if(cp==NULL) cout<<\未找到\ else cout<

if(cp!=NULL) cout<

数组与指针习题 15

}

else cout<<\未找到\cp=strstr(a,\西北\

if(cp==NULL) cout<<\未找到\else cout<

搜索更多关于: 《C%2B%2B数组与指针习题》 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

数组与指针习题 13 mystring ms1(sp1),ms2(sp2),ms3(sp3),ms4(ms3),ms5=ms3,ms6; ms1.show(); ms2.show(); ms3.show(); ms4.show(); ms5.show(); ms6.show(); ms4=ms1+ms3; ms4.show(); ms1+=ms2; ms1.show(); if(ms1

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com