Work 版 (精华区)

发信人: fondseedhl (fondseedhl), 信区: Work
标  题: 微软笔试题(一)
发信站: BBS 哈工大紫丁香站 (Fri Oct 14 17:06:45 2005)

微软研究院笔试题目
1.#include <stdio.h>

#include <String.h>

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 <stdio.h>

#include <string.h>

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;i<=32;i++)

              {

                       name[1]='\0';

              }

              //copy “Welcome” to name

              name=“Welcome”;

              //Append a blank char

              name[8]=”;

              //Append string to name

              strcat(name,GetName());

              //print out

              printf(name);

}

找出程序中的错误。

3.#include <stdio.h>

class A

{

public:

              void FuncA()

              {

                       printf(“FuncA called\n”);

              }

              virtual void FuncB()

              {

                       printf(“FuncB called\n”);

              }

};

class B: public A

{

public:

              void FuncA()

              {

                       A::FuncA();

                       printf(“FuncAB called\n”);

              }

              virtual void FuncB()

              {

                       printf(“FuncBB called\n”);

              }

};

void main(void)

{

              B b;

              A *pa;

              pa=&b;

              A *pa2=new A;

              b.FuncA();

              b.FuncB();

              pa->FuncA();

              pa->FuncB();

              pa2->FuncA();

              pa2->FuncB();

              delete pa2;

}

What is the output of the above program?

4.#include <stdio.h>

#include <string.h>

int FindSubString(char* pch)

{

             int count=0;

             char* p1=pch;

             while(*p1!=‘\0’)

             {

                      if(*p1==p1[1]-1)

                      {

                               p1++;

                               count++;

                      }

                      else

                      {

                               break;

                      }

             }

             int count2=count;

             while(*p1!=‘\0’)

             {

                      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!=‘\0’)

             {

                      int count=FindSubString(p1);

                      if(count>0)

                      {

                               *p2++=*p1;

                               sprintf(p2, “%I”, count);

                               while(*p2!= ‘\0’)

                               {

                                         p2++;

                               }

                               p1+=count+count+1;

                      }

                      else

                      {

                      *p2++=*p1++;

                      }

             }

}

void main(void)

{

             char text[32]=“XYBCDCBABABA”;

             ModifyString(text);

             printf(text);

}

In the main() function, after ModifyString(text) is called, what’s the value 
of ‘text’?
--

※ 来源:·哈工大紫丁香 http://bbs.hit.edu.cn·[FROM: 202.118.239.19]
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:208.380毫秒