- 相關(guān)推薦
51.com筆試題
大題: 1. 反轉(zhuǎn)鏈表 #include using namespace std; struct LNode { char data; LNode * next; }; LNode * initList() { LNode *head=new LNode; LNode *curPtr, *newPtr; curPtr=head; int i=0; char ch=A; while(i++<10)< pre=""> { newPtr=new LNode; newPtr->data=ch++; curPtr->next=newPtr; curPtr=newPtr; } newPtr->next=NULL; return head;} void print(LNode *head){ LNode *ptr=head->next; while(ptr != NULL) { cout data << " "; ptr=ptr->next; } cout << endl;} void reverse(LNode *head){ assert(head != NULL && head->next != NULL); LNode *ptr=head->next->next; head->next->next=NULL; while(ptr != NULL) { LNode *tmp=ptr->next; ptr->next=head->next; head->next=ptr; ptr=tmp; }} int main(){ LNode *head=initList(); print(head); cout << "After reverse: " << endl; reverse(head); print(head); system("PAUSE"); return 0;}2. 一個(gè)已知遞推式的遞歸程序 3. 數(shù)據(jù)庫(kù)查詢的問(wèn)題 主觀題:1. socket網(wǎng)絡(luò)編程,寫一個(gè)Helloworld程序,包括client和server兩部分Berkeley Socket API不記得,而且平時(shí)很少做網(wǎng)絡(luò)編程,所以沒法寫,直接畫了個(gè)圖,說(shuō)明用到哪幾個(gè)函數(shù)出這種題很沒水平,誰(shuí)去死記那些API啊,而且這個(gè)題敘述都有個(gè)地方錯(cuò)了,真是不知道51.com怎么招這種人來(lái)出題目考我們,巨faint! 2. 簡(jiǎn)要介紹leader/follower模式Design Pattern模式里好像沒這個(gè)模式吧!不過(guò)提示說(shuō)和多進(jìn)程/多線程類似,那我就發(fā)揮了,說(shuō)的和C/S模型下的多線程類似 3. 最后一題考C++的繼承和多態(tài)的主要是涉及到基類中protected數(shù)據(jù)成員和派生類中protected數(shù)據(jù)成員的重名問(wèn)題:#includeusing namespace std; class Base{protected: int int_i; double dbl_x; public: Base() { int_i=1; dbl_x=1.5; } virtual void foo(int i) { cout << "Base::i=" << i << endl; } virtual void foo(double x) { cout << "Base::x=" << x << endl; } virtual void foo() { cout << "Base::int_i=" << int_i << endl; cout << "Base::dbl_x=" << dbl_x << endl; }}; class Derived : public Base{protected: int int_i; public: Derived() { int_i=2; dbl_x=2.5; } virtual void foo(int i) { cout << "Derived::i=" << i << endl; } virtual void foo() { cout << "Derived::int_i=" << int_i << endl; cout << "Derived::dbl_x=" << dbl_x << endl; }}; class Derived2: public Derived{protected: double dbl_x; public: Derived2() { int_i=3; dbl_x=3.5; } virtual void foo(double x) { cout << "Derived2::x=" << x << endl; } virtual void foo() { cout << "Derived2::int_i=" << int_i << endl; cout << "Deroved2::dbl_x=" << dbl_x << endl; }}; int main(){ Derived2 d2; Derived d; Base b, *p; p=&d2; p->foo(7); p->foo(7.5); p->foo(); p=&d; p->foo(6); p->foo(6.5); p->foo(); p=&b; p->foo(5); p->foo(5.5); p->foo(); system("PAUSE"); return 0;}進(jìn)一步探討:關(guān)于這種情況下:到底對(duì)象怎樣布局呢??測(cè)試程序如下:#includeusing namespace std; class Base{protected: int int_i; double dbl_x; public: Base() { int_i=1; dbl_x=1.5; } virtual void print() { cout << "Base::int_i=" << int_i << endl; cout << "Base::dbl_x=" << dbl_x << endl; }}; class Derived : public Base{protected: int int_i; public: Derived() { int_i=2; dbl_x=2.5; } virtual void print() { cout << "Base::int_i=" << Base::int_i << endl; cout << "Derived::int_i=" << int_i << endl; cout << "Base::dbl_x=" << Base::dbl_x << endl; cout << "Derived::dbl_x=" << dbl_x << endl; }}; class Derived2: public Derived{protected: double dbl_x; public: Derived2() { int_i=3; dbl_x=3.5; } virtual void print() { cout << "Base::int_i=" << Base::int_i << endl; cout << "Derived::int_i=" << Derived::int_i << endl; cout << "Derived2::int_i=" << int_i << endl; cout << "Base::dbl_x=" << Base::dbl_x << endl; cout << "Derived::dbl_x=" << Derived::dbl_x << endl; cout << "Derived2::dbl_x=" << dbl_x << endl; }}; int main(){ Derived2 d2; Derived d; Base b, *p; p=&d2; p->print(); p=&d; p->print(); p=&b; p->print(); system("PAUSE"); return 0;}很顯然的看到,派生類中的重名成員只不過(guò)隱藏(hide)了基類的同名成員,默認(rèn)情況下是訪問(wèn)派生類中的成員,要訪問(wèn)基類中同名成員必須加上類域符既然是隱藏,那么在基類子對(duì)象中仍然是存在的!要記住,無(wú)論怎樣繼承,C++都需要保證基類子對(duì)象的完整性!這和成員函數(shù)同名一樣,只不過(guò)成員函數(shù)同名時(shí)要分清hide和override!
【51.com筆試題】相關(guān)文章:
中國(guó)銀行筆試題回顧,新鮮筆經(jīng)!11-21
迅雷JAVA廣州站二筆筆試題目分享11-21
大唐移動(dòng)測(cè)試工程師筆經(jīng),筆試題目分享11-21
網(wǎng)易筆經(jīng)11-11
奧美筆經(jīng)02-23
騰訊筆試題 試題分享02-24
北京埃森折筆試回來(lái),不是筆經(jīng)的筆經(jīng)11-21
采購(gòu)人員筆試題,試題分享02-25
殼牌Shell筆經(jīng)02-23