軟通動力筆試(帶參考答案)_第1頁
軟通動力筆試(帶參考答案)_第2頁
軟通動力筆試(帶參考答案)_第3頁
軟通動力筆試(帶參考答案)_第4頁
軟通動力筆試(帶參考答案)_第5頁
已閱讀5頁,還剩2頁未讀 繼續免費閱讀

下載本文檔

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

文檔簡介

1、精品答案僅供參考一、 改錯題1. 找出以下兩處邏輯錯誤(非編程規范)并改正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 = ge

2、tErrorString(errcode);printf("errcode:%d, errorString:%sn", errcode, errorString);case1 和 case2 返回了兩個局部變量指針,而局部變量在函數結束后將自動釋放。改正:將字符數組改為指針char *errorString= "not exist"char *errorString2 = "not available"2. 以下是輸出“welcome home ”的程序,找出邏輯錯誤(非編程規范)并改正const int MAX_STR_SIZE =

3、 12;int main(int argc, char *argv)char strMAX_STR_SIZE;strcpy(str,"welcome home");printf("%s", str);return 0;“ welcome home ”字符串應該是 13 個字節,而str 字符數組只能存儲12 個字符改正: const int MAX_STR_SIZE = 13;2、 程序填空題1. 寫出 String 類的構造函數,析構函數和賦值函數class Stringpublic :String( const char *str = NULL);S

4、tring( 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 char length+1;strcpy(m_

5、data, str);if( (5) this = other) return (6)*this;(7) delete m_data;int length = strlen( (8)other );m_data = new char length+1;(9)strcpy(m_data,other.m_data)return (10)*this;2. 一個計算到指定年份有多少個“黑色星期五”(當月的13號并且是星期五)的程序,具體忘了。3、 編程題1 . 實現以下函數,把給定string 中的和 替換成(和) std:string replace(std:string &str)for(

6、int i = 0; i < str.size();i+)if(stri='')stri='('if(stri='')stri=')'return str;2 .實現函數,使數字num按B進制輸出int main(int argc, char *argv)long num = 134;int B = 8;func(num, B);return 0;例如 134按 2進制輸出10000110 ,按 8進制輸出206,按十六進制輸出86void func(long num,int B)int a100 =0;int count=0;while(num>0)acount+=num%B; / 保存余數 num=num/B;for(int i = count - 1; i >=0; i-) / 逆序輸出if(ai>=10)/ 十六進制要

溫馨提示

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

評論

0/150

提交評論