问答题
使用VC6打开考生文件夹下的工程RevProj12。此工程包含一个源程序文件RevMain12.cpp,但在该程序中有错误。请改正程序中的错误,使它能得到正确结果。
注意:不得删行或增行,也不得更改程序的结构。
源程序文件RevMain12.cpp中的程序清单如下:
//RevMain12.cpp
#include<iostream>
/* * * * FOUND * * * * */
using namespace std;
class test
private:
const int value;
char dep[10];
public:
/* * * * *FOUND* * * * */
test()
value=0;
strcpy(dep,"m");
/* * * * *FOUND* * * * */
test(int newvalue)
value=newvalue;
strcpy (dep, "m");
/* * * * *FOUND * * * * */
void show()
cout<<"value= "<<value<<end1;
;
int main ()
test t1;
const test t2;
t1.show ();
t2.show();
return 0;
【参考答案】
正确的类定义为:
#include<iostream>
#include<string>......
(↓↓↓ 点击下方‘点击查看答案’看完整答案、解析 ↓↓↓)
点击查看答案&解析
<上一题
目录
下一题>
热门
试题
问答题
请编写一个函数void fun(int a [],int n),其中a为数组,n为数组a的长度。函数fun()的功能是冒泡排序法将数组a元素按从小到大的顺序排列,实现数组a的升序排列。 注意:部分源程序已存在文件PROC12.cpp中。 请勿修改主函数和其他函数中的任何内容,仅在函数fun()的花括号中填写若干语句。 文件PROC12.cpp的内容如下: PROC12. cpp #include <iostream> using namespace std; #define MAX 100 void fun(int a[],int n); int main () int a[MAX],n,i; cout<< Please enter the array size n: n ; do cin>>n; if (n>100) cout<< array size flowover! ReEnter a number(0-100) n ; while (n>100); cout<< Enter the array data: n ; for (i=0; i<n; i++) cin>>a [ii; fun(a[],n); for (i=0; i<n; i++) cout<<a [i] << ; cout<<end1; return 0; void fun(int a[ ],int n) * * * * * * * *
点击查看答案&解析
问答题
使用VC6打开考生文件夹下的工程MyProj12。此工程包含一个源程序文件MyMain12.cpp。程序中定义了两个类Base和Derived,但类的定义并不完整。 请按要求完成下列操作,将类的定义补充完成: ①类Derived是基类Base公有派生来的。请在注释“ * *1* *”之后添加适当的语句。 ②完成构造函数Derived(int x)定义,采用初始化列表的方式使基类Base私有成员a初始化为x,类Derived的私有成员b初始化为x+1。请在注释“ * *2* *”之后添加适当的语句。 ③完成类Derived的成员函数show()的类体外的定义。函数show()中要输出基类数据成员a的值,然后要输出私有成员b的值。请在注释“ * *3* *之后添加适当的语句。 注意;除在指定位置添加语句之外,请不要改动程序中的其他内容。 源程序文件MyMain12.cpp清单如下: MyMain12.cpp #include<iostream> using namespace std; class Base public: int a; Base(int i) a=i; ; * * * 1 * * * private: int b; public: * * * 2 * * * void show(); ; void Derived::show() * * * 3 * * * int main() Derived d(1); d.show(); return 0;
点击查看答案&解析
相关试题
请编写一个函数void fun(int a [],i...
使用VC6打开考生文件夹下的工程MyProj12...