- 相关推荐
51.com笔试题
大题: 1. 反转链表 #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. 一个已知递推式的递归程序 3. 数据库查询的问题 主观题:1. socket网络编程,写一个Helloworld程序,包括client和server两部分Berkeley Socket API不记得,而且平时很少做网络编程,所以没法写,直接画了个图,说明用到哪几个函数出这种题很没水平,谁去死记那些API啊,而且这个题叙述都有个地方错了,真是不知道51.com怎么招这种人来出题目考我们,巨faint! 2. 简要介绍leader/follower模式Design Pattern模式里好像没这个模式吧!不过提示说和多进程/多线程类似,那我就发挥了,说的和C/S模型下的多线程类似 3. 最后一题考C++的继承和多态的主要是涉及到基类中protected数据成员和派生类中protected数据成员的重名问题:#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;}进一步探讨:关于这种情况下:到底对象怎样布局呢??测试程序如下:#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;}很显然的看到,派生类中的重名成员只不过隐藏(hide)了基类的同名成员,默认情况下是访问派生类中的成员,要访问基类中同名成员必须加上类域符既然是隐藏,那么在基类子对象中仍然是存在的!要记住,无论怎样继承,C++都需要保证基类子对象的完整性!这和成员函数同名一样,只不过成员函数同名时要分清hide和override!
【51.com笔试题】相关文章:
迅雷2011.10.21笔试题08-10
中兴2015笔试题08-02
海尔04年笔试题及答案07-31
交通银行2014笔试题题目分享08-10
阿里巴巴非技术类笔经及试题08-13
攀枝花移动笔试题,笔经分享08-10
柜员合同工招聘笔试题型,笔经分享08-10
交通银行内蒙古分行2012笔试题,给2013的还只们08-09
腾讯笔试题 试题分享08-09