全部知识点

第6121题

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

 #include<iostream> using namespace std; 
class A { 
public: A(int i): r1(i) {} 
void print() {cout<<"E"<<r1*r1<<":";} 
void print() const {cout<<"C"<<r1*r1<<":";} 
private: int r1; }; i
nt main(){ A a1(2); 
const A a2(4); a1.print(); a2.print(); return 0; }
第6122题

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

#include<iostream> using namespace std; 
class A { public: A(int i=0):r1(i){} 
void print(){cout<<"E"<<r1*r1<<":";} 
void print() const {cout<<"C"<<r1*r1<<":";} 
void print(int x){cout<<"P"<<r1*r1*r1<<":";} 
private: int r1; }; 
nt main(){ A a1; const A a2(4); a1.print(2); a2.print(); return 0; }
第6123题

某类中有一个无参且无返回值的常成员函数Show,则正确的Show函数原型是()。

第6124题

已知类IMS中两个成员函数的声明为 void listen()const; 与 void speak(); ,另有两个对象的定义为 IMS obj1; 与 const IMS obj2; ,则下列语句中,产生编译错误的是()。

第6125题

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

第6126题

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

 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行 };
第6127题

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

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; } //④ };
第6128题

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

 #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; }
第6129题

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

 #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; }
第6130题

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

  #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; }
第6131题

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

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

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

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

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

  #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; }
第6134题

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

第6135题

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

 #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;}
第6136题

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

 #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; }
第6137题

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

第6138题

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

#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; }
第6139题

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

第6140题

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

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