微软研究院笔试题目
发布时间: 2010-01-12 15:36 阅读: 1557 次 推荐: 0
[收藏]
1、
#include
class CBuffer
{
char * m_pBuffer;
int m_size;
publc:
CBuffer()
{
m_pBuffer=NULL;
}
~CBuffer()
{
Free();
}
void Allocte(int size)
{
m_size=size;
m_pBuffer= new char[size];
}
private:
void Free()
{
if(m_pBuffer!=NULL)
{
delete m_pBuffer;
m_pBuffer=NULL;
}
}
public:
void SaveString(const char* pText) const
{
strcpy(m_pBuffer, pText);
char* GetBuffer() const
{
return m_pBuffer;
}
};
void main (int argc, char* argv[])
{
cBuffer buffer1;
buffer1.SaveString(“Microsoft”);
printf(buffer1.GetBuffer());
}
}
找出Allocate, SaveString, main的错误。
2、打印“Welcome MSR Asia”
#include
char * GetName (void)
{
//To return “MSR Asia” String
char name[]=“MSR Asia”;
return name;
}
void main(int argc, char* argv[])
{
char name[32];
//Fill in zeros into name
for(int i=0;iFuncA();
pa->FuncB();
pa2->FuncA();
pa2->FuncB();
delete pa2;
}
What is the output of the above program?
3、
#include
int FindSubString(char* pch)
{
int count=0;
char* p1=pch;
while(*p1!=‘’)
{
if(*p1==p1[1]-1)
{
p1++;
count++;
}
else
{
break;
}
}
int count2=count;
while(*p1!=‘’)
{
if(*p1!==p1[1]+1)
{
p1++;
count2--;
}
else
{
break;
}
if(count2==0)
return count;
return 0;
}
void ModifyString(char* pText)
{
char* p1=pText;
char* p2=p1;
while(*p1!=‘’)
{
int count=FindSubString(p1);
if(count>0)
{
*p2++=*p1;
sprintf(p2, “%I”, count);
while(*p2!= ‘’)
{
p2++;
}
p1+=count+count+1;
}
else
{
*p2++=*p1++;
}
}
}
void main(void)
{
char text[32]=“XYBCDCBABABA”;
ModifyString(text);
printf(text);
}
In the main() function, afterModifyString(text) is called, what’s the value of ‘text’?