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

面向对象程序设计23春模拟题二

[试题分类]:面向对象程序设计
1.        下列选项中,不属于C++程序开发步骤的是
A. 编译
B. 编辑
C. 链接
D. 解释
答案:D
题型:单选题
知识点:1.4C++程序的编辑、编译和运行
难度:1
2.        下列选项中,能够作为C++标识符的是
A. B&B
B. friend
C. iphone8
D. Good Luck
答案:
题型:单选题
知识点:1.3 C++语言的词法及词法规则
难度:1
3.        下列关于引用的叙述中,错误的是
A. 创建引用时必须为其分配存储空间
B. 创建引用时必须立即对其进行初始化
C. 对引用的操作就是对其代表的数据对象的操作
D. 引用必须与一块合法的存储空间相关联
答案:A
题型:单选题
知识点:2.5.4 引用
难度:2
4.        设变量x和y为整型变量,若有函数调用为“fun(x,&y)”,则下列选项中,能够作为函数fun原型声明的是
A. void fun(int &a,int &b);
B. void fun(int &a,int *b);
C. void fun(int *a,int &b);
D. void fun(int *a,int *b);
答案:B
题型:单选题
知识点:4.2 函数的调用
难度:2
5.        下列选项中,不是重载函数调用时的选择依据的是
A. 参数个数
B. 参数类型
C. 函数名称
D. 函数返回类型
答案:D
题型:单选题
知识点:4.5 函数重载
难度:1
6.        {
若有如下Fruit类定义:
      class Fruit\{
            char name;
      public:
            void Print();
      private:
            double price;
      \};
则下列描述中,正确的是
}
A. 类中有1个公有数据成员
B. 类中有1个私有数据成员
C. 类中有2个私有数据成员
D. 数据成员name的访问权限未知
答案:C
题型:单选题
知识点:5.1 类的定义
难度:1
7.        若MyClass为一个类,执行“MyClass a,*p;”时会自动调用该类构造函数的次数是
A. 2
B. 4
C. 5
D. 9
答案:
题型:单选题
知识点:5.3.1 构造函数与析构函数
难度:3
8.        下列关于静态成员的叙述中,正确的是
A. 静态成员不属于对象,是类的共享成员
B. 静态数据成员要由构造函数初始化
C. 静态成员函数只能通过类激活
D. 非静态成员函数不能操作静态数据成员
答案:A
题型:单选题
知识点:5.5 静态成员
难度:2
9.        下列关于友元的叙述中,错误的是
A. 友元破坏了类的封装性
B. 友元提高了程序的运行效率
C. 友元可以在类外声明和定义
D. 友元能够访问类中的私有成员
答案:C
题型:单选题
知识点:5.6 友元
难度:1
10.        {
        下列函数中,具有隐含的this指针的是
        void fun1();                                        //①
        class MyClass\{
        public:
                friend void fun2();                //②
                static int fun3();                        //③
                int fun1();                                //④
        \};
}
A. ①
B. ②
C. ③
D. ④
答案:D
题型:单选题
知识点:6.1.3 this指针
难度:2
11.        派生类的一个成员函数试图调用其基类成员函数“void f();”,但无法通过编译,说明
A. f()是基类的私有成员
B. f()是基类的保护成员
C. 派生类的继承方式为私有
D. 派生类的继承方式为保护
答案:
题型:单选题
知识点:7.1.3 基类成员在派生类中的访问权限
难度:3
12.        {
有如下类定义:
class Point\{
public:
    Point(int xx=0,int yy=0):x(xx),y(yy) \{ \}
private:
    int x,y;
\};
class Circle:public Point\{
public:
    Circle(int r):radius(r) \{ \}
private:
    int radius;
\};
派生类Circle中数据成员的个数为
}
A. 1
B. 2
C. 3
D. 5
答案:C
题型:单选题
知识点:7.1 基类和派生类
难度:2
13.        下列运算符中,可以重载的是
A. .*       
B. ?:
C. ++       
D. ::
答案:C
题型:单选题
知识点:8.2 运算符重载
难度:1
14.        下列关于抽象类和纯虚函数的叙述中,正确的是
A. 可以重载抽象类的析构函数
B. 可以说明抽象类对象
C. 抽象类中包含纯虚函数
D. 抽象类的派生类一定不是抽象类
答案:
题型:单选题
知识点:8.5 纯虚函数与抽象类
难度:2
15.        C++流中重载的运算符<<是一个
A. 用于输出操作的成员函数
B. 用于输入操作的成员函数
C. 用于输出操作的非成员函数
D. 用于输入操作的非成员函数
答案:C
题型:单选题
知识点:9.1.1 使用预定义的插入符
难度:1
16.        已知一个函数的原型是“double fun(double x);”,若要以4.25为实参调用该函数,应使用表达式     。
答案:fun(4.25)
题型:填空题
知识点:4.2 函数的调用
难度:1
17.        {
下列程序运行后的输出结果是________________。
#include<iostream>
using namespace std;
void f1(int&x) \{ x++; \}
void f2(int x) \{ ++x; \}
int main() \{
        int x=10,y=12;
        f1(x);        f2(y);
        cout<<x+y<<endl;
        return 0;
\}
        }
答案:
题型:填空题
知识点:4.2.3 函数的引用调用
难度:2
18.        将一个函数声明为一个类的友元函数必须使用关键字     。
答案:friend
题型:填空题
知识点:5.6 友元
难度:1
19.        类中的      成员由类的所有对象共享。
答案:静态
题型:填空题
知识点:5.5 静态成员
难度:1
20.        {
        请在划线处填写正确内容,使类Test的复制构造函数的声明完整。
        class Test \{
        public:
                Test(const                obj);
        \};
}
答案:Test&
题型:填空题
知识点:5.3.3 复制构造函数
难度:1
21.        常用的三种类继承方式为     、     和     。
答案:公有或public | 私有或private | 保护或protected(三个答案顺序可变)
题型:填空题
知识点:7.1.2 派生类的三种继承方式
难度:1
22.        {
下列程序运行后输出Hello,请将划线处的语句补充完整。
        #include<iostream>
        using namespace std;
        class MyClass \{
        public:
                void Print() const \{ cout<<"Hello"; \}
        \};
int main() \{
        MyClass* p = new MyClass();
            Print();
        delete p;
        return 0;
\}
       }
答案:
题型:填空题
知识点:5.2 对象的定义
                6.4.2 堆对象
难度:2
23.        {
下列程序运行后的输出结果是    。
        #include<iostream>
        using namespace std;
        class MyClass \{
        public:
                MyClass(int x=0) \{ cout<<x; \}
                ~MyClass() \{ cout<<0; \}
        \};
        int main() \{
                MyClass arr=\{MyClass(1),MyClass(2)\};
                return 0;
        \}
}
答案:120000
题型:填空题
知识点:5.3 对象的初始化
                6.2.1 对象数组
难度:2
24.        运算符函数的函数名是由运算符前加关键字    构成的。
答案:operator
题型:填空题
知识点:8.2 运算符重载
难度:1
25.        形状类Shape中包含一个纯虚函数Print,它没有形参和返回值,则Print函数在Shape类中的原型声明是      。
答案:
题型:填空题
知识点:8.5 纯虚函数和抽象类
难度:2
26.        改错题
{
下列程序中有三个错误,请指出错误所在行号并改正错误(注意不要修改主函数),使程序输出结果为:
Constructor
The value is 10
Destructor
源文件清单如下:
Line1:                #include <iostream>
Line2:                using namespace std;
Line3:                class MyClass \{
Line4:                public:
Line5:                        MyClass(int x):value(x) \{ cout<<"Constructor"<<endl; \}
Line6:                        void ~MyClass() \{ cout<<"Destructor"<<endl; \}
Line7:                        void Print() const;
Line8:                private:
Line9:                        int value=0;
Line10:                \};
Line11:                void MyClass::Print() \{
Line12:                        cout<<"The value is "<<value<<endl;
Line13:                \}
Line14:                int main() \{
Line15:                        const MyClass object(10);
Line16:                        object.Print();
Line17:                        return 0;
Line18:                \}
}
答案:Line6:        ~MyClass() { cout<<"Destructor"<<endl; }
题型:改错题
知识点:5.3 对象的初始化
难度:1
答案:Line9:        int value;
题型:改错题
知识点:5.1 类的定义
难度:1
答案:Line11:void MyClass::Print() const
题型:改错题
知识点:6.3.3 常成员函数
难度:2
27.        {
请写出下列程序的输出结果。                                                                                       
#include <iostream>
using namespace std;
class MyClass \{
public:
        MyClass(int x=0):val1(x),val2(x)                 \{ cout<<1<<endl; \}
        MyClass(int x,int y):val1(x),val2(y)         \{ cout<<2<<endl; \}
        ~MyClass()                                                         \{ cout<<'~'<<val1<<endl; \}
        void Print()                                                         \{ cout<<val1<<'-'<<val2<<endl; \}
        void Print() const                                         \{ cout<<val1<<'*'<<val2<<endl;\}
private:
        int val1,val2;
\};
int main() \{
        MyClass obj1;
const MyClass obj2(10,20);
        obj1.Print();
        obj2.Print();
        return 0;
\}
}
答案:
题型:阅读程序题
知识点:5.3 对象的初始化
5.4 成员函数的特性
6.3.3 常成员函数
难度:2
28.        {
请写出下列程序的输出结果。                                                                                       
#include <iostream>
using namespace std;
class Base\{
public:
        Base(int x=0) : vB(x)         \{ cout<<"Base"<<vB<<endl; \}
        ~Base()                                         \{ cout<<"~Base"<<endl; \}
protected:
int vB;
\};
class Derived : public Base \{
public:
        Derived(int x=0,int y=0,int z=0) : Base(x), obj(y), vD(z)
\{ cout<<"Derived"<<vB<<vD<<endl; \}
        ~Derived()                                 \{ cout<<"~Derived"<<endl; \}
private:
        Base obj;
int vD;
\};
int main()\{
        Derived d(9,3,1);
        return 0;
\}
}
答案:
Base9
Base3
Derived91
~Derived
~Base
~Base
题型:阅读程序题
知识点:7.3.2 多继承的构造函数和析构函数
难度:2
29.        {
请写出下列程序的输出结果。                                                                               
#include <iostream>
using namespace std;
class Base \{
public:
        virtual void f()                       \{ cout<<"fB"<<endl; \}
        void g()                                       \{ cout<<"gB"<<endl; \}
\};
class Derived : public Base \{
public:
        virtual void f()                         \{ cout<<"fD"<<endl; \}
        void g()                                         \{ cout<<"gD"<<endl; \}
\};
int main() \{
        Derived d;
        Base *p=&d;
        cout<<"Section 1: ";                p->f();
        cout<<"Section 2: ";                p->g();       
return 0;
\}
}
答案:
Section 1: fD
Section 2: gB
题型:阅读程序题
知识点:8.3.2 动态联编
8.4 虚函数
难度:2

页: [1]
查看完整版本: 面向对象程序设计23春模拟题二