问答题
请使用VC6或使用【答题】菜单打开考生文件夹pmj1下的工程pmjl,此工程中含有一个源程序文件pmj1.cpp。其中位于每个注释“//ERROR ****found****”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为: This object is no.1 注意:只修改注释“//ERROR ****found****”的下一行语句,不要改动程序中的其他内容。//proj1.cpp#include<iostream>using namespace std;class NyClass{public: NyClass():count(0){cout<<”This object is”;)//ERROR********found******** void Inc()const {tout<<”no.”<<++count<<end1;}private://ERROR********found******** int count=0; }; int main() { NyClass*obj=new NyClass; //ERROR********found******** *obj.Inc(); return 0; }
【正确答案】正确答案:(1)void Inc() (2)int count; (3)obj一>Inc();
【答案解析】解析:(1)考查考生对const的掌握,在Inc函数的函数体{cout<<“no.”<<++count<”,而不能使用“.”。