康佳软件方向笔考试题2012年9月19号郑大
报的是c++方向的,试卷是100分制,题型有选择题、填空题、简答题、改错题、找错题、编程题。60分的c方面的题,40分的c++或者java方面的题。
考的都很基础,没有什么太难的算法方面的,都是些语法基础,指针数组什么的都是些老生常谈的问题。有一个网络协议方面的填空题,一个操作系统方面的简答题
按回想的顺序总结一下想起那个算哪个:
1、定义一个宏交换一个unsigned short型数据的高8位和低8位
当时就是没想起来应该用移位了
代码:#define exchangebit(i) ((i) = ((i)<<(8))|((i)>>(8)));
2、互联网使用的协议是:TCP/IP协议。
ping(Packet Internet Groper)程序使用的协议是:ICMP(Internet Control Messages Protocol)
即因特网信报控制协议。
应用层所包含的协议有:
DHCP · DNS · FTP · Gopher · HTTP ·
IMAP4 · IRC · NNTP · XMPP · POP3 ·
SIP · SMTP · SNMP · SSH · TELNET ·
RPC · RTCP · RTP ·RTSP · SDP ·
SOAP · GTP · STUN · NTP · SSDP
3、要对绝对地址0x100000赋值,我们可以用(unsigned int*)0x100000 = 1234;
那么要是想让程序跳转到绝对地址是0x100000去执行,应该怎么做?
答案:*((void (*)( ))0x100000 ) ( );
首先要将0x100000强制转换成函数指针,
即:(void (*)())0x100000然后再调用它:*((void (*)())0x100000)();
用typedef可以看得更直观些:typedef void(*)() voidFuncPtr;*((voidFuncPtr)0x100000)();
4、写出该程序的运行结果
#include <iostream> using namespace std; class A { public: A(){cout << "A::A()" << endl;} ~A(){cout << "~A::~A()" << endl;} }; class B { public: B(){cout << "B::B()" << endl;} ~B(){cout << "~B::~B()" << endl;} }; class C: public B { A a; public: C(){cout << "C::C()" << endl;} ~C(){cout << "~C::~C()" << endl;} }; A a; int main() { C c; return 0; }
cygwin下运行结果如下:
A::A()
B::B()
A::A()
C::C()
~C::~C()
~A::~A()
~B::~B()
~A::~A()
5、编写一个String类
#include <iostream> #include <cstdlib> #include <cstring> #include <cassert> using namespace std; class String { char *m_pdata; public: String(const char *str = NULL);//普通构造函数 String(const String& other);//拷贝构造函数 ~String();//析构函数 String& operator=(const String& other);//重载= String& operator=(const char *str);//重载= }; String::String(const char *str) { if(NULL == str) { m_pdata = new char[1]; assert(m_pdata != NULL); } else { m_pdata = new char[strlen(str) + 1]; assert(m_pdata != NULL); strcpy(m_pdata, str); } } String::String(const String& other) { m_pdata = new char[strlen(other.m_pdata) + 1]; assert(m_pdata != NULL); strcpy(m_pdata, other.m_pdata); } String::~String() { delete [] m_pdata; m_pdata = NULL; } String& String::operator=(const String& other) { if(&other == this) { return *this; } delete [] m_pdata; m_pdata = new char[strlen(other.m_pdata) + 1]; assert(m_pdata != NULL); strcpy(m_pdata, other.m_pdata); return *this; } String& String::operator=(const char *str) { delete [] m_pdata; if(NULL == str) { m_pdata = new char[1]; assert(m_pdata != NULL); m_pdata[0] = '\0'; } else { m_pdata = new char[strlen(str) + 1]; assert(m_pdata != NULL); strcpy(m_pdata, str); } return *this; } int main() { char chs[] = "hello"; String s(chs); return 0; }
6、二分查找
#include <stdio.h> int binarysearch(int a[], int n, int k) { int mid; if(n <= 0) return -1; mid = n/2; if(a[mid] == k) return mid; if(a[mid] < k) return binarysearch(a, mid, k); return binarysearch(a+mid+1, n-mid-1, k) + mid + 1; } int main() { return 0; }
7、写一个队列类
8、优先级反转及其解决办法
暂时这些吧,希望通过呵呵。。。