请使用VC6或使用【答题】菜单打开考生文件夹proj1下的工程proj1。程序中位于每个“//ERROR****found****”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: value=63 number=1 注意:只修改每个“//ERROR****found****”下的那一行,不要改动程序中的其他内容。#includeiostreamusing namespace std;class MyClass{ int*p; const int N;public://ERROR ********found******** MyClass(int val):N=1 { p=new int; *p=val; }//ERROR********found******** ~MyClass(){delete*p;) friend void print(MyClassobj);};//ERROR********found********void MyClass::print (MyClassobj){ cout"value="*(obj.p)endl; cout"number="obj.Nendl;}int main(){MyClass obj(63);print(obj);return 0;}
在说明int const *ptr;中,ptr应是( )。
请打开考生文件夹下的解决方案文件proj2,其中在编辑窗口内显示的主程序文件中定义有类XBase和XDerived,以及主函数main。程序文本中位于每行"//**********found**********下面的——行内有一处或多处下划线标记,请在每个下划线标记处填写合适的内容,并删除掉下划线标记。经修改后运行程序,得到的输出结果为:s=25#includeiostreamusing namGspacG std;class XBase{ private: int mem1,mem2; public: //*****found***** XBase (int m1=0,int m2=0):mem1(m1),___________{} //*****found***** Virtual int___________};//*****found*****class XDerived:{ private: int mem3; public: XDerived():XBase(),mem3(0){} //*****found***** XDerived(int m1,int m2,int m3):___________{} int sum() {return XBase::sum()+mem3;}};void main(){ XDerived b(3,4,5); XBase a(6,7), *pb=b; int s=pb-sum()+a.sum(); tout"s="sendl;}
对于多重继承,下面说法中正确的是( )。
使用VC6打开考生文件夹下的源程序文件modil.cpp,但该程序运行时有错,请改正程序中的错误,使程序输出的结果为: 1 5 1注意:错误的语句在∥********error********的下面,修改该语句即可。#includeiostream.h∥********error********enum{ Sun, Mon, Tue, Wed, Thu, Fri, Sat, ∥********error********}MyEnum;struct Struct{∥********error******** int Fri, int Sun;};void main(){ int i=Mon; MyEnum t=Fri; Struct str1; Strl.Fri=Mon; coutiendl; couttendl; coutstrl.Friendl;}
请打开考生文件夹下的解决方案文件proj1,此工程中包含程序文件main.cpp,其中有类Score(“成绩”)和主函数main的定义,程序中位于每个“//ERROR ****found****”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: 学号:12345678课程:英语总评成绩:85 注意:只修改每个“//FRROR ****found****”下的一行,不要改动程序中的其他内容。#includeiostreamusing namespace std;class score {public: Score (const char *the COUrSe,const char*the id,int the normal,int the midterm,int the end of term) :course(the_course),normal(the_normal),midterm(the_midterm),end_of_term(the_end_of_term){//ERROR **********found********** strcpy(the_id,student_id); } const char*getCourse()const{return course;}//返回课程名称//ERROR **********found********** const char*getID()const{returnstudent id;} //返回学号 int getNormal()const{return normal ;} //返回平时成绩 int getMidterm()const{ return midterm;}//返回期中考试成绩 int getEndOfTerm()const{return end of term;} //返回期末考试成绩 int getFinal()const; //返回总评成绩private: const char*course; //课程名称 char student id[12]; //学号 int normal; //平时成绩 int midterm; //期中考试成绩 int end of term; //期末考试成绩};//总评成绩中平时成绩占20%,期中考试占30%,期末考试占50%,最后结果四舍五入为一个整数//ERROR *******found*******int getFinal()const{ return normal*0.2+midterm*0.3+end_of_term*0.5+0.5 ;}int main(){ char English[]="英语"; Score score(English,"12345678",68,83,92); cout"学号:"score.getID()" ": cout"课程:"score.getCourse()" "; cout"总评成绩:"score.getFinal()endl ; return 0;}
请打开考生文件夹下的解决方案文件proj1,此工程中包含程序文件main.cpp,其中有类Score(“成绩”)和主函数main的定义,程序中位于每个“//ERROR ****found****”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: 学号:12345678课程:英语总评成绩:85 注意:只修改每个“//FRROR ****found****”下的一行,不要改动程序中的其他内容。#includeiostreamusing namespace std;class score {public: Score (const char *the COUrSe,const char*the id,int the normal,int the midterm,int the end of term) :course(the_course),normal(the_normal),midterm(the_midterm),end_of_term(the_end_of_term){//ERROR **********found********** strcpy(the_id,student_id); } const char*getCourse()const{return course;}//返回课程名称//ERROR **********found********** const char*getID()const{returnstudent id;} //返回学号 int getNormal()const{return normal ;} //返回平时成绩 int getMidterm()const{ return midterm;}//返回期中考试成绩 int getEndOfTerm()const{return end of term;} //返回期末考试成绩 int getFinal()const; //返回总评成绩private: const char*course; //课程名称 char student id[12]; //学号 int normal; //平时成绩 int midterm; //期中考试成绩 int end of term; //期末考试成绩};//总评成绩中平时成绩占20%,期中考试占30%,期末考试占50%,最后结果四舍五入为一个整数//ERROR *******found*******int getFinal()const{ return normal*0.2+midterm*0.3+end_of_term*0.5+0.5 ;}int main(){ char English[]="英语"; Score score(English,"12345678",68,83,92); cout"学号:"score.getID()" ": cout"课程:"score.getCourse()" "; cout"总评成绩:"score.getFinal()endl ; return 0;}
请打开考生文件夹下的解决方案文件proj1,此工程包含一个源程序文件proj1.cpp。其中位于每个注释“//ERROR****found****”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为:You are right. 注意:只修改注释“//ERROR ****found****”的下一行语句,不要改动程序中的其他内容。//proj1.cpp#includeiostreamusing namespace std;class HyClass{public: MyClass(int x):number(x){)//ERROR *******found******* ~MyClass(int x){}//ERROR *******found******* void Judge(MyClassobj);private: int number ;};void Judge(MyClas sobj){ if(obj.number=10) cout"You are right."endl; else cout"Sorry"endl:}int main(){//ERROR *******found******* MyClass object; Judge(object); return 0;}
使用VC6打开考生文件夹下的源程序文件modi2.epp。阅读下列函数说明和代码,补充空出的代码。函数IsPalindromes(cha*string)实现的功能是判定给定的字符串是否构成回文字符串,如果是则返回1,否则返回0。 如:1234554321或者1234321都认为是回文字符串。 如果串为空或一个字母时,均认为是回文字符串。 注意:不能修改程序的其他部分,只能补充IsPalindromes()函数。1 #include2 #define MAXLEN 10243 bool IsPalindromes(char*string)4 {56 }7 void main()8 {9 char str[MAXLEN];10 cout11 cin.getline(str,MAXLEN);12 cout13 return;14 }
