A.8,6
B.8,3
C.6,4
D.7,4
第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打开考生文件夹下的工程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;
第4题
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;
}
第5题
使用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();
}
第6题
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;
}
第7题
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;
}
第8题
7
源程序文件test41_1.cpp清单如下:
include<iostream.h>
class myclass
{
int a, b;
public:
/***************** found *****************/
int sum(myclass x);
void set_ab(int i, int j);
}:
/**************** found ****************/
void myclass:set_ab(int i, int j)
{
a=i;
b=j;
}
int sum (myclass x)
{
/***************** found ***************/
x.a+x.b;
}
void main ()
{
myclass n;
n.set_ab (3, 4);
cout <<sum(n)<<endl;
}
第9题
Previous=9,Next=11
源程序文件test30_1.cpp清单如下:
include <iostream.h>
/***************** found *****************/
void prevnext (int,int &,int&);
int main ()
{
int x=10,y,z;
prevnext (x,y,z);
cout << "Previous=" << y << ", Next=" << z<<end1;
return 0;
}
/***************** found *****************/
void prevnext (int x, int prev, int next)
{
/***************** found *****************/
prev=x--;
next=++x;
}
第10题
ch1=7 ch2=9
源程序文件test11_1.cpp清单如下:
include<iostream.h>
class Sample
{
/**************** found ***************/
char ch1,ch2
public:
/************** found ***************/
friend void set(Sample s, char c1,char c2)
{
s.ch1=c1;
s.ch2=c2;
}
void print() {cout<<"ch1="<<" ch2="<<ch2<<end1;}
};
void main()
{
Sample obj;
/************* found ****************/
obj.set(obj,'7','9');
obj.print();
}
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!