【文件属性】:
文件名称:面向对象程序设计试题集
文件大小:260KB
文件格式:DOC
更新时间:2017-05-06 04:21:39
试题集
一.阅读程序题
1. #include
class CSample
{
int i;
public:
CSample()
{
i=1; cout<
class Sample
{
private:
int x;
public:
Sample(){ cout<<(x=0);}
Sample(int i,int j) {cout<<(x=i+j);}
~Sample(){cout<
class Sample
{
public:
Sample(){}
Sample(int a){x=a;}
Sample(Sample &a){x=a.x++;}
void disp(){cout<
class Sample
{
int x;
public:
Sample(){x=0;}
Sample(int a) {cout<<(x=a);}
~Sample()
{
cout<<++x;
}
void disp()
{
cout<
class Sample
{
int x;
public:
Sample(){cout<<(x=0);}
Sample(int i){cout<<(x=i);}
~Sample(){cout<
class Sample
{
public:
Sample(){cout<<"Constructor"<
class Sample
{
int n;
public:
Sample(int i){n=i;}
friend int add(Sample &s1,Sample &s2);
};
int add(Sample &s1,Sample &s2) {
return s1.n+s2.n;
}
void main()
{
Sample s1(10),s2(20);
cout<
class B;
class A
{
int i;
public:
int set(B&);
int get(){return i;}
A(int x){i=x;}
};
class B
{
int i;
public:
B(int x){i=x;}
friend A;
};
int A::set(B &b)
{
return i=b.i;
}
void main()
{
A a(1);
B b(2);
cout<
float f(float x, float y)
{
return x+y;
}
int f(int x, int y)
{
return x+y;
}
void main()
{
float a, b, c;
a = b = 50.5; c = f(a, b);
cout << c;
}
10. #include
int max(int x, int y)
{
if(x > y) return x;
else return y;
}
int max(int x, int y, int z)
{
return max(x, max(y, z));
}
void main()
{
int a = 3, b = 4, c = 5, d = 0; d = max(a, b);
cout << d;
}
11. #include
int p(int x = 4, int y = 5) {
return x + y;
}
void main()
{
int a = 3, b = 4, c = 0; c = p(b);
cout << c;
}
12. #include
int add(int x, int y = 8);
void main()
{
int a = 6; cout << add(a, add(a)) << endl;
}
int add(int x, int y)
{
return x + y;
}
13. #include
int p(int x = 4, int y = 5, int z = 6) {
return x + y + z;
}
void main()
{
int a = 3, b = 4, c = 5; c = p(b, a);
cout << c;
}
14. #include
int p(int x = 4, int y = 5, int z = 6) {
return x + y + z;
}
void main()
{
int a = 3, b = 4, c = 0; c = p(b, c);
cout << c;
}
15. #include
int n = 1; void Fun();
void main()
{
n++;
Fun();
if(n > 0) {
int n = 5; cout<< "Block:n=" << n << ",";
}
cout << "Main:n = " <