《面向对象程序设计语言C++》_期末考试试卷.doc
文本预览下载声明
《面向对象程序设计语言C++》 期末考试试卷
一、填空题
1、在字长为32位的机器中,sizeof(char)= 1 字节,sizeof(unsigned int)=4字节.
2、C++语法规定,任何变量在使用前必须先 定义 ;变量有两个值,一个是变量本身的值,另一个是变量的 地址 。
3、C++中任何一个数组的名字是一个 常量 指针,该指针的值是该数组 第0号元素 的地址。
4、函数调用时的参数传递主要分为单向传递和 双向 传递,前者的特点是 只能把实参对应的值依次传递给形参 。
5、函数重载时要求同名函数的参数 个数和参数类型 或返回值 (10) 不同,否则无法确定是哪个函数。
6、静态数据成员是类的所有对象中 共享 的成员,静态数据成员初始化与一般数据成员初始化 不同 。
二、写出程序的运行结果
1、#include iostream.h
void main()
{
int a,b,c,d(5);
c=2,c+=10;
a =b=10;
a * = 2;
b / = 2;
c % = 2;
couta,b,cendl;
}
20,5,0
2、#include iostream.h
void main()
{
int a = 50 , b(0) ;
b = ++a;
couta,bendl;
b = a++;
couta,bendl;
}
50,51
50,50
3、#include iostream.h
void main()
{
int f = 2002 , x;
if( f != 3)
x = 2003 ;
else
x = 20 ;
coutf,xendl;
}
2002,2003
4、#include iostream.h
void main()
{
int i=1,sum=0;
while(i=10)
sum+ = ++i;
cout sum= sum , i= iendl;
}
65,110
5、#include iostream.h
void main()
{
int i;
for(i=4 ; i=10 ; i++ )
{ if (i%3= =0) continue;
couti; }
}
4,5,7,8,10
6、#include iostream.h
void main()
{
char flag=c ;
switch(flag)
{
case a :cout1endl ;
case b :cout 2endl ; break;
case c : cout 3endl ;
default : cout 4endl ; break;
}
}
30
7、#include iostream.h
void main()
{
static int b[][3] = { {1,2,3},{4},{5,6} };
b[0][2]=12,b[1][2]=18;
cout **b\t**(b+1) \t**b+1\t*(*(b+1)+2) \n;
cout b[0][2]+b[1][2]+b[2][2] endl;
}
1 4 2 18
30
8、#include iostream.h
void Swap( int a, int b);
void main()
{
int x( 10 ), y( 7 );
coutx=x y=yendl;
Swap( x , y );
coutx=x y=yendl;
}
void Swap(int a, int b)
{ int temp; temp = a ; a=b ; b=temp ; }
10 7
7,10
9、#include iostream.h
int add(int a, int b);
void main()
{
extern int x, y;
coutadd(x,y)endl;
x/=y;
coutadd(x,y)endl;
}
int x(50),y(100);
int add(int a, int b)
{ int s=a+b ; return s; }
150
100
10、#include iostream.h
class A
{
public:
A();
A(int i,int j);
~A(){coutDonstructor.\n;}
void print();
p
显示全部