更多"使用VC6打开考生文件夹下的工程test38_3。此工程包含一个tes"的相关试题:
[简答题]使用VC6打开考生文件夹下的工程RevProj7。此工程包含一个源程序文件RevMain6.cpp,但该程序运行有问题。请改正主函数中的错误,使程序的输出结果是:
MyNumber=0
MyNumber=1
MyNumber=2
源程序文件RevMain6.cpp清单如下:
//RevMain6.cpp
#include<iostream>
using namespace std;
class MyClass
public:
MyClass(int i)
MyNumber=i;
void SetMember(int m)
MyNumber=m;
int GetMember( )const
return MyNumber;
void Print( ) const
cout<<"MyNumber="<<MyNumber<<end1;
private:
int MyNumber;
;
int main( )
/* * * * * * * * *found* * * * * * * * *
MyClass *pObj=new MyClass(O);
pObj.Print( );
/* * * * * * * * *found* * * * * * * * *
pObj->MyNumber = 1;
pObj->Print( );
/* * * * * * * * *found* * * * * * * * *
MyClass. SetMember(2);
(*pObj).Print( );
return O;
[简答题]使用VC6打开考生文件夹下的工程MyProj6。此工程包含一个源程序文件MyMain6.cpp。在程序中,定义了一个Furniture类,Bed类和Sofa类是在Furniture类的基础上按公有继承的方式产生的派生类,Sleepersofa类是在Bed类和Sofa类的基础上按公有继承的方式产生的派生类。
请按要求完成下列操作,将类Date的定义补充完成:
①Bed类是在Furniture类的基础上按公有继承的方式产生的派生类,为了使程序中的多重继承关系不出现二义性。请在注释“//**1**”之后添加适当的语句。
②Sofa类是在Furniture类的基础上按公有继承的方式产生的派生类,为了使程序中的多重继承关系不出现二义性。请在注释“//**2**”之后添加适当的语句。
③Sleepersofa类是在Bed类和Sofa类的基础上按公有继承的方式产生的派生类。请在注释“//**3**”之后添加适当的语句。
注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。
源程序文件MyMain6.cpp清单如下;
//MyMain6.cpp
#include<iostream>
using namespace std;
class Furniture
public:
Furniture( )
void setweight(int w)
weight=w;
int getweight( )
return weight;
protected:
int weight;
;
//* *1 * * class Bed definition
public:
Bed( )
void sleep( )
cout<<"sleeping..."<<end1;
;
//* *2* * class Sofa definition
public:
Sofa( )
[简答题]使用VC6打开考生文件夹下的工程RevProj3。此工程包含一个源程序文件 RevMain3.cpp。阅读文件中的程序代码,找出程序中的错误,并改正。
源程序文件RevMain3.cpp清单如下:
//RevMain3.cpp
#include<iostream>
using namespace std;
class MyClass
public:
/* * * * * * * * *found * * * * * * * * * */
void MyClass(int a) value=a;
int Max(int x,int y)
if(x>y)
return x>yx:y;
else
return y>valuey:value;
/* * * * * * * * *found * * * * * * * * * */
~MyClass(int a)
value=a;
private:
int value;
;
int main( )
MyClass my(10);
cout<<my.Max(20,30)<<end1;
return 0;
[简答题]使用VC6打开考生文件夹下的工程MyProj11。此工程包含一个源程序文件 MyMain11.cpp。程序中定义了3个类A、B和C,但类C的定义并不完整。
请按要求完成下列操作,将类的定义补充完成:
①类C是基类A和B公有派生来的。请在注释“//* *1* *”之后添加适当的语句。
②完成构造函数C(int k)定义,采用初始化列表的方式使基类A私有成员a初始化为k-2,基类B的私有成员b初始化为k+2,类C的私有成员c初始化为k。请在注释“//* *2* *”之后添加适当的语句。
③完成类Derived的成员函数disp( )的类体外的定义。函数disp( )中要分别显式调用基类A、B的disp( )函数,然后要输出私有成员c的值。请在注释“//* *3* *”之后添加适当的语句。
注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。
源程序文件MyMain11.cpp清单如下;
//MyMain11.cpp
#include <iostream>
using namespace std;
class A
{
private:
int a;
public:
A(int i) { a=i;}
void disp( )
{
cout<<a<<" , "
}
};
class B
{
private:
int b;
public:
B(int j){ b=j;}
disp ( )
{
cout<<b<<", ";
}
};
//* * *1* * *
{
private:
int c;
public:
//* * *2* * *
void disp( );
};
void c::disp( )
{
//* * *3* * *
}
int main ( )
{
C obj(10);
obj.d
[简答题]使用VC6打开考生文件夹下的工程RevProj10。此工程包含一个源程序文件RevMain10.cpp。在该文件中,函数fun的功能是:计算出数组x中的最小值与次最小值,并分别将其与x[0]、x[1]交换。
请改正程序中的错误,使它能得到正确结果。
注意,不要改动主函数,不得删行或增行,也不得更改程序的结构。
源程序文件RevMain10.cpp中的程序清单如下:
//RevMain10.cpp
#include <iostream>
using namespace std;
#define N 30
int fun(int *x, int n);
int main ( )
{
int h[N]={4,7, 6, 5, 1, 7,3, 8,0,2,3};
int i;
for (i=0; i<11; i++)
cout<<h [i] << " " ;
cout <<"/n";
fun(h, 11);
for (i=0; i<n; i++)
cout<<h [i]<<" ";
cout<<’ /n’;
return 0;
}
int fun(int *x, int n)
{
int i,t;
int a1=0, a2=0,min1=32767,min2=32676;
/* * * * *FOUND * * * * */
for(i=1;i<n;i++)
{
if (x [i]<min1)
{
min2=min1;
a2=a1;
min1=x [i];
a1=i;
}
else if (x [i] <min2)
{
min2=x [i];
a2=i;
}
}
/* * * * *FOUND * * * *
[简答题]使用VC6打开考生文件夹下的工程RevProj11。此工程包含一个源程序文件RevMain11.cpp,但在源程序文件中有错误。请改正程序中的错误,使它能得到正确结果。
注意,不得删行或增行,也不得更改程序的结构。
源程序文件RevMainll.cpp中的程序清单如下:
//RevMainll.cpp
#include<iostream>
using namespace std;
class point
private:
const int color;
int x;
int y;
public:
point(int x,int y,int c)
this->x=x;
this->y=y;
color=c;
void show( )
cout<<"x="<<x<<",y="<<y<<",color="<<color<<end1;
;
int main( )
const point p(10,10,100);
p.show( );
return 0;
[简答题]使用VC6打开考生文件夹下的工程RevProj12。此工程包含一个源程序文件RevMain12.cpp,但在该程序中有错误。请改正程序中的错误,使它能得到正确结果。
注意:不得删行或增行,也不得更改程序的结构。
源程序文件RevMain12.cpp中的程序清单如下:
//RevMain12.cpp
#include<iostream>
/* * * * FOUND * * * * */
using namespace std;
class test
private:
const int value;
char dep[10];
public:
/* * * * *FOUND* * * * */
test( )
value=0;
strcpy(dep,"m");
/* * * * *FOUND* * * * */
test(int newvalue)
value=newvalue;
strcpy (dep, "m");
/* * * * *FOUND * * * * */
void show( )
cout<<"value= "<<value<<end1;
;
int main ( )
test t1;
const test t2;
t1.show ( );
t2.show( );
return 0;
[简答题]使用VC6打开考生文件夹下的工程RevProj14。此工程包含一个源程序文件RevMain14.cpp,但该程序中类的定义有错误。请改正程序中的错误,使它能得到正确结果。
注意,不要改动main函数,不得删行或增行,也不得更改程序的结构。
源程序文件RevMain14.cpp中的程序清单如下:
//RevMain14.cpp
#include<iostream>
#include<math>
using namespace std;
class Point
private:
double x;
double y;
public:
Point( )
void Point(double x1,double y1)
x=x1;
y=y1;
void setvalue(double x,double y)
x=x;
y=y;
double getx ( )
return x;
double gety( )
return y;
void print( )
cout<<"x="<<x<<",y= "<<y<<end1;
~Point( )
;
class Line
private:
Point p1;
Point p2;
double width;
public:
Line(double x1,double y1,double x2,double y2,double d)
:p1(x1,y1),p2(x2,y2)
width=d;
~Line( )
void displ