C++上机考试复习资料(程序改错)

2019-06-05 00:14

/*------------------------------------------------------ 【程序改错】

--------------------------------------------------------

题目:类B是类A的友元类,程序的运行结果为: 20 10

--------------------------------------------------------

注意:不可以增加或删除程序行,也不可以更改程序的结构。 ------------------------------------------------------*/

#include #include

class A {

private:

int x; public:

A(int a){x=a;}

/***********FOUND***********/ Friend class B; };

/***********FOUND***********/ class B {

private:

int x; public:

B(int a){x=a;}

/***********FOUND***********/ void set(A &aa){x=aa.x;} int get(){return x;} };

void main() {

A a(10); B b(20);

cout<

/***********FOUND***********/ cout<

1) friend class B

2) class B

3) void set(A &aa){x=aa.x;} 4) cout<

/*------------------------------------------------------ 【程序改错】

--------------------------------------------------------

题目: 一个数列的头三个数是0,0,1,第四个数是前三个数之和, 以后每个都是前三个数之和,问当该数列中的某个数值达 到10的15次方,它是该数列的第几项?

--------------------------------------------------------

注意:不可以增加或删除程序行,也不可以更改程序的结构。 ------------------------------------------------------*/

#include void main()

/***********FOUND***********/ {double i,j,k,l,n; i=j=0; k=1; n=3;

while(k<1e15) {n++; l=i+j+k;

/***********FOUND***********/ i=j;

/***********FOUND***********/ k=j;

/***********FOUND***********/ k=l; }

cout<

1) {double ★i★,★j★,★k★,★l★,★n★; 2) i=j; 3) j=k; 4) k=1;

/*------------------------------------------------------ 【程序改错】

--------------------------------------------------------

题目:用二分法在一组按升序的数中找出指定的数K.

--------------------------------------------------------

注意:不可以增加或删除程序行,也不可以更改程序的结构。 ------------------------------------------------------*/

#include void main() {

int a[20],n,find,k,m,i,j; cin>>n;

for(i=0;i>a[i]; cin>>k; find=0; i=0;j=n-1;

/***********FOUND***********/ while(i<=j&&find=0) {m=(i+j)/2; if(k==a[m])

/***********FOUND***********/ find=0;

/***********FOUND***********/ else if(k>a[m]) j=m-1; else i=m+1; }

/***********FOUND***********/ if(find=1)

cout<<\else

cout<<\}

1) while(j<=j&&find==0) 2) find=1;

3) else if(k

/*------------------------------------------------------ 【程序改错】

--------------------------------------------------------

题目:以下程序中函数fun1和fun2为两个虚函数,类derive为base 的派生类。程序的运行结果为: base::fun1() base::fun2()

--------------------------------------------------------

注意:不可以增加或删除程序行,也不可以更改程序的结构。 ------------------------------------------------------*/

#include class base {

public:

virtual void fun1()=0;

/***********FOUND***********/ abstract void fun2()=0; {

cout<<\ } };

/***********FOUND***********/ class base:fun1() {

cout<<\}

class derive:public base {

public:

void fun1(){base::fun1();} void fun2(){base::fun2();} /***********FOUND***********/ }

void main() {

/***********FOUND***********/ base d; d.fun1(); d.fun2(); }

答案:

1) virtual void fun2()=0 2) void base::fun1() 3) };

4) derive d;

/*------------------------------------------------------ 【程序改错】

-------------------------------------------------------- 题目:该程序的输出结果为 number=3,7,10 number=14,9,11 sum=54 sum=54 sum=54

程序中共有4条错误语句,请改正错误。 --------------------------------------------------------

注意:不可以增加或删除程序行,也不可以更改程序的结构。 ------------------------------------------------------*/ #include class Myclass {

public: /**********FOUND**********/ Myclass(int a, b, c); void Getnumber(); void Getsum(); static int sum;//静态成员 private: int A,B,C; };

/**********FOUND**********/ static int Myclass::sum=0;

Myclass::Myclass(int a,int b,int c) { A=a; B=b; C=c;

sum+=A+B+C; }

/**********FOUND**********/ Myclass::Getnumber() { cout<<\}

void Myclass::Getsum() { cout<<\}


C++上机考试复习资料(程序改错).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:2009年第七届六年级“希望杯”培训试题100题

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: