2008自考c 试题(附答案) 下载本文

41.#include

main( ) {

int x=5,y=6;

const int * p=&x;

*p=y;

cout<<*p<

42.#include

class f{

private:int x,y;

public:f1( ){x=0;y=0;}

print( ){cout<

main( ){

f a;

a.f1(1,1);

a.print( ); }

43.#include

class f{

private:int x=0,y=0;

public:void f1(int a,int b){x=a;y=b;}

void get( ){cout<

};

main( ){

f a;

a.f1(1,3);

a.get ( );

}

44.#include

class point{private:float x;

public:void f(float a){x=a;}

void f( ){x=0;}

friend float max(point& a,point& b);

};

float max(point& a,point& b)

{return(a.x>b.x)? a.x:b.x;}

main( ){

point a,b;

a.f(2.2);b.f(3.3);

cout<

}

45.#include

template

class f{

private:T x,y;

public:void f1(T a,T b){x=a;y=b;}

T max( ){retum(x>y)?x:y;} };

main( ){

f a;

a.f1(1.5,3.8); ’

cout<

四、完成程序题(本大题共5小题,每小题4分,共20分)

46.完成下面类中的成员函数的定义。

class point

{

private:

int m,n;

public:

point(int,int);

point(point&);

};

point::point(int a,int b)

{

m=a;

________=b; }

point::point(________)

{

m=t.m;

n=t.n;

}

47.下面是一个输入半径,输出其面积和周长的C++程序,在下划线处填上正确的语句。

#include

using namespace std;

________pi=3.14159;

void main( ) {

double r;

cout<<″r=″;

___________ ;

double l=2.0*pi*r;

double s=pi*r*r;

cout<<″\n The long is:″<

cout<<″The area is:″<

}

48.在下划线处填上缺少的部分。

#include

#include

using namespace std;

class complex

{

public:

int real;

int imag;

complex(int r=0,int i=0)

{

real=r;

imag=i;

}

};

complex operator+(________,complex& b)

{

int r=a.real+b.real;

int i=a.imag+b.imag;

return_________;

}

void main( )