自考真题答案

3773考试网自学考试自考真题答案正文

2011年自考C++程序设计试题

来源:fjzsksw.com 2011-6-8 16:31:24

 

二、排除下列程序的错误(每处错误3分,共30分)

1、请指出以下程序的3处错误的位置

#include

void f1();

void f2(int x);

void f2(int x,int y=0);

void f2(const int&);

void main()

{

f1();

       f2(3,4);

       f2(3);

}

void f1(int x)

{

       cout<

}

void f2(int x)

{

       cout<

}

void f2(int x,int y)

{

cout<

}

void f2(const int & x)

{

       cout<

}

2、请指出以下程序的4处错误的位置

#include

class sample

{

public:

       sample (int xx, int zz)

{

x=xx;

z=zz;

}

       void disp(){cout<

       static void f1()

{

              cout<

       }

       void ~sample()

       {cout<<”destructing object”<

protected:

       int x;

       static int y=100;

       const z;

};

void main()

{

       const sample a2(3, 5);

       a2.disp();

}

3、请指出以下程序的3处错误的位置

#include

class base

{

protected:

       int x;

       int *p;

public:

       base(int xx)

       {

              x=xx;

              p=new int[x];

       }

       ~base()

       {delete []p;}

};

class derive:public base

{

protected:

       int y;

       int * p1;

public:

       derive(int xx,int yy)

       {

              p=new int[x=xx];

       y=yy;

       p1=new int[yy];

}

~derive()

{

       delete []p1;

}

};

void main()

{

       base b1[10];

base *p1;

       derive *p2;

       p2=new derive(10,10);

       p1=p2;

       free p1;

}

 

上一页  [1] [2] [3] 下一页

触屏版 电脑版
3773考试网 琼ICP备12003406号-1