填空题

使用VC6打开考生文件夹下的工程test39_1,此工程包含一个源程序文件test39_1.cpp,但该程序运行有问题,请改正函数中的错误,使该程序的输出结果为; This is static a: 1 This is non-static b: 1 This is static a: 2 This is non-static b: 2 This is static a: 2 This is non-static b: 1 Press any key to continue 源程序文件test39_1.cpp清单如下; #include<iostream.h> class shared { static int a; int b; public: /***************** found *****************/ void set(int i=0, int j) {a=i; b=j;} void show(); }; /***************** found *****************/ void shared::show() { cout << "This is static a: "<< a; cout << "\nThis is non-static b: " << b; /***************** found *****************/ cout >> "\n"; } void main () { shared x, y; x.set (1, 1); x.show ( ); y.set (2, 2); y.show ( ); x.show ( ); }

【参考答案】

(1) 错误:void set(int i=0,int j){a=i;b=j;} 正确:void set(int i,i......

(↓↓↓ 点击下方‘点击查看答案’看完整答案 ↓↓↓)
热门 试题

问答题
使用VC6打开考生文件夹下的工程test39_3。此工程包含一个test39_3.cpp,其中定义了类ARRAY和其派生类 STUDENT,其中类ARRAY是一个多态数组,该数组可以存放学校中的各类人员,如学生等,但它们的定义并不完整。请按要求完成下列操作,将程序补充完整。(1)定义类ARRAY的三个公有成员纯虚函数add(int a)、del(int d)和show(int s),它们的返回值类型都是void型的。请在注释“ **1**”之后添加适当的语句。(2)添加派生类STUDENT的保护数据成员float型的二维数组table,使其有row行和s_col列,请在注释“ **2**”。之后添加适当的语句。(3)完成派生类STUDENT的成员函数del(int s)的定义,实现把二维数组第s行删除的功能,即把该行清零,请在注释“ **3**”之后添加适当的语句。(4)完成派生类STUDENT的成员函数show(int s)的定义,使其以格式“ 跳格table[行号][列号]is_换行”依次输出s行的各个元素,请在注释“ **4**”之后添加适当的语句。源程序文件test39_3.cpp清单如下:#include <iostream.h>#include <stdlib.h>const int row = 100;const int s_col = 3;class ARRAY{public: ** 1 **}class STUDENT:public ARRAY{public:virtual void add(int s){cout<< tInput data of STUDENT. <<endl;cout<< tFirst: ;cin>>table[s] [0];cout<< tSecond: ;cin>>table[s] [1];cout<< tThird: ;cin>>table[s] [2];}virtual void del(int s);virtual void show(int s);protected:int i; ** 2 **};void STUDENT::del(int s){ ** 3 **}void STUDENT::show(int s){cout<<endl;for(i=0;i<=s_col-1;i++){ ** 4 **}}int main(){STUDENT st;ARRAY* ap;ap=&st;ap->add(3);ap->show(3);ap->del(3);ap->show(3);return 0;}