青青 发表于 2023-3-4 10:22:39

面向对象程序设计23春北理工模拟三

[试题分类]:面向对象程序设计
1.        在C++中,实现封装性需借助于
A. 枚举       
B. 类
C. 数组
D. 函数
答案:B
题型:单选题
知识点:1.1.2面向对象的有关概念
难度:1
2.        下列选项中能够作为C++标识符的是
A. points
B. 2b
C. const       
D. -256
答案:
题型:单选题
知识点:1.3 C++语言的词法及词法规则
难度:1
3.        下列选项中,对常类型定义错误的是
A. MyClass const obj(1,2);
B. char const *ptr="hello";
C. const int &ref;
D. void fun() const \{ \}
答案:C
题型:单选题
知识点:6.3 常类型
难度:2
4.        为了解决程序中函数调用的效率问题,可以将一些函数体代码不是很大,但被频繁调用的函数定义为
A. 重载函数
B. 内联函数
C. 递归函数
D. 友元函数
答案:B
题型:单选题
知识点:4.4 内联函数
难度:1
5.        已知函数fun的原型是“void fun(int *x, int &y);”,变量v1、v2的定义是“int v1, v2; ”,下列选项中,对函数fun调用正确的是
A. fun(v1,&v2);
B. fun(v1,v2);
C. fun(&v1,v2);
D. fun(&v1,&v2);
答案:
题型:单选题
知识点:4.2 函数的调用
难度:2
6.        已知函数原型为“int test(int,int,int);”,则下列重载形式中错误的是
A. char test(int,int);
B. double test(int,int,double);
C. int test(int,char*);
D. float test(int,int,int) ;
答案:D
题型:单选题
知识点:4.5 函数重载
难度:2
7.        在C++中,编译系统自动为一个类生成默认构造函数的条件是
A. 该类没有定义任何有参构造函数
B. 该类没有定义任何无参构造函数
C. 该类没有定义任何构造函数
D. 该类没有定义任何成员函数
答案:C
题型:单选题
知识点:5.3.3 复制构造函数
难度:1
8.        {
        下列划线处应填入的内容是
        class MyClass\{
        public:
                MyClass() \{ count++; \}
        private:
                        count;
        \};
        int MyClass::count=10;
        }
A. int
B. static int
C. static       
D. 无
答案:
题型:单选题
知识点:5.5 静态成员
难度:2
9.        {
        下列函数中,具有隐含的this指针的是
        class MyClass\{
        public:
                int fun1();                                //
                friend int fun3();                        //
                static void fun2();                //
                static int count;                        //
        \};
        }
A. 
B. 
C. 
D. 
答案:A
题型:单选题
知识点:6.1.3 this指针
难度:2
10.        下列关于new运算符的叙述中,错误的是
A. new运算符用于申请动态存储空间
B. new运算符返回指向操作数类型变量的指针
C. new运算符创建数组时要为数组元素指定初值
D. new运算符创建类对象时要调用类构造函数
答案:C
题型:单选题
知识点:6.4.2 堆对象
难度:2
11.        当一个派生类继承自一个基类时,基类中的所有公有成员都成为派生类的
A. 可访问成员
B. 公有成员
C. 私有成员
D. 保护成员
答案:A
题型:单选题
知识点:7.1.3 基类成员在派生类中的访问权限
难度:2
12.        下列关于继承和派生的叙述中,错误的是
A. 派生类要向基类的构造函数传递参数
B. 多继承时可能会产生二义性
C. 派生类可以访问基类的所有数据成员,也能调用基类的所有成员函数
D. 一个基类可以有多个派生类,一个派生类可以有多个基类
答案:C
题型:单选题
知识点:7 继承性和派生类
难度:2
13.        下列运算符中,可以重载的是
A. ?:
B. ::       
C. !=
D. .*
答案:
题型:单选题
知识点:8.2 运算符重载
难度:1
14.        抽象类至少包含一个
A. 友元函数
B. 静态函数
C. 对象成员
D. 纯虚函数
答案:D
题型:单选题
知识点:8.5 纯虚函数与抽象类
难度:1
15.        在C++中,cin 是一个
A. 类
B. 对象
C. 模板       
D. 函数
答案:B
题型:单选题
知识点:9.2 键盘输入
难度:1
16.        若有函数声明“void fun(int x);”,则函数fun是按    方式传递参数的。
答案:传值
题型:填空题
知识点:4.2 函数的调用
难度:1
17.        在C++中,   是指同一个函数名可以对应多个函数的实现。
答案:函数重载
题型:填空题
知识点:4.5 函数重载
难度:1
18.        {
        请在划线处写出MyClass类的析构函数的声明。
        class MyClass \{
        public:
        \};
}
答案:~MyClass();
题型:填空题
知识点:5.3.1 构造函数和析构函数
难度:1
19.       C++中的      函数可以取代C中带参数的宏。
答案:内联函数
题型:填空题
知识点:4.4 内联函数
难度:1
20.        {
下列程序运行后输出10,请将划线处的语句补充完整。
        #include<iostream>
        using namespace std;
        class MyClass \{
        public:
                MyClass(int x) :    \{ \}
                void Print() \{ cout<<val<<endl; \}
        private :
                int val;
        \};
        int main() \{
                MyClass obj(10);
                obj.Print();
                return 0;
        \}
}
答案:val(x)
题型:填空题
知识点:5.3 对象的初始化
难度:2
21.        {
下列程序运行后的输出结果是    。
        #include<iostream>
        using namespace std;
        class MyClass \{
        public:
                MyClass(int x):val(x) \{ cout<<val; \}
                MyClass(const MyClass& p) \{ cout<<p.val; \}
                ~MyClass() \{ cout<<0; \}
        private:
                int val;
        \};
        int main() \{
                MyClass obj1(1),obj2(obj1);
                return 0;
        \}
}
答案:1100
题型:填空题
知识点:5.3 对象的初始化
难度:2
22.        有两个类M和C,其中类C定义如下:class C \{ public: M m; \};。若释放类C的对象object,则对象m和对象object中先被释放的是对象    。
答案:
题型:填空题
知识点:6.4.1 子对象
难度:2
23.        如果类Alpha继承自类Beta,则类Alpha称为       类。
答案:派生类或子类
题型:填空题
知识点:7.1 基类和派生类
难度:1
24.        设置虚基类的目的是为了解决多继承产生的    问题。
答案:二义性
题型:填空题
知识点:7.3.3 多继承的二义性问题
难度:1
25.        {
下列语句序列重载了复数的加法操作,请将其补充完整。
class Complex \{
public:
        Complex(double r=0.0,double i=0.0):real(r),imag(i) \{\}
        friend Complex operator +(Complex&, Complex&);
private:
        double real,imag;
\};
      operator +(Complex &c1, Complex &c2) \{       
return Complex(c1.real+c2.real,c1.imag+c2.imag);
\}
        }
答案:Complex
题型:填空题
知识点:8.2 运算符重载
难度:2
26.        改错题
{
下列程序中有三个错误,请指出错误所在行号并改正错误(注意不要修改主函数),使程序的输出结果为:
Constructor
False
Destructor
源文件清单如下:
Line1:                #include <iostream>
        Line2:                using namespace std;
Line3:                class MyClass \{
Line4:                public:
Line5:                        MyClass(int x):flag(x) \{ cout<<"Constructor"<<endl; \}
Line6:                        void ~MyClass() \{ cout<<"Destructor"<<endl; \}
Line7:                        void Judge();
Line8:                private:
Line9:                        int flag;
Line10:                \};
Line11:                void Judge() \{
Line12:                        switch(flag) \{
Line13:                                case 0:
Line14:                                        cout<<"False"<<endl;                break;
Line15:                                default:
Line16:                                        cout<<"True"<<endl;
Line17:                        \}
Line18:                \}
Line19:                int main() \{
Line20:                        MyClass obj;
Line21:                        obj.Judge();
Line22:                        return 0;
Line23:                \}
   }
答案:Line5:        MyClass(int x=0):flag(x) { }
题型:改错题
知识点:5.3 对象的初始化
5.4.3 设置参数的默认值
难度:2
答案:Line6: ~MyClass() { cout<<"Destructor"<<endl; }
题型:改错题
知识点:5.3 对象的初始化
难度:1
答案:Line11:void MyClass::Judge() {
题型:改错题
知识点:5.1 类的定义
难度:1
27.        {
请写出下列程序的输出结果。                                                                                       
#include <iostream>
using namespace std;
class A \{
public:
        A(int i):r1(i)                \{ cout<<r1<<endl; \}
        ~A()                    \{ cout<<'~'<<r1<<endl; \}
        void print()                         \{cout<<"Empty:"<<r1<<endl;\}
        void print() const         \{cout<<"Const:"<<r1<<endl;\}
        void print(int x)           \{cout<<"Param:"<<x*x<<endl;\}
private:
        int r1;
\};
int main() \{
        A a1(1);
        const A a2(2);
        a1.print();
        a2.print();
        return 0;
\}
   }
答案:
1
2
Empty:1
Const:2
~2
~1
题型:阅读程序题
知识点:5.3 对象的初始化
5.4 成员函数的特性
6.3.3 常成员函数
难度:2
28.        {
   请写出下列程序的输出结果。                                                                                       
#include <iostream>
#include <string>
using namespace std;
class Father\{
public:
    Father(string s):name(s)        \{ cout<<name<<endl; \}
    ~Father()                                 \{ cout<<"F-"<<name<<endl; \}
private:
    string name;
\};
class Mother\{
public:
    Mother(string s):name(s)        \{ cout<<name<<endl; \}
    ~Mother()                                \{ cout<<"M-"<<name<<endl; \}
private:
    string name;
\};
class Child:public Mother,public Father\{
public:
Child(string s1,string s2,string s3,int a):Father(s1),Mother(s2),name(s3),age(a)
\{ cout<<name<<age<<endl; \}
    ~Child()                                         \{ cout<<"C-"<<name<<endl; \}
private:
    string name;
    int age;
\};
int main()\{
    Child son("Mike","Ice","Bob",20);
    return 0;
\}
}
答案:
Ice
Mike
Bob20
C-Bob
F-Mike
M-Ice
题型:阅读程序题
知识点:7.3.2 多继承的构造函数和析构函数,
难度:2
29.        {
请写出下列程序的输出结果。                                                                                       
#include <iostream>
using namespace std;
class Base \{
public:
        virtual void f()                        \{ cout<<"fB"<<endl; \}
        virtual void g()                        \{ cout<<"gB"<<endl; \}
\};
class Derived : public Base \{
public:
        virtual void f()                        \{ cout<<"fD"<<endl; \}
        virtual void g()                        \{ cout<<"gD"<<endl; \}
\};
int main() \{
        Base b,*p=new Derived;
        cout<<"Section 1: ";                b.f();
        cout<<"Section 2: ";                p->g();
        delete p;
        return 0;
\}
}
答案:
Section 1: fB
Section 2: gD
题型:阅读程序题
知识点:8.3.2 动态联编
8.4 虚函数
难度:2

页: [1]
查看完整版本: 面向对象程序设计23春北理工模拟三