zoukankan      html  css  js  c++  java
  • 试卷

    面向对象程序设计试题A

     

    一、选择题(每小题1分,共10分)

    1.下列关于内联函数的描述中,错误的是( )。C

    A. 内联函数主要解决程序的运行效率问题;

    B. 内联函数的定义必须出现在内联函数第一次被调用之前;

    C. 内联函数中可以包括各种语句;

    D. 对内联函数不可以进行异常接口声明;

    2.下列( )不是构造函数的特征。D

    A. 构造函数的函数名与类名相同

    B. 构造函数可以重载

    C. 构造函数可以设置缺省参数

    D. 构造函数必须指定类型说明

    3.关于成员函数特征的下列描述中,( )是错误的。A

      A. 成员函数一定是内联函数

      B. 成员函数可以重载

      C. 成员函数可以设置缺省参数值

      D. 成员函数可以是静态的

    4.下列静态数据成员的特性中,( )是错误的。C

    A. 说明静态数据成员时前边要加修饰符static

    B. 静态数据成员要在类体外进行初始化

    C. 静态数据成员不允许对象访问

    D. 引用静态数据成员时,要在其名称前加<类名>和作用域运算符

    5.友元的作用是( )。A

    A. 提高程序的运用效率

    B. 加强类的封装性

    C. 实现数据的隐藏性

    D. 增加成员函数的种类

    6.调用重载函数时,根据( )来选择具体的函数。B

    A. 函数名                        B. 参数的个数和类型

         C. 参数名及参数个数             D. 函数的返回值类型

    7.关于delete运算符的下列描述中,( )是错误的。C

       A. 必须用于new返回的指针

    B. 使用它删除对象时要调用析构函数

    C. 对一个指针可以使用多次该运算符

    D. 指针名前只有一对方括号符号,不管所删除数组的维数

    8.设置虚基类的目的是( )。B

    A. 简化程序       B. 消除二义性;

    C. 提高运行效率    D. 减少目标代码

    9.下列描述中,正确的是( )。C

      A. 虚函数是一个static 类型的成员函数

    B. 虚函数是一个非成员函数

    C. 抽象类是指具有纯虚函数的类

    D. 抽象类可以创建对象

    10.通过( )调用虚函数时,采用动态联编技术。A

    A. 对象指针      B. 对象名         C. 成员名限定  D. 派生类名

    二、填空题(每空1分,共10分)

    1.对象是                          的封装体。状态、操作

    2.定义重载函数时,要从                          上进行区分。参数个数、参数类型

    3.对虚函数使用基类类型的指针或引用调用,系统使用       联编;使用对象调用时,系统使用       联编。动态、静态

    4.带有             的类称为抽象类,它只能作为             来使用。纯虚函数、基类

    5.给定某个定义了默认(缺省)构造函数的类A,则语句A* p = new A[5],将执行        次构造函数,为了释放p所占用的空间,正确的写法应该是          。5、delete [] p;

    三、判断题(每小题1分,共10分)

    正确填T,错误填F

    1.返回值类型、参数个数和类型都相同的函数也可以重载。( )F

    2.类中缺省的访问权限是私有(private)的。( )T

    3.类的私有成员只能被类中的成员函数访问,任何类以外的函数对它们的访问都是非法的。( )F

    4.多继承情况下,派生类的构造函数的执行顺序取决于成员初始化列表中的顺序。( )F

    5.在公有继承中,基类中的公有成员和私有成员在派生类中都是可见的。( )F

    6.构造函数可以声明为虚函数。( )F

    7.C++中有些异常不能被捕捉。( )F

    8.虚拟继承需要在继承的关键字前加virtual关键字。( )T

    9.类的静态成员在创建对象之前就已经存在。( )T

    10.对象析构的顺序与对象创建的顺序相同。( )F

    四、简答题(每小题5分,共20分)

    1.面向对象技术的主要特征是什么?

    2.函数重载和虚函数有什么区别?

    3.多重继承时,构造函数与析构函数的执行顺序各是什么样的?

    4.什么是纯虚函数?什么是抽象类?抽象类有什么特点和用途?

    五、分析题(每小题10分,共30分)

    1.分析以下程序运行结果。

    #include <iostream>

    #include <string>

    using namespace std;

    void f( int a)

    {

         a++;

    }

    void f( int *b)

    {

         *b*=2;

    }

     

    void f( double &v)

    {

         v*=3;

    }

     void f( string &s)

    {

         s = "Changed";

    }

    void f(int* array,int length)

    {

        

         for (int i = 0; i <length ; i++)

         {

             array[i] *= 2;

         }

    }

    void main()

    {

        int m=2,n = 5; 

         double x=1.2;

         string str = "Original";

        int a [4]= { 1, 2, 3, 4 };  

        f(m);

         cout<<m<<endl;

         f( &n);

         cout<<n<<endl;

         f(x);

         cout<<x<<endl;

         f( str);

         cout<< str<<endl;

         f(a,2);

         for (int i = 0; i <4 ; i++)

         {

             cout<<a[i]<<"\t";

         }

    }

    运行结果:

    2

    10

    3.6

    Changed

    2       4       3       4

     

    2.分析以下程序运行结果。

    #include <iostream>

    using namespace std;

    class A

    {

    public:

         static int count;

         A() 

         {

             count++;

             cout<<"class A construct "<<endl;

         }

    };

    int A::count=0;

    class B:public A

    {

    public:

         B():member(),A(){cout<<"class B construct"<<endl;}

    private:

         A member;

    };

     

    void main()

    {

         A a;

         B b;

        cout<<"object count="<<B::count<<endl;

    }

    运行结果:

    class A construct

    class A construct

    class A construct

    class B construct

    object count=3

    3.分析以下程序运行结果。

    #include <iostream>

    using namespace std;

    class A

    {

         public:

             A(){}

             virtual ~A(){}

             virtual void fun1()

             {

                  cout<<"fun1 of class A "<<endl;

             }

              void fun2()

             {

                  cout<<"fun2 of class A "<<endl;

             }

    };

    class B : public A

    {

         public:

             B(){}

             ~B(){}

             void fun1()

             {   

                  cout<<"fun1 of class B  "<<endl;

             }

             void fun2()

             {

                  cout<<"fun2 of class B "<<endl;

             }

    };

     void main()

    {

         A b=B();;

         b.fun1();

         b.fun2();

         A *pA=new A;

         pA->fun1();

         delete pA;

         pA=new B;

         pA->fun1();

         pA->fun2();

         delete pA;

    }

    运行结果:

    fun1 of class A

    fun2 of class A

    fun1 of class A

    fun1 of class B

    fun2 of class A

    六、编程题(20分)

    编写一个表示形状的抽象类Shape,Area()为求图形面积的函数。从Shape类派生矩形类(Rectangle)、圆类(Circle),实现具体的求面积函数。在main()函数中验证多态性。

    #include <iostream>

    using namespace std;

    class Shape

    {

    public:

             Shape(){cout<<"Construct Shape"<<endl;}

             virtual ~Shape(){cout<<"Destruct Shape"<<endl;}

             virtual double area()=0;

    };

    class Rectangle:public Shape

    {

    public:

             Rectangle(double a,double b)

             {

                       width=a;

                       height=b;

                       {cout<<"Construct Rectangle"<<endl;}

             }

             ~Rectangle(){cout<<"Destruct Rectangle"<<endl;}

             double area()

             {

                       return width*height;

             }

    private:

             double width,height;

     

    };

    class Circle:public Shape

    {

    public:

             Circle(double r)

             {

                       radius=r;

                       {cout<<"Construct Circle"<<endl;}

             }

             ~Circle(){cout<<"Destruct Circle"<<endl;}

             double area()

             {

                       return 3.14*radius*radius;

             }

    private:

             double radius;

    };

     void main()

    {

             Shape *s;

             s=new Rectangle(3,5);

             cout<<s->area()<<endl;

             delete s;

             s=new Circle(10);

             cout<<s->area()<<endl;

             delete s;

    }

  • 相关阅读:
    Python爬取微博热搜榜,将数据存入数据库
    Python爬取网站文章数据并存到数据库
    在自己的框架系统中使用tp类
    conda环境下pip install 无法安装到指定conda环境中(conda环境的默认pip安装位置)
    jupyter notebook 加入conda虚拟环境(指定conda虚拟环境)
    本地打包好的项目如何运行在docker中
    测试
    SQL Server创建dblink跨库查询
    深入浅析BIO、NIO、AIO
    JavaWeb_html_js_css_javaweb
  • 原文地址:https://www.cnblogs.com/herizai/p/3101390.html
Copyright © 2011-2022 走看看