软件工程师笔试题Bgoyg.docx
校园招聘笔试题(软件B)学 校: 专 业: 姓 名: 学 历: 四级成绩: 最终得分: 注意:满分100分,答题时间45分钟一、填空题(共30分)1、通常,在什么情况下适合采用inline定义内联函数?_2、含有纯虚函数的类称为 3、C+函数中参数的传递方式有 、 、 三种方式。4、程序的局部变量存在于 中,全局变量存在于 中,动态申请内存存在于 中。5、C+里声明某一函数为C程序中的库函数,则需要在该函数前加_。6、如果编译器在编译和连接程序时,已经确定了调用函数的地址,这种做法通常称为_联编。7、C+预定义的标准输入流对象是_,标准输出流对象是_。8、#ifndef #define #endif的主要作用是 。(2分)9、假设定义类型如下:union Aint x; double y; char z; struct Bint x; char y; char* z;在Win32平台下,sizeof(A)= , sizeof(B)= 10、下面程序输出分别是 (4分)#define PRINTX printf("%d ", x)int main()int x=2,y,z;x*=3+2;PRINTX;x*=y=z=4;PRINTX;x=y=z;PRINTX;x=(y=z);PRINTX;return 0;11、假定CLS_PtzControl是一个类,那么执行语句CLS_PtzControl x5, *y3;时程序会自动调用该类的无参构造函数 次。(2分)12、对于数组int x10,其元素x4的字节地址为 。(2分)13、执行如下程序后的输出结果是: 。(2分)#include<iostream.h>class teststatic int count;public:test()count+;test()count-;static int getCount()return count;int test:count=0;int main()test * p=new test;test * q=new test; delete p;cout<<"count="<<test:getCount()<<endl;return 0;14、以下程序的正确执行结果为: 。(2分)#include<iostream.h>#int f(int);void main()int a=2,i;for(i=0;i<3;i+)cout<<f(a)<< " "cout<<endl;int f(int a)int b=0;static int c=3;b+;c+;return (a+b+c);15、下面程序的输出结果是 。(2分)#include<iostream.h>int fun(char *s)char *p=s;while(*p!='0')p+;return (p-s);void main()count<<fun("ABCDEF")<<endl;二、选择题(每题2分,共20分),请将答案写在【】内。【】1、C+中,符号“&”不可以表示的是:( )A取变量运算 B按位与运算 C引用运算符 D取地址运算【】2、有关函数重载的正确说法是:( )A函数名不同,但形式参数的个数和类型相同B函数名相同,但形式参数的个数不同或参数的类型不同C函数名相同,形式参数的个数和类型也相同D函数名相同,函数的返回值不同,而与函数的形式参数和类型无关【】3、对于std:vector<int> vec; const std:vector<int>:iterator iter = vec.begin() 下列说法正确的是( )A*iter = 10 和 +iter均可通过编译B*iter = 10可通过编译,+iter不可通过编译C*iter = 10不可通过编译,+iter可通过编译D*iter = 10 和 +iter均不可通过编译【】4、一个指向整型数组的指针的定义为:( )Aint(*ptr) Bint *ptr Cint*(ptr) Dint prt【】5、假定要对类AB定义加号操作符重载成员函数,实现两个AB类对象的加法,并返回相加结果,则该成员函数的声明语句为:( )A AB operator+(AB & a , AB & b) BAB operator+(AB & a)Coperator+(AB a) DAB & operator+( )【】6、如果需要定义一个只允许本源文件中能够被访问使用的全局变量,那么该变量使用的类型是( )Aextern Bregister Cauto Dstatic【】7、C+中的this指针是其实现( )的一种机制。A封装 B继承 C抽象 D重载【】8、对于类CLS_Matrix,语句void (CLS_Matrix:*pControl)(int _iCmd);表明( )ApControl是一个指向类成员函数的指针BpControl是类CLS_Matrix的一个成员CpControl是类CLS_Matrix的一个对象DpControl是一个指向类对象的指针【】9、设置虚基类的目的是( )A简化程序B消除二义性 C提高运行效率 D减少目标代码【】10、有如下程序:执行后的输出结果应该是( )#include <iostream.h>class BASEpublic:BASE()cout<<"BASE"class DERIVED: public BASEpublic:DERIVED()cout<<"DERIVED"void main()DERIVED x;ABASE BDERIVED CBASEDERIVED DDERIVEDBASE三、纠错题(8分)1、下面的函数实现代码是否有问题?请指出。(4分)答题处:char *GetMemory(void)char p = "hello world"return p;void Test(void)char *str = NULL;str = GetMemory();printf(str);2、以下的程序运行后会产生什么问题?(4分)答题处:#define SIZE 255int main() unsigned char ArraySIZE, i; for (i=0;i<=SIZE;i+) Arrayi=i;return 0;四、简答题(共42分)1、C中的结构体与C+中的类主要区别是什么?(5分)2、以下为Windows NT下的32位C+程序,请计算sizeof的值(5分)char str = "Hello" ;char *p = str ;int n = 10;请计算sizeof (str ) sizeof ( p ) = sizeof ( n ) = void Func ( char str100)请计算sizeof( str ) = void *p = malloc( 100 );请计算sizeof ( p ) = 3、类成员函数的重载、覆盖和隐藏区别?(8分)4、写出如下程序的运行结果。(12分)class Apublic:virtual void Output() printf("This is As Outputn");void Display() printf("A:Displayn"); Output(); ;class B:public Apublic:virtual void Output() printf("This is Bs Outputn"); 答题处:; int main()B b1;b1.Display(); (A *)(&b1)->Display(); (A)b1).Display();return 0;5、用单链表表示集合,设计算法求两个集合的并集。(12分)typedef struct SNodeint data;SNode * next; SNode;void diffence(SNode *A,SNode *B,SNode *&C) SNode *pa=A,*pb=B,*pc,*s,*r; C=(SNode*)malloc(sizeof(SNode); ; r=C; while(pa!=NULL) s=(SNode*)malloc(sizeof(SNode); ; s->next=NULL; r->next=s; ; pa = pa->next; while(pb!=NULL) pc=C->next; while( ) pc=pc->next; if(pc=NULL) s=(SNode*)malloc(sizeof(SNode); ; s->next=NULL; ; r=s; pb=pb->next; pc = C; C = C->next; free(pc); 6