下载此文档

C语言笔试面试题整理知识.docx


文档分类:IT计算机 | 页数:约19页 举报非法文档有奖
1/19
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/19 下载此文档
文档列表 文档介绍
现在的公司招聘,,又不好好准备一
番,,
,我就略去那
ar*strDestCopy=strDest;
while((*strDest++=*strSrc++)!='\0');
returnstrDestCopy;
}
str1末尾没有'\0’结束标志,所以strcpy不知道拷贝到何时结束.
printf函数,对于输出char*类型,顺序打印字符串中的字符直到遇到空字符(,\0,)
或已打印了由精度指定的字符数为止.
下面是微软的两道笔试题
ImplementastringclassinC++withbasicfunctionalitylikecomparison,concatenation,
alsoprovidesometestcasesandusingscenarios(samplecodeofusingthisclass).
PleasedonotuseMFC,STLandotherlibrariesinyourimplementation.
我的实现方案如下,这道题真地对c++的主要特性都进行了较好地考察.
:
#ifndefSTRING_H
#defineSTRING_H
#include<iostream>
usingnamespacestd;
classString{
public:
String();
String(intn,charc);
String(constchar*source);
String(constString&s);
//String&operator=(char*s);
String&operator=(constString&s);
~String();
char&operator[](inti){returna[i];}
constchar&operator[](inti)const{returna[i];}//对常量的索引.
String&operator+=(constString&s);
intlength();
friendistream&operator>>(istream&is,String&s);//搞清为什么将>>设置为友元
函数的原因.
//friendbooloperator<(constString&left,constString&right);
friendbooloperator>(constString&left,constString&right);//下面三个运算
符都没必要设成友元函数,这里是为了简单.
friendbooloperator==(constString&left,constString&right);
friendbooloperator!=(constString&left,constString&right);private:
char*a;intsize;
};
#endif
:
#include""
#include<cstring>
#include<cstdlib>
String::String(){
a=newchar[1];
a[0]='\0';
size=0;
}
String::String(intn,charc){a=newchar[n+1];memset(a,c,n);
a[n]='\0';size=n;
}
String::String(constchar*source){if(source==NULL){a=newchar[1];
a[0]='\0';
size=0;
}else
{size=strlen(source);
a=newchar[size+1];strcpy(a,source);
}
}
String::String(constString&s){size=strlen();//可以访问私有变量a=newchar[size+1];
//if(a==NULL)
strcpy(a,);
}
String&String::operator=(constString&s){if(this==&s)return*this;
else
{
delete[]a;
size=strlen();
a=newchar[size+1];
strcpy(a,);return*thi

C语言笔试面试题整理知识 来自淘豆网m.daumloan.com转载请标明出处.

非法内容举报中心
文档信息
  • 页数19
  • 收藏数0 收藏
  • 顶次数0
  • 上传人cjl201801
  • 文件大小43 KB
  • 时间2022-01-18