C++试卷

第401题

已知函数print()没有返回值,如果在类中将其声明为常成员函数,正确的是()。

第402题

有如下类定义,编译时没有错误的行是()。

 class Test{ char a; const char b; public: Test(char c){a=c;b=c;}   
 //第1行 void f(char a)const{this->a=a;}//第2行 void g(char b){this->b=b;}     //第3行 char h() const{return a;}      //第4行 };
第403题

有如下定义,其中的四个函数定义中正确的是()。

class AA{
 int a; public:
 int getRef()const{
 return &a; } //① int getValue()const{ return a; } //
② void set(int n)const{ a=n; }  
  //③ friend void show(AA aa)const{ cout<<a; } //④ };
第404题

有如下程序,运行时输出的结果是()。

 #include<iostream> using namespace std; class Sample{ 
friend long fun(Sample s); 
public: Sample(long a):x(a){}
 private: long x; }; long fun(Sample s){ if(s.x<2) return 1
; return s.x*fun(Sample(s.x-1)); } 
int main(){ int sum=0; 
for(int i=0;i<6;i++)sum+=fun(Sample(i));
 cout<<sum; return 0; }
第405题

 有如下程序,下列叙述中正确的是()。

 #include<iostream>
 #include<cmath> 
using std::cout; class Point{
 public: friend double distance(const Point &p); 
Point(int xx=0,int yy=0):x(xx),y(yy){} private: int x,y; }; 
double distance(const Point &p){ return sqrt(p.x*p.x+p.y*p.y); } 
int main(){ Point p1(3,4); cout<<distance(p1); return 0; }
第406题

有如下程序,下列关于程序的描述中,正确的是()。

  #include<iostream> using namespace std; class Boat; class Car{ 
public: Car(int i):weight(i){} 
friend int Total(const Car &c,const Boat &b); 
private: int weight; }; class Boat{ public: Boat(int i):
weight(i){} friend int Total(const Car &c,const Boat &b); 
private: int weight; }; int Total(const Car &c,const Boat &b)
{ return c.weight+b.weight; } i
nt main(){ Car c(10); Boat b(8); cout<<"The total weight is "<<Total(c,b)<<endl; return 0; }
第407题

已知类MyClass声明如下,在下列数组定义中正确的是()。

 class MyClass {
 public: MyClass(int d) { data = d;} ~MyClass() {} 
private: int data; };
第408题

已知类MyClass的定义如下,下列对MyClass类对象数组的定义和初始化语句中,正确的是()。

  class MyClass {
 int n; 
public: MyClass(int k): n(k) {}
 int getValue()const { return n; } };
第409题

分析下面程序,该程序的运行结果是()。

  #include<iostream> class TestClass{
public: static int m; TestClass() { m++; } TestClass(int n) { m=n; } 
static void test() { m++; } }; int TestClass::m=0; 
void main() { TestClass A; TestClass B(3); A.test(); 
TestClass::test(); cout<<"m="<<B.m<<endl; }
第410题

 下列说法中错误的是()。

第411题

 有如下程序,执行后的输出结果是()。

 #include<iostream> using namespace std; 
class TestClass{ public: ~TestClass (){cout<<"BASE:";} }; 
class TestClass1:
public TestClass { 
public: ~TestClass1 (){cout<<"DERIVED:";} }
; int main(){TestClass1 x;return 0;}
第412题

有以下定义和程序,以下不合语法的调用语句是()。

 #include<iostream.h> class TestClass{ public: 
void show1() { cout<<"TestClass1"<<endl; } }; 
class TestClass2:TestClass1{
 public: void show2() {
 cout<<"TestClass2"<<endl; } }; 
class TestClass3:protected TestClass2{ 
public: void show3() { 
cout<<"TestClass3"<<endl; } }; 
void main() { TestClass1 obj1; TestClass2 obj2; TestClass3 obj3; }
第413题

在下面的4个关键字中用来说明虚函数的是()。

第414题

有如下程序,执行后的输出结果是()。

#include<iostream> using namespace std; class AA{ 
int n; 
public: AA(int k):n(k){} 
int get(){return n;} 
int get()const{return n+1;} }; i
nt main(){ AA a(5); const AA b(6); cout<<a.get()<<b.get(); return 0; }
第415题

关于函数重载,下列叙述中错误的是()。

第416题

有如下类声明,下面关于setValue成员函数的实现中,正确的是()。

class TestClass{ 
int n; 
public: TestClass (
int i=0):n(i){} 
void setValue (int n0); };
第417题

下面关于常成员函数的说法中正确的是()。

第418题

下面关于虚函数的描述中,正确的是()。

第419题

 在类中说明的成员可以使用关键字的是()。

第420题

下列不能作为类的成员的是()。