-->
当前位置:首页 > 题库 > 正文内容

Luz4年前 (2021-03-08)题库5598
1-1

动态绑定是在运行时选定调用的成员函数的。

(1分)
作者
何振峰
单位
福州大学
1-1
答案正确
(1 分)

1-2

面向对象程序设计的继承性鼓励程序员重用被实践验证的高质量软件。

(1分)
作者
张德慧
单位
西安邮电大学
1-2
答案正确
(1 分)

1-3

 动态联编在编译时确定操作函数。

(2分)
作者
Gloria
单位
沈阳师范大学
1-3
答案正确
(2 分)

1-4

动态联编调用函数操作是指向对象的指针或对象引用。

(2分)
作者
Gloria
单位
沈阳师范大学
1-4
答案正确
(2 分)

1-5

动态联编是以虚函数为基础的。

(2分)
作者
Gloria
单位
沈阳师范大学
1-5
答案正确
(2 分)

1-6

如果一个类至少有一个纯虚函数,那么就称该类为派生类。

(2分)
作者
Gloria
单位
沈阳师范大学
1-6
答案正确
(2 分)

1-7

派生类的虚函数与基类中对应的虚函数具有相同的参数个数和类型。

(2分)
作者
Gloria
单位
沈阳师范大学
1-7
答案正确
(2 分)

1-8

虚函数既可以在函数说明时定义,也可以在函数实现时定义。

(2分)
作者
Gloria
单位
沈阳师范大学
1-8
答案正确
(2 分)

1-9

实现动态联编必须通过对象名来调用虚函数。

(2分)
作者
Gloria
单位
沈阳师范大学
1-9
答案正确
(2 分)

1-10

动态联编是在运行时确定所调用的函数代码的。

(2分)
作者
Gloria
单位
沈阳师范大学
1-10
答案错误
(0 分)

1-11

含有纯虚函数的类是不可以用来创建对象的,因为它是虚基类。

(2分)
作者
Gloria
单位
沈阳师范大学
1-11
答案正确
(2 分)

1-12

虚函数具有继承性。

(2分)
作者
Gloria
单位
沈阳师范大学
1-12
答案正确
(2 分)

1-13

静态成员函数可以声明为虚函数。

(2分)
作者
Gloria
单位
沈阳师范大学
1-13
答案正确
(2 分)

1-14

虚函数是一个成员函数。

(2分)
作者
Gloria
单位
沈阳师范大学
1-14
答案错误
(0 分)

1-15

如果一个类的函数全部都是纯虚函数,则这个类不能有自己类的实现(包括引用和指针),只能通过派生类继承实现。

(2分)
作者
Gloria
单位
沈阳师范大学
1-15
答案正确
(2 分)
2-1

下面关于类的继承与派生的程序,其输出结果是

#include<iostream>using namespace std;class A {public:
    A(int i) {    x = i;  }    void dispa() {        cout << x << ',';
    }private:    int x;
};class B: public A {public:
    B(int i) : A(i + 10) {
        x = i;
    }    void dispb() {
        dispa();        cout << x << endl;
    }private:    int x;
};int main() {    B b(2);
    b.dispb();    return 0;
}
(4分)
作者
李廷元
单位
民用航空飞行学院
2-1
答案正确
(4 分)

2-2

以下说法正确的是?

(2分)
作者
黄淑伟
单位
沈阳师范大学
2-2
答案正确
(2 分)

2-3

在C++中,要实现动态联编,必须使用( )调用虚函数。

(2分)
作者
Gloria
单位
沈阳师范大学
2-3
答案正确
(2 分)

2-4

下列函数中,不能说明为虚函数的是( )。

(2分)
作者
Gloria
单位
沈阳师范大学
2-4
答案正确
(2 分)

2-5

当一个类的某个函数被说明为virtual时,该函数在该类的所有派生类中( )。

(2分)
作者
Gloria
单位
沈阳师范大学
2-5
答案正确
(2 分)

2-6

( )是一个在基类中说明的虚函数,它在该基类中没有定义,但要求任何派生类都必须定义自己的版本。

(2分)
作者
Gloria
单位
沈阳师范大学
2-6
答案正确
(2 分)

2-7

以下基类中的成员函数,哪个表示纯虚函数( )。

(2分)
作者
Gloria
单位
沈阳师范大学
2-7
答案正确
(2 分)

2-8

类B是类A的公有派生类,类A和类B中都定义了虚函数func( ),p是一个指向类A对象的指针,则p->A::func( )将( )。

(2分)
作者
Gloria
单位
沈阳师范大学
2-8
答案正确
(2 分)

2-9

下面4个选项中,()是用来声明虚函数的。

(2分)
作者
Gloria
单位
沈阳师范大学
2-9
答案正确
(2 分)

2-10

以下成员函数中,()表示虚函数。

(2分)
作者
Gloria
单位
沈阳师范大学
2-10
答案错误
(0 分)

2-11

下面函数原型声明中,()声明了fun为普通虚函数。

(2分)
作者
Gloria
单位
沈阳师范大学
2-11
答案正确
(2 分)

2-12

如果一个类至少有一个纯虚函数,那么就称该类为()。

(2分)
作者
Gloria
单位
沈阳师范大学
2-12
答案正确
(2 分)

2-13

假设A为抽象类,下列声明()是正确的。

(2分)
作者
Gloria
单位
沈阳师范大学
2-13
答案正确
(2 分)

2-14

在派生类中,重载一个虚函数时,要求函数名、参数的个数、参数的类型、参数的顺序和函数的返回值()。

(2分)
作者
Gloria
单位
沈阳师范大学
2-14
答案正确
(2 分)

2-15

不能创建对象的类是()。

(2分)
作者
Gloria
单位
沈阳师范大学
2-15
答案错误
(0 分)

2-16

下列关于抽象类的描述错误的是()。

(2分)
作者
Gloria
单位
沈阳师范大学
2-16
答案正确
(2 分)

2-17

当基类的成员函数被声明为虚函数时,该函数()。

(2分)
作者
Gloria
单位
沈阳师范大学
2-17
答案正确
(2 分)

2-18

下列函数中实现运行时多态的是()。

(2分)
作者
Gloria
单位
沈阳师范大学
2-18
答案正确
(2 分)

2-19

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

(2分)
作者
Gloria
单位
沈阳师范大学
2-19
答案正确
(2 分)
4-1

###写出程序运行的结果

#include <iostream>
using namespace std;
class A
 {
  public:
   A(){cout<<"constructing A "<<endl;}
   ~A(){cout<<"destructing A "<<endl;}
 };

class B  : public A
 {
  public:
   B(){cout<<"constructing B "<<endl;}
   ~B(){cout<<"destructing B "<<endl;}
};

class C  : public B
 {
  public:
   C(){cout<<"constructing C "<<endl;}
   ~C(){cout<<"destructing C "<<endl;}
};
int main()
{ C c1;
  return 0;
}

程序输出为:
第一行:

1分

第二行:
1分

第三行:
1分

第四行:
1分

第五行:
1分

第六行:
1分


作者
范鹏程
单位
内蒙古师范大学
4-1
答案正确
(6 分)

4-2

读下面的程序,写出运行结果。

include <iostream>
using namespace std;
class B {
public:
B(){ cout << "B_Con"<<endl; }
~B() { cout << "B_Des"<<endl; }
};
class C:public B {
public:
C(){ cout << "C_Con"<<endl; }
~C() { cout << "C_Des"<<endl; }
};
int main()
{
C * pc = new C;
delete pc;
return 0;
}。

2分


2分


2分


2分


作者
黄淑伟
单位
沈阳师范大学
4-2
答案正确
(8 分)

4-3

写出下面程序的输出结果?

#include <iostream>
using namespace std;
class Base
{
public:
  int val;
  Base(){ cout << "Base Constructor"<<endl; }
  ~Base() { cout << "Base Destructor"<<endl;}
};
class Base1:virtual public Base{};
class Base2:virtual public Base {};
class Derived:public Base1, Base2 {};
int main() 
{
 Derived d;
 return 0;
}

2分


2分


作者
黄淑伟
单位
沈阳师范大学
4-3
答案正确
(4 分)

4-4

写出下面程序的运行结果。

#include <iostream>
using namespace std;
class A {
public:
  A() { }
  virtual void func(){ cout <<"A::func" <<endl; }
  ~A() { }
  virtual void fund(){ cout <<"A::fund" << endl;}
};
class B:public A {
public:
  B() { func(); }
  void fun() { func(); }
  ~B() { fund(); }
};
class C : public B {
public :
  C() { }
  void func(){ cout <<"C::func"<<endl;}
  ~C() { fund();}
  void fund(){ cout <<"C::fund"<<endl;}
};
int main()
{ C c;
  return 0;
}

2分


2分


2分


作者
黄淑伟
单位
沈阳师范大学
4-4
答案正确
(6 分)

4-5

写出下列程序的运行结果。

#include <iostream>
using namespace std;
class A {
public :
 virtual ~A() {cout<<"DestructA" <<endl; }
};
class B: public A {
public:
 virtual ~B() {cout<<"DestructB" << endl; }
};
class C: public B {
public:
 ~C() { cout << "DestructC" << endl; }
};
int main() {
A * pa = new C;
delete pa; 
A a;
return 0;
}

2分


2分


2分


2分


作者
黄淑伟
单位
沈阳师范大学
4-5
答案正确
(8 分)

4-6

写出下面程序的运行结果。

#include <iostream>
using namespace std;
class A {
public:
A( ) { }
virtual void func()
{ cout << "A::func" << endl; }
virtual void fund( )
{ cout << "A::fund" << endl; }
void fun()
{ cout << "A::fun" << endl;}
};
class B:public A {
public:
B ( ) { func( ) ; }
void fun( ) { func( ) ; }
};
class C : public B {
    public :
C( ) { }
void func( )
{cout << "C::func" << endl; }
void fund()
{ cout << "C::fund" << endl;}
};
int main()
{
A * pa = new B();
pa->fun();
B * pb = new C();
pb->fun();
return 0;
}

2分


2分


2分


2分


作者
黄淑伟
单位
沈阳师范大学
4-6
答案正确
(8 分)

4-7

下面程序的运行结果是:

A::Fun

C::Do

请填空。

#include <iostream>
using namespace std;
class A {
private:
  int nVal;
public:
  void Fun(){ cout << "A::Fun"<<endl;} 
  void Do(){ cout << "A::Do"<<endl;} 
};
class B:public A{ 
public:
  virtual void Do(){ cout << "B::Do"<<endl;}
};
class C:public B {
public:
  void Do(){ cout << "C::Do"<<endl;} 
  void Fun() { cout << "C::Fun"<<endl;} 
};
void Call(2分){ 
p.Fun();
p.Do(); 
}
int main(){
C c;
Call(c); 
return 0;
}

2分


作者
黄淑伟
单位
沈阳师范大学
4-7
答案错误
(0 分)

4-8

程序的运行结果如下:

A::Fun

A::Do

A::Fun

A::Do

请填空。

#include <iostream>
using namespace std;
class A {
private:
  int nVal;
public:
  void Fun(){ cout << "A::Fun"<<endl;} 
  void Do(){ cout << "A::Do"<<endl;} 
};
class B:public A{ 
public:
  virtual void Do(){ cout << "B::Do"<<endl;}
};
class C:public B {
public:
  void Do(){ cout << "C::Do"<<endl;} 
  void Fun() { cout << "C::Fun"<<endl;} 
};
void Call(2分){ 
  p->Fun();
  p->Do(); 
}
int main(){
  Call(new A()); 
  Call(new C()); 
  return 0;
}

2分


作者
黄淑伟
单位
沈阳师范大学
4-8
部分正确
(2 分)

4-9

下面是一个单继承的例子,请写出其运行结果。

class  A 
{
public:
A() {cout<<"A constructor"<<endl;}
~A() {cout<<"A destructor"<<endl;}
};
class B:private  A  
{
public:
B( ){cout<<"B constructor"<<endl;    }
~B( ){cout<<"B destructor"<<endl;}
};

写出主函数执行如下代码后的输出结果。

B b;
cout<<"调用结束。"<<endl;

2分


2分


调用结束。

2分


2分


作者
黄淑伟
单位
沈阳师范大学
4-9
答案正确
(8 分)

4-10

这是一个多继承的例子。

class  A 
{
private:
    int a;    
public:
    A(int i) {a=i;cout<<"A constructor"<<endl;}
};
class B
{
private:
    int b;
public:
    B(int j) {b=j;cout<<"B constructor"<<endl;}
};
class C: public B,public A
{
private:
    int c;

public:
    C(int k):A(k-2),B(k+2) {c=k;cout<<"C constructor"<<endl;}
};

主函数中有如下定义语句,则输出结果是。

C c(10);

2分


2分


2分


作者
黄淑伟
单位
沈阳师范大学
4-10
答案正确
(6 分)

4-11

读程序,写出下面程序的输出结果。

#include <iostream>
using namespace std;
class  A 
{
private:
    int a;

public:
    A(int i) {a=i;}
    void disp(){ cout<<"a="<<a<<endl;}
};

class B
{
private:
    int b;
public:
    B(int j) {b=j;}
    void disp(){ cout<<"b="<<b<<endl;}
};
class C: public B,public A
{
private:
    int c;
public:
    C(int k):A(k-2),B(k+2) {c=k;}
 void disp()
    { A::disp();
      B::disp();
      cout<<"c="<<c<<endl;}
};
int main()
{
    C c(10);
    c.disp();
    return 0;    
 }

2分


2分


2分


作者
黄淑伟
单位
沈阳师范大学
4-11
答案正确
(6 分)

4-12

有下面的一段程序:

#include <iostream>
using namespace std;
class Base{
protected:
 int i,j;
public:
 void set(int a,int b){i=a;j=b;}
 void show(){cout<<i<<","<<j<<"\n";}
};
class Derived:public Base
{
 int k;
public:
 void setk(){k=i*j;}
 void showk(){cout<<k<<"\n";}
};
int main()
{
 Derived ob;
 ob.set(2,3);
 ob.show();
 ob.setk();
 ob.showk();
 return 0;
}

执行后的输出结果是:

2分


2分


如果将protected换成private,编译能通过吗?请回答“yes”或“no”。

2分


如果去掉protected,编译能通过吗?请回答“yes”或“no”。

2分


作者
黄淑伟
单位
沈阳师范大学
4-12
部分正确
(6 分)
5-1

根据所定义的基类,定义派生类,请填空完成程序的功能

#include <iostream>
#include <string>
using namespace std;
class Student                              //声明基类
 {public:                                  //公用部分
   Student(int n,string nam)              //基类构造函数
    {num=n;
     name=nam;
    }
   void display()                           //输出基类数据成员
    {cout<<"num:"<<num<<endl<<"name:"<<name<<endl;}
  protected:                                //保护部分
    int num;
    string name;
};

class Student1: public Student              //用public继承方式声明派生类student
 {public:   2分              //派生类构造函数
    {age=a;                                 //在此处只对派生类新增的数据成员初始化
     addr=ad;
    }
   void show( )
    {cout<<"This student is:"<<endl;
     display();                               //输出num和name
     cout<<"age: "<<age<<endl;
     cout<<"address: "<<addr<<endl<<endl;
    }

   void show_monitor()                        //输出子对象的数据成员
    {cout<<endl<<"Class monitor is:"<<endl;
     monitor.display();                       //调用基类成员函数
    }
   private:                                //派生类的私有数据
    Student monitor;                       //定义子对象(班长)
    int age;
    string addr;                
  };

int main( )
 {Student1 stud1(10010,"Wang-li",10001,"Li-sun",19,"115 Beijing Road,Shanghai");
  stud1.show( );                             //输出第一个学生的数据
  stud1.show_monitor();                       //输出子对象的数据
  return 0;
 }

###程序输出如下

This student is:
num:10010
name:Wang-li
age: 19
address: 115 Beijing Road,Shanghai


Class monitor is:
num:10001
name:Li-sun
作者
范鹏程
单位
内蒙古师范大学
时间限制
400 ms
内存限制
64 MB
5-1
答案正确
(2 分)

5-2

根据所定义的基类,完成派生类的定义。

#include <iostream>
#include<string>
using namespace std;
class Student                             
 {public:                                 
   Student(int n, string nam )           
    {num=n;
     name=nam;
    }
   void display()                         
    {cout<<"num:"<<num<<endl;
     cout<<"name:"<<name<<endl;
    }
  protected:                               
    int num;                               
    string name;
};

class Student1: public Student              
 {public:   2分
    {age=a; }                        
   void show( )                              
    {display();                             
     cout<<"age: "<<age<<endl;
    }
   private:                                 
    int age;                                
  };

class Student2:public Student1              
 {public:    3分
    {score=s;}
   void show_all()                             
    {show();                                    
     cout<<"score:"<<score<<endl;             
    }
  private:
   int score;                               
 };

int main( )
 {Student2 stud(10010,"Li",17,89);
  stud.show_all( );                           
  return 0;
 }
作者
范鹏程
单位
内蒙古师范大学
时间限制
400 ms
内存限制
64 MB
5-2
答案正确
(5 分)


发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。