軟通動力筆試(帶參考答案)_第1頁
軟通動力筆試(帶參考答案)_第2頁
軟通動力筆試(帶參考答案)_第3頁
軟通動力筆試(帶參考答案)_第4頁
全文預覽已結束

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

精選文庫答案僅供參考1、 改錯題1. 找出以下兩處邏輯錯誤(非編程規(guī)范)并改正 char* getErrorString(int errcode)char errorString = not exist; char errorString2 = not available;switch(errcode) case 1: return errorString; case 2: return errorString2; default: return NULL;void printErrorString(int errcode)char *errorString = getErrorString(errcode);printf(errcode:%d, errorString:%sn, errcode, errorString); case1和case2返回了兩個局部變量指針,而局部變量在函數結束后將自動釋放。改正:將字符數組改為指針 char *errorString= not exist; char *errorString2 = not available;2. 以下是輸出“welcome home”的程序,找出邏輯錯誤(非編程規(guī)范)并改正 const int MAX_STR_SIZE = 12; int main(int argc, char *argv) char strMAX_STR_SIZE; strcpy(str,welcome home); printf(%s, str);return 0; “welcome home”字符串應該是13個字節(jié),而str字符數組只能存儲12個字符 改正: const int MAX_STR_SIZE = 13;2、 程序填空題1. 寫出String類的構造函數,析構函數和賦值函數 class Stringpublic:String(const char *str = NULL);String(const String &other);String();String& operator =(const String &other);private:char *m_data;String:String()(1)delete m_data;String:String(const char *str)if( (2)str=NULL ) m_data = (3)new char;*m_data = 0;else int length = (4)strlen(str);m_data = new charlength+1;strcpy(m_data, str);String& String:operator =(const String &other)if( (5) this = other) return (6)*this;(7) delete m_data;int length = strlen( (8)other );m_data = new charlength+1;(9)strcpy(m_data,other.m_data)return (10)*this;2. 一個計算到指定年份有多少個“黑色星期五”(當月的13號并且是星期五)的程序,具體忘了。3、 編程題1. 實現以下函數,把給定string中的和替換成(和)std:string replace(std:string &str) for(int i = 0; i 0) acount+=num%B; /保存余數 num=num/B; for(int i = count - 1; i =0; i-

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論