軟件類筆試題目參考_第1頁
軟件類筆試題目參考_第2頁
軟件類筆試題目參考_第3頁
軟件類筆試題目參考_第4頁
已閱讀5頁,還剩4頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、軟件類筆試題目參考 軟件類筆試題目參考下面的代碼輸出是什么,為什么? void foo(void) unsigned int a = 6; int b = -20; (a+b6)?puts(6):puts(6就是考察隱式轉(zhuǎn)換int型變量轉(zhuǎn)化成unsigned int,b成了正數(shù)2. b)運行下面的函數(shù)會有什么結果?為什么? void foo(void) char string10,str110; int i; for(i=0;i10;i+) str1i = a; strcpy(string, str1); printf(%s,string); 首先搞清strcpy函數(shù)的實現(xiàn)方法,char *

2、strcpy(char * strdest,const char * strsrc)if (strdest=null)|(strsrc=null) throw invalid argument(s);char * strdestcopy=strdest;while (*strdest+=*strsrc+)!=0); return strdestcopy;由于str1末尾沒有0結束標志,所以strcpy不知道拷貝到何時結束printf函數(shù),對于輸出char* 類型,順序打印字符串中的字符直到遇到空字符()或已打印了由精度指定的字符數(shù)為止下面是微軟的兩道筆試題.3. implement a str

3、ing class in c+ with basic functionality like comparison, concatenation, input and output. please also provide some test cases and using scenarios (sample code of using this class).please do not use mfc, stl and other libraries in your implementation.我的實現(xiàn)方案如下,這道題真地對c+的主要特性都進行了較好地考察.string.h:#ifndef

4、string_h#define string_h#include using namespace std;class string public: string(); string(int n,char c); string(const char* source); string(const string& s); /string& operator=(char* s); string& operator=(const string& s); string(); char& operator(int i)return ai; const char& operator(int i) const

5、return ai;/對常量的索引. string& operator+=(const string& s); int length(); friend istream& operator(istream& is, string& s);/搞清為什么將設置為友元函數(shù)的原因. /friend bool operator (const string& left, const string& right);/下面三個運算符都沒必要設成友元函數(shù),這里是為了簡單. friend bool operator= (const string& left, const string& right); frien

6、d bool operator!= (const string& left, const string& right); private: char* a; int size;#endifstring.cpp:#include string.h#include #include string:string() a = new char1; a0 = 0; size = 0;string:string(int n,char c)a = new charn + 1;memset(a,c,n);an = 0;size = n;string:string(const char* source)if(s

7、ource = null) a = new char1; a0 = 0; size = 0;else size = strlen(source); a = new charsize + 1; strcpy(a,source);string:string(const string& s)size = strlen(s.a);/可以訪問私有變量.a = new charsize + 1;/if(a = null)strcpy(a,s.a);string& string:operator=(const string& s)if(this = &s) return *this;else delete

8、a; size = strlen(s.a); a = new charsize + 1; strcpy(a,s.a); return *this;string:string()delete a;/ string& string:operator+=(const string& s) int j = strlen(a); int size = j + strlen(s.a); char* tmp = new charsize+1; strcpy(tmp,a); strcpy(tmp+j,s.a);delete a;a = tmp;return *this;int string:length()r

9、eturn strlen(a);main.cpp:#include #include string.husing namespace std;bool operator=(const string& left, const string& right)int a = strcmp(left.a,right.a); if(a = 0) return true;else return false;bool operator!=(const string& left, const string& right)return !(left = right);ostream& operator(ostre

10、am& os,string& s)int length = s.length();for(int i = 0;i length;i+) /os s.ai;這么不行,私有變量. os si;return os;string operator+(const string& a,const string& b)string temp;temp = a;temp += b;return temp;bool operator(const string& left,const string& right)int j = 0;while(leftj != 0) & (rightj != 0) if(left

11、j (const string& left, const string& right) int a = strcmp(left.a,right.a); if(a 0) return true;else return false;istream& operator(istream& is, string& s)delete s.a;s.a = new char20;int m = 20; char c;int i = 0;while (is.get(c) & isspace(c); if (is) do s.ai = c; i+; /*if(i = 20) cout input too much characters! f;/需要輸入.string g;g = a + b;/abcdwwwif(a b) cout a b endl;else cout = b endl;if(e = a) cout e = a endl;else cout e != a endl;b += a;cout a endl;cout b endl; cout c endl;cout d endl;cout e endl;cout f endl;cout g endl;cout g0 endl;return 0;4. implement a single-direction linked

溫馨提示

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

評論

0/150

提交評論