问答题
使用VC6打开考生文件夹下的工程proj2。此工程包含一个源程序文件main2.cpp,但该程序运行有问题。请改正main函数中的错误。
源程序文件main2.cpp清单如下:
//main2.cpp
#include <iostream>
using namespace std;
class MyClass
public:
MyClass(int m)
member=m;
~MyClass()
int GetMember()
return member;
private:
int member;
;
MyClass MakeObject(int m)
MyClass *pMyClass=new MyClass(m);
return *pMyClass;
int main ( )
int x=7;
/************found**************/
MyClass *myObj=MakeObject(x);
/*************found*************/
cout<<"My object has member"<<myObj.GetMember()<<end1;
return 0;
【参考答案】
修改后的主函数为:
int main()
{
int x=7;
MyCl......
(↓↓↓ 点击下方‘点击查看答案’看完整答案、解析 ↓↓↓)
点击查看答案&解析
<上一题
目录
下一题>
热门
试题
问答题
编写一个函数,用该函数可以统计一个长度为3的字符串在另一个字符串中出现的次数。例如,假定输入字符串“the abcthe they have theren”,子字符串为“the”,则应输出4。 注意:部分源程序在文件PROC2.CPP中。 请勿改动主函数和其他函数中的任何内容,仅在fun()的花括号中填入编写的若干语句。 部分源程序如下: PROC2.CPP #include <iostream> using namespace std; #define MAX 100 int fun(char *str,char *substr); int main() char str[MAX],substr[3]; int n; cout<< Please Input the source String n ; cin>>str; cout<< Please Input the subString n ; cin>>substr; n=fun(str, substr); cout<< The counter is: <<n<<end1; return 0; int fun(char *str,char *substr) ******
点击查看答案&解析
问答题
使用VC6打开考生文件夹下的工程MyProj2。此工程包含一个源程序文件 MyMain2.cpp,此程序的运行结果为: Derive1’s Print() Called. Derive2’s Print() called. 其中定义的类并不完整,按要求完成下列操作,将类的定义补充完整。 ①定义函数Print()为无值型纯虚函数。请在注释“ **1**”之后添加适当的语句。 ②建立类Derivel的构造函数,请在注释“ **2**”之后添加适当的语句。 ③完成类Derive2成员函数Print()的定义。请在注释“ **3**”之后添加适当的语句。 ④定义类Derivel的对象指针d1,类Derive2的对象指针d2。其初始化值分别为1和2。 源程序文件MyMain2.cpp中的程序清单如下: MyMain2. cpp #include <iostream> using namespace std; class Base public: Base(int i) b=i; * * 1 * * protected: int b; ; class Derivel: public Base public: * * 2 * * void print () cout<< Derivel’s Print() called. <<end1; ; class Derive2 : public Base public: Derive2(int i) :Base(i) * * 3 * * ; void fun (Base *obj) obj->Print (); int main ( ) * * 4 * * fun (d1); fun (d2); return 0;
点击查看答案&解析
相关试题
使用VC6打开考生文件夹下的工程MyProj2。...
编写一个函数,用该函数可以统计一个长度为...