/*------------------------------------------------------ 【程序改错】
--------------------------------------------------------
题目:类B是类A的友元类,程序的运行结果为: 20 10
--------------------------------------------------------
注意:不可以增加或删除程序行,也不可以更改程序的结构。 ------------------------------------------------------*/
#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 /***********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 int a[20],n,find,k,m,i,j; cin>>n; for(i=0;i /***********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 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 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<<\}