void print()const;
const void print();
void const print();
void print(const);
第1题:
有以下类定义 classPoint{ public: Point(int x=0,int y=0){_x=x;_y=y;} void Move (int xOff,int yOff {_x +=xOff;_y+yOff} void Print() const {cout<<'('<<_x<<','<<_y<<')'<<endl;} private: int_x_y; }; 下列语句中会发生编译错误的是
A.Pointpt;pt;Print();
B.const Point pt;pt.Print();
C.Pointpt;pt.Move(1,2);
D.const Point pt;pt.Move(1,2);
第2题:
有如下程序:
include<iostream>
using namespace std;
class Monitor{
public:
Monitor(char t):type(t){ }
void Print( )const
{cout<<"The type of monitor is"<<type< private:
char type;
};
class Computer{
public:
Computer(int i,char C) :______{}
void Print( )const
{eout<<"The computer is"<<id<<endl;mort.Print( );}
private:
int id;
Monitor mon;
};
int main( ){
const Computer myComputer(101,'B');
myComputer.Print( );
return 0;
}
请将程序补充完整,使程序在运行时输出:
The computer is 101
The type of monitor is B
第3题:
Avoid print( ) const;
Bconst void print( );
Cvoid print( );
Dvoid print(const);
第4题:
( 29 )有如下程序
#include <iostream>
using namespace std;
class A{
public:
A(int i=0):r1(i) { }
void print() {cout<< ' E ’ <<r1<< ' - ' ;}
void print() const {cout<< ' C ' <<r1*r1<< ' - ' ;}
void print(int x) {cout << ' P ' <<r1*r1*r1<< ' - ' ;}
private:
int r1;
};
int main() {
A a1;
const A a2(4);
a1.print(2);
a1.print();
return 0;
}
运行时的输出结果是
A ) P8-E4
B ) P8-C16-
C ) P0-E4-
D ) P0-C16-
第5题:
( 11 )有如下程序:
#include<iostream>
using namespace std;
class Monitor{
public:
Monitor ( char t ) : type ( t ) {}
void print ( ) const
{cout<<"The type of monitor is"<<type<<endl;}
private:
char type;
};
class Computer{
public:
Computer ( int i , char c ) : 【 11 】 {}
void Print () const
{cout<<"The computer is"<<id<<endl;mon.Print ( ) ; }
private:
int id;
Monitor mon;
};
const Computer myComputer ( 101,'B' ) ;
myComputer .Print ( ) ;
return 0;
}
请将程序补充完整,使程序在运行时输出:
The computer is 101
'The type of monitor i.s 8
第6题:
( 15 )下列程序的输出结果是 【 15 】 。
#include
using namespace std;
class A {
int a;
public:
A():a(9){}
virtual void print() const { cout<<a;};
};
class B : public A {
char b;
public:
B( ){b='S';}
void print( ) const { cout <<b;}
};
void show(A &x){ x.print();}
int main()
{ A d1,*p;
B d2;
p=&d2;
d1.print();
d2.print();
p->print();
show(d1);
show(d2);
return 0;}
第7题:
( 28 )有如下程序:
#include<iostream>
using namespace std;
class MyClass{
public:
MyClass(int x):val(x) {}
void Print() const {cout<<"const:val="<<val<<'\t';}
void Print(){cout<<"val="<<val<<'t';}
private:
int val;
};
int main(){
const MyClass obj1(10);
MyClass obj2(20);
obj1.Print();
obj2.Print();
return 0;
}
程序的输出结果是
A ) val=10 const:val=20
B ) const:val=10 const:val=20
C ) const:val=10 val=20
D ) val=10 val=20
第8题:
下列程序的输出结果是 ( )
#include
using namespace std;
class A{
int a
public:
A():a(9){}
virtual void print() const {cout<};
class B:public A{
char b;
public:
B(){b= ‘S’;}
void print()const{cout<};
void show(Aa&X){X,print()}
int main()
{ Ad1;*p;
Bd2;
p=&d2;
d1,print();
d2,print();
p->print();
show(d1);
show(d2);
return 0;}
s--
第9题:
( 28 )有如下程序
#include <iostream>
using namespace std;
class A {
public:
A(int i):rl(i) {}
void print() {cout<<'e'<<r1<<'-';}
void print() const {cout<<'C'<<rl*rl<<'-';}
private:
int rl;
};
int main(){
A al(2); const A a2(4);
Al.print();a2.print();
Return 0;
}
运行时的输出结果是
A )运行时出错
B ) E2-C16-
C ) C4-C16-
D ) E2-E4-
第10题:
有如下程序: #include<iostream> using namespace std; class MyClass{ public: MyClass(int x):val(x){} void Print()const{cout<<“const:val=”<<<val<<‘\’;} void Print(){cout<<“val=”<<val<<‘t’;} private: int va1; }; int main(){ cons
A.val=10 const:val=20
B.const:val=10 const:val=20
C.const:val=10 val=20
D.val=10 val=20