试卷详情
-
全国计算机等级考试二级C++上机题库试卷一2013年
-
[简答题]改错题
使用VC6打开考生文件夹下的工程kt6_1,此工程包含一个源程序文件kt6_1.cpp,但该程序运行有问题,请改正程序中的错误,使程序的输出结果如下:
Constructor2
Constructor1
i=0
i=10
Destructor
源程序文件kt6_1.cpp清单如下:
#include
classCSample
{
inti;
public:
CSample( ){cout<<"Constructor1"<
CSample(intval){cout<<"Constructor2"<
~CSample( ){cout<<"Destructor"<
voiddisp( );
};
/**********found**********/
voiddisp( )
{cout<<"i="<
voidmain( )
{
CSample*a,b(10);
/**********found**********/
a->disp( );
/**********found**********/
b->disp( );
}
-
[简答题]简单应用题 编写函数fun( ),它的功能是利用以下所示的简单迭代方法求方程cos(x)-x=0的一个实根。 xn+1=cos(xn) 迭代步骤如下: (1)取x1初值为0.0。 (2)x0=x1,把x1的值赋给x0。 (3)x1=cos(x0),求出一个新的x1。 (4)若x0-x1的绝对值小于0.000001,则执行步骤(5),否则执行步骤(2)。 (5)所求x1就是方程cos(x)-x=0的一个实根,做为函数值返回。 程序输出结果Root=0.739085。 注意:部分源程序已存在文件kt6_2.cpp中。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 文件kt6_2的内容如下: #include #include #include floatfun( ) { } voidmain( ) {cout<<"Root="<
-
[简答题]综合应用题使用VC6打开考生文件夹下的工程kt6_3,此工程包含一个源程序文件kt6_3.cpp,其中定义了用于表示考生的类Student,请按要求完成下列操作,将程序补充完整。 (1)定义私有数据成员code、english分别用于表示考生的编号、英语成绩、它们都是int型的数据。请在注释“//**1**”之后添加适当的语句。 (2)完成成员函数voidStudent::inputinformation( )的定义,该函数用于用户输入一个考生对象的信息,输入格式如下所示: 输入编号: 英语成绩: 计算机成绩: 请在注释“//**2**”之后添加适当的语句。 (3)利用已实现的类Student的成员函数,完成函数voidfirstname(Student*A[],intnum)的定义,该函数根据考生信息A[],输出num个考生中总分最高者的编号及其相应的总分,在此不考虑总分相同的情况。请在注释“//**3**”之后添加适当的语句。 注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。 源程序文件kt6_3.cpp清单如下: #include classStudent {//**1** intcomputer; inttotal; public: voidgetinformation( ); voidcomputesum( ); intgetcode( ); intgettotalscore( ); ~Student( );}; voidStudent::getinformation( ) {//**2** cout<<"英语成绩:"; cin>>english; cout<<"计算机成绩:"; cin>>computer;} voidStudent::computesum( ) {total=english+computer; cout<<"编号"< intStudent::getcode( ) {returncode;} intStudent::gettotalscore( ) {returntotal;} voidfirstname(Student*A[],intnum) { //**3** tempsum=(*A[0]).gettotalscore( ); for(inti=1;i { if(((*A[i]).gettotalscore( ))>tem