问答题
使用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。...