校园招聘笔试题(软件B )
学 校: 专 业: 姓 名: 学 历: 四级成绩: 最终得分:
注意:满分100分,答题时间45分钟
一、填空题(共30分)
1、通常,在什么情况下适合采用inline 定义内联函数?2、含有纯虚函数的类称为3、C++函数中参数的传递方式有、、三种方式。
4、程序的局部变量存在于
5、C++里声明某一函数为C 程序中的库函数,则需要在该函数前加。
6、如果编译器在编译和连接程序时,已经确定了调用函数的地址,这种做法通常称为联编。
7、C++预定义的标准输入流对象是,标准输出流对象是。
8、#ifndef #define #endif的主要作用是(2分)
9、假设定义类型如下:
union A{int x; double y; char z;};
struct B{int x; char y; char* z;};
在Win32平台下,sizeof(A)= , sizeof(B)=
10、下面程序输出分别是4分)
#define PRINTX printf("%d ", x)
int main()
{
}
11、假定CLS_PtzControl是一个类,那么执行语句CLS_PtzControl x[5], *y[3];时程序会自动调用该类int x=2,y,z; x*=3+2;PRINTX; x*=y=z=4;PRINTX; x=y==z;PRINTX; x==(y=z);PRINTX; return 0;
的无参构造函数 次。(2分)
12、对于数组int x[10],其元素x[4]的字节地址为。(2分)
13、执行如下程序后的输出结果是:2分)
#include
class test{
static 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
return 0;
}
14、以下程序的正确执行结果为:2分)
#include
#int f(int);
void main()
{
int a=2,i;
for(i=0;i
{
cout
}
cout
}
int f(int a)
{
int b=0;
static int c=3;
b++;
c++;
return (a+b+c);
}
15、下面程序的输出结果是2分)
#include
int fun(char *s)
{
char *p=s;
while(*p!='\0')
{
p++;
}
return (p-s);
}
void main()
{
count
}
二、选择题(每题2分,共20分),请将答案写在【 】内。
【 】1、C++中,符号“&”不可以表示的是:( )
A .取变量运算 B .按位与运算 C .引用运算符 D .取地址运算
【 】2、有关函数重载的正确说法是:( )
A .函数名不同,但形式参数的个数和类型相同
B .函数名相同,但形式参数的个数不同或参数的类型不同
C .函数名相同,形式参数的个数和类型也相同
D .函数名相同,函数的返回值不同,而与函数的形式参数和类型无关
【 】3、对于std::vector vec; const std::vector::iterator iter = vec.begin() 下列说法正确的是( )
A .*iter = 10 和 ++iter均可通过编译
B .*iter = 10可通过编译,++iter不可通过编译
C .*iter = 10不可通过编译,++iter可通过编译
D .*iter = 10 和 ++iter均不可通过编译
【 】4、一个指向整型数组的指针的定义为:( )
A .int(*ptr)[] B .int *ptr[] C .int*(ptr[]) D .int prt[]
【 】5、假定要对类AB 定义加号操作符重载成员函数,实现两个AB 类对象的加法,并返回相加结果,则该成员函数的声明语句为:( )
A . AB operator+(AB & a , AB & b) B .AB operator+(AB & a)
C .operator+(AB a) D .AB & operator+( )
【 】6、如果需要定义一个只允许本源文件中能够被访问使用的全局变量,那么该变量使用的类型是( )
A .extern B .register C .auto
A .封装 B .继承 C .抽象 D .static D .重载 【 】7、C++中的this 指针是其实现( )的一种机制。
【 】8、对于类CLS_Matrix,语句void (CLS_Matrix::*pControl)(int _iCmd);表明( )
A .pControl 是一个指向类成员函数的指针 B .pControl 是类CLS_Matrix的一个成员
C .pControl 是类CLS_Matrix的一个对象 D .pControl 是一个指向类对象的指针
【 】9、设置虚基类的目的是( )
A .简化程序 B .消除二义性 C .提高运行效率 D .减少目标代码
【 】10、有如下程序:执行后的输出结果应该是( )
#include
class BASE{
public:
~BASE(){cout
};
class DERIVED: public BASE{
public:
~DERIVED(){cout
};
void main(){DERIVED x;}
A .BASE B .DERIVED C .BASEDERIVED D .DERIVEDBASE
三、纠错题(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 255
int main() 答题处:
{
unsigned char Array[SIZE], i;
for (i=0;i
{
Array[i]=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 ) =void Func ( char str[100])
{
请计算
sizeof( str ) =
}
void *p = malloc( 100 );
请计算
3、类成员函数的重载、覆盖和隐藏区别? (8分)
4、写出如下程序的运行结果。(12分)
class A{
public:
virtual void Output() { printf(" This is A’s Output\n" );}
void Display() { printf(" A::Display\n" ); Output(); }
};
class B:public A{
public:
virtual void Output() { printf(" This is B’s Output\n" ); }
}; 答题处: int main()
{ ① B b1; ② b1.Display();
((A *)(&b1))->Display(); ③ ((A)b1).Display(); ④ return 0;
⑤ }
⑥
5、用单链表表示集合,设计算法求两个集合的并集。(12分)
typedef struct SNode
{
int 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;
{
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);
}
① ② ③ ④ ⑤ ⑥
校园招聘笔试题(软件B )
学 校: 专 业: 姓 名: 学 历: 四级成绩: 最终得分:
注意:满分100分,答题时间45分钟
一、填空题(共30分)
1、通常,在什么情况下适合采用inline 定义内联函数?2、含有纯虚函数的类称为3、C++函数中参数的传递方式有、、三种方式。
4、程序的局部变量存在于
5、C++里声明某一函数为C 程序中的库函数,则需要在该函数前加。
6、如果编译器在编译和连接程序时,已经确定了调用函数的地址,这种做法通常称为联编。
7、C++预定义的标准输入流对象是,标准输出流对象是。
8、#ifndef #define #endif的主要作用是(2分)
9、假设定义类型如下:
union A{int x; double y; char z;};
struct B{int x; char y; char* z;};
在Win32平台下,sizeof(A)= , sizeof(B)=
10、下面程序输出分别是4分)
#define PRINTX printf("%d ", x)
int main()
{
}
11、假定CLS_PtzControl是一个类,那么执行语句CLS_PtzControl x[5], *y[3];时程序会自动调用该类int x=2,y,z; x*=3+2;PRINTX; x*=y=z=4;PRINTX; x=y==z;PRINTX; x==(y=z);PRINTX; return 0;
的无参构造函数 次。(2分)
12、对于数组int x[10],其元素x[4]的字节地址为。(2分)
13、执行如下程序后的输出结果是:2分)
#include
class test{
static 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
return 0;
}
14、以下程序的正确执行结果为:2分)
#include
#int f(int);
void main()
{
int a=2,i;
for(i=0;i
{
cout
}
cout
}
int f(int a)
{
int b=0;
static int c=3;
b++;
c++;
return (a+b+c);
}
15、下面程序的输出结果是2分)
#include
int fun(char *s)
{
char *p=s;
while(*p!='\0')
{
p++;
}
return (p-s);
}
void main()
{
count
}
二、选择题(每题2分,共20分),请将答案写在【 】内。
【 】1、C++中,符号“&”不可以表示的是:( )
A .取变量运算 B .按位与运算 C .引用运算符 D .取地址运算
【 】2、有关函数重载的正确说法是:( )
A .函数名不同,但形式参数的个数和类型相同
B .函数名相同,但形式参数的个数不同或参数的类型不同
C .函数名相同,形式参数的个数和类型也相同
D .函数名相同,函数的返回值不同,而与函数的形式参数和类型无关
【 】3、对于std::vector vec; const std::vector::iterator iter = vec.begin() 下列说法正确的是( )
A .*iter = 10 和 ++iter均可通过编译
B .*iter = 10可通过编译,++iter不可通过编译
C .*iter = 10不可通过编译,++iter可通过编译
D .*iter = 10 和 ++iter均不可通过编译
【 】4、一个指向整型数组的指针的定义为:( )
A .int(*ptr)[] B .int *ptr[] C .int*(ptr[]) D .int prt[]
【 】5、假定要对类AB 定义加号操作符重载成员函数,实现两个AB 类对象的加法,并返回相加结果,则该成员函数的声明语句为:( )
A . AB operator+(AB & a , AB & b) B .AB operator+(AB & a)
C .operator+(AB a) D .AB & operator+( )
【 】6、如果需要定义一个只允许本源文件中能够被访问使用的全局变量,那么该变量使用的类型是( )
A .extern B .register C .auto
A .封装 B .继承 C .抽象 D .static D .重载 【 】7、C++中的this 指针是其实现( )的一种机制。
【 】8、对于类CLS_Matrix,语句void (CLS_Matrix::*pControl)(int _iCmd);表明( )
A .pControl 是一个指向类成员函数的指针 B .pControl 是类CLS_Matrix的一个成员
C .pControl 是类CLS_Matrix的一个对象 D .pControl 是一个指向类对象的指针
【 】9、设置虚基类的目的是( )
A .简化程序 B .消除二义性 C .提高运行效率 D .减少目标代码
【 】10、有如下程序:执行后的输出结果应该是( )
#include
class BASE{
public:
~BASE(){cout
};
class DERIVED: public BASE{
public:
~DERIVED(){cout
};
void main(){DERIVED x;}
A .BASE B .DERIVED C .BASEDERIVED D .DERIVEDBASE
三、纠错题(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 255
int main() 答题处:
{
unsigned char Array[SIZE], i;
for (i=0;i
{
Array[i]=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 ) =void Func ( char str[100])
{
请计算
sizeof( str ) =
}
void *p = malloc( 100 );
请计算
3、类成员函数的重载、覆盖和隐藏区别? (8分)
4、写出如下程序的运行结果。(12分)
class A{
public:
virtual void Output() { printf(" This is A’s Output\n" );}
void Display() { printf(" A::Display\n" ); Output(); }
};
class B:public A{
public:
virtual void Output() { printf(" This is B’s Output\n" ); }
}; 答题处: int main()
{ ① B b1; ② b1.Display();
((A *)(&b1))->Display(); ③ ((A)b1).Display(); ④ return 0;
⑤ }
⑥
5、用单链表表示集合,设计算法求两个集合的并集。(12分)
typedef struct SNode
{
int 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;
{
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);
}
① ② ③ ④ ⑤ ⑥