A.25
B.32
C.40
D.50
第1题
使用VC6打开考生文件夹下的工程proj2。此工程包含一个源程序文件main2.cpp,但该程序运行有问题。请改正main函数中的错误。
源程序文件main2.cpp清单如下:
//main2.cpp
include <iostream>
using namespace std;
class MyClass
{
public:
MyClass(int m)
{
member=m;
}
~MyClass() {}
int GetMember()
{
return member;
}
private:
int member;
};
MyClass MakeObject(int m)
{
MyClass *pMyClass=new MyClass(m);
return *pMyClass;
}
int main ()
{
int x=7;
/************found**************/
MyClass *myObj=MakeObject(x);
/*************found*************/
cout<<"My object has member"<<myObj.GetMember()<<end1;
return 0;
}
第2题
使用VC6打开考生文件夹下的工程test29_1,此工程包含一个源程序文件test29_1.cpp,但该程序运行有问题,请改正程序中的错误,使该程序的输出结果为:
A:no parameters
B:int parameter
A:no parameters
B:int parameter
C:int parameter
源程序文件test29_1.cpp清单如下;
include <iostream.h>
class A
{
/***************** found *****************/
private:
A(){ cout<<"A:no parameters\n";}
A(int a) {cout<<"A: int parameter\n";}
};
class B:public A
{
public:
B(int a){cout<<"B:int Parameter\n";}
};
/***************** found *****************/
class C:public B,public A
{
public:
/***************** found *****************/
C(int a) ::B(a) {cout<<"C: int parameter\n"; )
};
void main ()
{
B b(1);
C c(2);
}
第3题
使用VC6打开考生文件夹下的工程test22_1,此工程包含—个源程序文件test22_1.cpp,但该程序运行有问题,请改正程序中的错误,使程序的输出结果为:
6/15
3/4
9/19
源程序文件test22_1.cpp清单如下:
include<iostream.h>
class Franction
{
int nume;
int deno;
public:
Franction FranAdd(const Franction& x)
{
this->nume+=x.nume;
this->deno+=x.deno;
/****************found*******************/
return this;
}
void InitFranction() {nume=0; deno=l;}
void InitFranction(int n, int d) {nume=n; deno=d;}
void FranOutput() {cout<<nume<<'/'<<deno<<endl;}
};
void main()
{
Franction *a=new Franction;
Franction *b=new Franction;
a->InitFranction(6,15);
b->InitFranction(3,4);
a->FranOutput();
b->FranOutput();
Franction c;
/****************found*******************/
c->InitFranction();
/****************found*******************/
c=a->FranAdd(b);
c. FranOutput();
}
第4题
使用VC6打开考生文件夹下的工程test18_1,此工程包含一个源程序文件(est18_1.cpp,但该程序运行有问题,请改正程序中的错误,使程序的输出结果如下:
Enter x and y:
-4 -5
xoffset=1
yoffset=1
angle=45
radius=1.41421
源程序文件test18_1.cpp 清单如下:
include <iostream.h>
include <math.h>
class point
{
public:
void set(double ix,double iy)
{
x=ix;
y=iy;
}
double xoffset()
{
return x;
}
double yoffset()
{
return y;
}
double angle ()
{
return (180/3.14159)*atan2(y,x);
}
/**************** found *******************/
inline radius ()
{
return sqrt(x*x+y*y);
}
protected:
double x;
double y;
};
void main()
{
point p;
double x,y;
cout<<"Enter x and y:\n";
cin>>x>>y;
p.set(x,y);
/**************** found *******************/
p.x+=5;
p.y+=6;
/**************** found *******************/
cout<<"xoffset="<<p.xoffset()<<end1;
cout<<"yoffset="<<p.yoffset()<<end1;
cout<<"angle="<<p.angle()<<end1;
cout<<"radius="<<p.radius()<<end1;
第5题
使用VC6打开考生文件夹下的工程test40_3。此工程包含一个test40_3.cpp,其中定义了类CVector,但该类的定义并不完整。请按要求完成下列操作,将程序补充完整。
(1)完成类CVector构造函数的定义,把传入的int型参数a和b分别赋值给类的成员变量x和y。请在注释“//**1**”之后添加适当的语句。
(2)完成类CVector的“+”运算符重载函数的定义,使Cvector类的两个对象相加时可以直接使用符号“+”,并且结果仍然为类Cvector的对象,请在注释“//**2**”之后添加适当的语句。
(3)在主函数中添加适当的语句,把类Cvector的对象a和b相加,并且把结果保存在对象c中,最后以“x,y”的形式输出在屏幕上,请在注释“//**3**”之后添加适当的语句。
源程序文件test40_3.cpp清单如下:
include <iostream.h>
class CVector
{
public:
int x,y;
CVector () {};
CVector (int,int);
CVector operator + (CVector);
};
CVector::CVector (int a, int b)
{
//**1**
}
CVector CVector::operator+ (CVector param)
{
//**2**
temp.y = y + param.y;
return (temp);
}
int main ()
{
CVector a (3,1);
CVector b (1,2);
CVector c;
//**3**
return 0;
}
第6题
5
5
源程序文件test28_1.cpp清单如下:
include <iostream.h>
class A{
public:
/***************** found *****************
static int n=1;
A(){n++;};
~A() (n--;};
};
/***************** found *****************
int n=0;
int main() {
A a;
A b[3];
A *c=new A;
c=&a;
/***************** found *****************
cout<<c.n<<end1;
cout<<A::n<<end1;
return 0;
}
第7题
The grade is 3
源程序文件test21_1.cpp清单如下:
include<iostream.h>
class student
{
private:
int grade;
public:
/**************** found*******************/
student(int thegra):(thegra){}
~student(){}
int get_grade(){return grade;}
};
void main()
{
int thegra=3;
/**************** found*******************/
student point=new student(thegra);
/**************** found*******************/
cout<<"The grade is"<<point.get_grade()<<endl;
delete point;
}
第8题
源程序文件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>y?x:y;
else
return y>value?y:value;
}
/* * * * * * * * *found * * * * * * * * * */
~MyClass(int a)
{
value=a;
}
private:
int value;
};
int main()
{
MyClass my(10);
cout<<my.Max(20,30)<<end1;
return 0;
}
第9题
x=20
源程序文件RevMain4.cpp的清单如下:
//RevMain4.cpp
include<iostream>
using namespace std;
class MyClass
{
public:
MyClass(int a)
{
x=a;
}
void setX(int a)
{
x=a;
}
void print()
{
cout<<"x="<<x;
}
private:
int x;
};
int main()
{
const MyClass obj (10);
/ ************found**************/
obj.setX(20);
/ ************found**************/
obj.print();
return 0;
}
第10题
a=3 b=13
a=5 b=13
注意:请勿修改主函数main中的任何内容。
源程序文件rcst4_1.cpp清单如下:
include<iostream.h>
class T
{
public:
/*********found***+******/
T(int x){a=x; b+=x;)
/+********found**********/
void display(T c)
{ cout<<"a="<<c.a<<"\t"<<"b="<<c.b<<endl;)
private:
const int a;
static int b;
};
/**********found*********/
int b=5;
void main()
{
T A(3),B(5);
T::display(A);
T::display(B);
}
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!