操作题1.请打开考生文件夹下的解决方案文件proj1,此工程中含有一个源程序文件proj1.cpp。其中位于每个注释“//ERROR **** found ****”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为: Constructor called. The value is 10 Max number is 20 Destructor called. 注意:只能修改注释“//ERROR **** found ****”的下一行语句,不要改动程序中的其他内容。 //proj 1.cpp #include<iostream> using namespace std;
class MyClass{ public: //ERROR ******** found ******** void NyClass(int i) {value=i;cout;<<"Constructor called."<<endl;}
int Max(~nt x, int y) { return x>y?x:y;} //求两个整数的最大值
//ERROR ******* found ******* int Max(int x,int y,int z=0) //求三个整数的最大值 { if(x>y) return x>z?x:z; else return y>z?y:z; }
int GetValue()const {returnvalue;}
~NyClass() {cout;<<"Destructor called."<<endl;} private: int value; };
int main() { MyClass obj(10); //ERROR ******* found ******* cout << "The value is" <<value()<<endl; cout<<"Max number is" <<obj.Nax(10,2 0)<<endl; return 0; }
【正确答案】(1)MyClass(int i) (2)int Max(int x,int y,int z) (3)cout<<"The value is"<<obj.GetValue()<<endl: