欧美在线观看www-欧美在线观看高清一二三区-欧美在线观看网站-欧美在线观看网址-国产高清在线精品免费-国产高清在线精品一区二区

當(dāng)前位置:高考升學(xué)網(wǎng) > 招聘筆試題 > 正文

創(chuàng)維集團(tuán)2019筆試題和面試題答案(三)

更新:2023-09-20 05:09:42 高考升學(xué)網(wǎng)

五、編寫strcpy函數(shù)(10分)

  已知strcpy函數(shù)的原型是

  char strcpy(char strdest, const char strsrc);

  其中strdest是目的字符串,strsrc是源字符串。

  (1)不調(diào)用c++/c的字符串庫(kù)函數(shù),請(qǐng)編寫函數(shù) strcpy

  char strcpy(char strdest, const char strsrc);

  {

  assert((strdest!=null) & (strsrc !=null)); // 2分

  char address = strdest; // 2分

  while( (strdest++ = strsrc++) != ‘\0’ ) // 2分

  null ;

  return address ; // 2分

  }

  (2)strcpy能把strsrc的內(nèi)容復(fù)制到strdest,為什么還要char 類型的返回值?

  答:為了實(shí)現(xiàn)鏈?zhǔn)奖磉_(dá)式。 // 2分

  例如 int length = strlen( strcpy( strdest, “hello world”) );

六、編寫類string的構(gòu)造函數(shù)、析構(gòu)函數(shù)和賦值函數(shù)(25分)

  已知類string的原型為:

  class string

  {

  public:

  string(const char str = null); // 普通構(gòu)造函數(shù)

  string(const string other); // 拷貝構(gòu)造函數(shù)

  ~ string(void); // 析構(gòu)函數(shù)

  string operate =(const string &other); // 賦值函數(shù)

  private:

  char m_data; // 用于保存字符串

  };

  請(qǐng)編寫string的上述4個(gè)函數(shù)。

  標(biāo)準(zhǔn)答案:

  // string的析構(gòu)函數(shù)

  string::~string(void) // 3分

  {

  delete [] m_data;

  // 由于m_data是內(nèi)部數(shù)據(jù)類型,也可以寫成 delete m_data;

  }

  // string的普通構(gòu)造函數(shù)

  string::string(const char str) // 6分

  {

  if(strnull)

  {

  m_data = new char; // 若能加 null 判斷則更好

  m_data = ‘\0’;

  }

  else

  {

  int length = strlen(str);

  m_data = new char[length+1]; // 若能加 null 判斷則更好

  strcpy(m_data, str);

  }

  }

  // 拷貝構(gòu)造函數(shù)

  string::string(const string other) // 3分

  {

  int length = strlen(other.m_data);

  m_data = new char[length+1]; // 若能加 null 判斷則更好

  strcpy(m_data, other.m_data);

  }

  // 賦值函數(shù)

  string string:perate =(const string other) // 13分

  {

  // (1) 檢查自賦值 // 4分

  if(this other)

  return this;

  // (2) 釋放原有的內(nèi)存資源 // 3分

  delete [] m_data;

  // (3)分配新的內(nèi)存資源,并復(fù)制內(nèi)容 // 3分

  int length = strlen(other.m_data);

  m_data = new char[length+1]; // 若能加 null 判斷則更好

  strcpy(m_data, other.m_data);

  // (4)返回本對(duì)象的引用 // 3分

  return this;

  }

相關(guān)文章

最新圖文

2020年河北新聞網(wǎng)兩學(xué)一做

時(shí)間:2023-09-18 07:0:24

2020年河北新聞網(wǎng)兩學(xué)一做

時(shí)間:2023-09-15 11:0:59

兩學(xué)一做學(xué)習(xí)教育知

時(shí)間:2023-09-21 06:0:30
主站蜘蛛池模板: 亚洲一区二区在线免费观看 | 久久精品久久久 | 2019天堂网 | 一区二区三区欧美视频 | 在线观看一区二区三区四区 | 国产极品麻豆91在线 | 久热re国产手机在线观看 | 手机看片在线精品观看 | 欧美一区亚洲二区 | 日韩精品在线观看视频 | 国产午夜精品久久久久小说 | 亚洲欧洲精品成人久久曰影片 | 日本精品视频 | 天天射美女 | 91精品成人免费国产 | 日本不再卡v片 | 四虎aⅴ| 免费三片在线观看网站 | 欧美成人免费高清二区三区 | 一区二区三区四区欧美 | 老子影院午夜伦手机不四虎 | 日本久久综合 | 欧美高清hd视频免费播放 | 日本精品久久久久中文字幕2 | 九九视频在线看精品 | 欧洲三级在线观看 | 9久热久爱免费精品视频在线观看 | 亚洲精品视频免费 | 四虎在线免费观看视频 | 黄色欧美视频在线观看 | 春日迟迟再出发最新一期在线观看 | 久久香蕉国产精品一区二区三 | 九色国产在视频线精品视频 | 成人av在线播放 | 青青青国产依人在在线观看高 | 97国产在线播放 | 999re6热在线精品视频思思 | 大学生久久香蕉国产线观看 | 欧美日韩视频在线一区二区 | 久久精品国产久精国产 | 国产四虎免费精品视频 |