青青 发表于 2023-3-4 10:23:20

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

[试题分类]:面向对象程序设计
1.        在C++的面向对象程序设计框架中,程序的基本组成单元是
A. 类
B. 对象
C. 变量
D. 函数
答案:A
题型:单选题
知识点:1.1.2面向对象的有关概念
难度:1
2.        下列选项中,不能作为C++标识符的是
A. points
B. 5x
C. x_5
D. _256
答案:
题型:单选题
知识点:1.3 C++语言的词法及词法规则
难度:1
3.        {
        有如下语句序列:
int x=100,&r=x;
cout<<x<<'-'<<r<<endl;
已知其中变量x的地址为0012FF7C,则执行该语句序列的输出结果为
}
A. 0012FF7C-0012FF7C
B. 100-0012FF7C
C. 0012FF7C-100
D. 100-100
答案:D
题型:单选题
知识点: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);
答案:D
题型:单选题
知识点:4.2 函数的调用
难度:2
5.        下列关于函数重载的叙述中,错误的是
A. 重载函数必须在参数个数或参数类型上有所不同
B. 重载函数的函数名必须相同
C. 重载函数的返回值类型必须相同
D. 重载函数的函数体可以有所不同
答案:
题型:单选题
知识点:4.5 函数重载
难度:1
6.        下列关于类和对象的叙述中,错误的是
A. 类是创建对象的模板
B. 一个类只能有一个对象
C. 一个对象一定属于某个类
D. 对象是状态和操作的封装体
答案:B
题型:单选题
知识点:5.2 对象的定义
难度:1
7.        下列关于析构函数的叙述中,正确的是
A. 系统不能提供默认的析构函数
B. 析构函数必须由用户定义
C. 析构函数没有参数
D. 析构函数可以设置默认参数
答案:C
题型:单选题
知识点:5.3.1 构造函数与析构函数
难度:1
8.        下列选项中,不是类成员函数的是
A. 友元函数
B. 析构函数
C. 构造函数
D. 虚函数
答案:
题型:单选题
知识点:5.6 友元
难度:2
9.        {
下列函数中,不具有隐含的this指针的是
        class MyClass\{
        public:
                int fun1 ();                                //
                void fun2 ();                                //
                virtual void fun3();                //
                friend int fun4();                        //
        \};
        }
A. 
B. 
C. 
D. 
答案:D
题型:单选题
知识点:6.1.3 this指针
难度:2
10.        若有声明“MyClass * const ptr;”,则下列叙述中,正确的是
A. ptr是一个类对象
B. ptr是一个常量指针
C. ptr指向一个常量
D. ptr是一个指向常量的常指针
答案:
题型:单选题
知识点:6.3.2 常指针和常引用
难度:2
11.        {
有如下类定义,obj是类D的对象,下列语句中不违反访问控制权限的是
        class B \{
                public: void fun1();
                private: void fun2();
                protected: void fun3();
        \};
        class D : public B \{
                protected: void fun4();
        \};
        }
A. obj.fun1();
B. obj.fun2();
C. obj.fun3();
D. obj.fun4();
答案:A
题型:单选题
知识点:7.1.3 基类成员在派生类中的访问权限
难度:2
12.        在C++中,能够被派生类继承的函数是
A. 析构函数
B. 友元函数
C. 构造函数
D. 成员函数
答案:D
题型:单选题
知识点:7.2.1 派生类的构造函数和析构函数
难度:2
13.        下列运算符中,不能重载的是
A. &
B. ==
C. ::
D. ||
答案:
题型:单选题
知识点:8.2 运算符重载
难度:1
14.        下列函数中,可以作为虚函数的是
A. 构造函数
B. 静态函数
C. 析构函数
D. 非成员函数
答案:C
题型:单选题
知识点:8.4 虚函数
8.5 虚析构函数
难度:2
15.        下列格式控制符中,可以设置输出项域宽的是
A. setw
B. setfill
C. setprecision
D. endl
答案:A
题型:单选题
知识点:9.4 格式化的输入和输出
难度:1
16.        若有函数声明“void fun(int& x);”,则函数fun是按    方式传递参数的。
答案:引用
题型:填空题
知识点:4.2 函数的调用
难度:1
17.        {
        请在划线处填写Point类的构造函数的定义。
        class Point \{
        public:
        private:
           int x,y;
        \};
}
答案:Point(int xx, int yy):x(xx),y(yy) { }
题型:填空题
知识点:5.3.1 构造函数和析构函数
难度:2
18.        面向对象思想的三个主要特征是    、     和     。
答案:
题型:填空题
知识点:1.1.2面向对象的有关概念
难度:1
19.        声明类的静态成员时必须使用关键字      。
答案:static
题型:填空题
知识点:5.5 静态成员
难度:1
20.        {
下列程序运行后输出10,请将划线处的语句补充完整。
        #include<iostream>
        using namespace std;
        class MyClass \{
        public:
                MyClass(int x):val(x) \{ \}
                void Print();
        private :
                int val ;
        \};
        void     Print() \{ cout<<val<<endl; \}
        int main() \{
                MyClass obj(10);
                obj.Print();
                return 0;
        \}
}
答案:MyClass::
题型:填空题
知识点:5.1 类的定义
难度:1
21.        {
下列程序运行后的输出结果是    。
        #include<iostream>
        using namespace std;
        class MyClass \{
        public:
                MyClass(int x) \{ cout<<x; \}
                ~MyClass() \{ cout<<0; \}
        \};
        int main() \{
                MyClass obj1(1), *ptr=&obj1;
                return 0;
        \}
}
答案:10
题型:填空题
知识点:5.3 对象的初始化
难度:2
22.        有两个类M和C,其中类C定义如下:class C \{ public: M m; \};。若建立类C的对象object,则对象m和对象object中先被初始化的是对象    。
答案:
题型:填空题
知识点:6.4.1 子对象
难度:2
23.        某类中有一个无参且无返回值的常成员函数Show,则在该类中Show函数的原型是      。
答案:void Show() const;
题型:填空题
知识点:6.3.3 常成员函数
难度:2
24.        设置虚基类的目的是为了解决多继承产生的    问题。
答案:二义性
题型:填空题
知识点:7.3.3 多继承的二义性问题
难度:1
25.        {
类Base、Component和Derived的定义如下,请将划线处的语句补充完整。
        class Base \{
        public:
                Base(double d):data(d) \{ \}
        private:
                double data;
        \};
        class Component \{
        public:
                Component(int d):data(d) \{ \}
        private:
                int data;
        \};
        class Derived : public Base \{
        public:
                //使用参数b初始化成员对象com
                Derived(double a, int b, char c): Base(a),   ,character(c) \{ \}
        private:
                Component com;                //成员对象
                char character;
        \};
}
答案:com(b)
题型:填空题
知识点:7.2.1 派生类构造函数和析构函数
难度:1
26.        改错题
{
下列程序中有三个错误,请指出错误所在行号并改正错误(注意不要修改主函数),使程序的输出结果为:
Kelly is 10 years old.
Patrick is 35 years old.
源文件清单如下:
Line1:                #include <iostream>
Line2:                #include <string>
Line3:                using namespace std;
Line4:                class Person \{
Line5:                public:
Line6:                        Person(string str, int _age) : name(str), age(_age) \{ \}
Line7:                        void SetAge(int num) const \{ age=num; \}
Line8:                        void Print() const
Line9:                                \{ cout<<name<<" is "<<age<<" years old."<<endl; \}
Line10:                private:
Line11:                        string name;
Line12:                        int age=10;
Line13:                \};
Line14:                int main() \{
Line15:                        Person p1("Kelly"),p2("Patrick",25);
Line16:                        p1.Print();
Line17:                        p2.SetAge(35);
Line18:                        p2.Print();
Line19:                        return 0;
Line20:                \}
}
答案:Line6:        Person(string str, int _age=10) : name(str), age(_age) { }
题型:改错题
知识点:5.3 对象的初始化
5.4.3 设置参数的默认值
难度:2
答案:Line7:        void SetAge(int num) { age=num; }
题型:改错题
知识点:6.3.3 常成员函数
难度:1
答案:Line12:        int age;
题型:改错题
知识点: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(3);
        a2.print();
        return 0;
\}
   }
答案:
1
2
Param:9
Const:2
~2
~1
题型:阅读程序题
知识点:5.3 对象的初始化
5.4 成员函数的特性
6.3.3 常成员函数
难度:2
28.        {
请写出下列程序的输出结果。                                                                                       
#include <iostream>
#include <string>
using namespace std;
class Equipment\{
public:
Equipment(string s="台式机") : nameE(s) \{ cout<<nameE<<endl; \}
private:
string nameE;
\};
class Monitor\{
public:
Monitor(string s="三星") : nameMo(s) \{ cout<<nameMo<<"显示器"<<endl; \}
private:
string nameMo;
\};
class Computer:public Equipment\{
public:
Computer(string s="我") : name(s) \{ cout<<name<<"的电脑"<<endl; \}       
Computer(string s1, string s2) : name(s1), Equipment(s2)
\{ cout<<name<<"的电脑"<<endl; \}
private:
string name;
Monitor mo;
\};
int main()\{
    Computer c1, c2("小王","笔记本");
    return 0;
\}
}
答案:
台式机
三星显示器
我的电脑
笔记本
三星显示器
小王的电脑
题型:阅读程序题
知识点:7.3.2 多继承的构造函数和析构函数
难度:2
29.        {
请写出下列程序的输出结果。                                                                                       
#include <iostream>
using namespace std;
class A\{
public:
void f()                         \{ cout<<1; \}
        virtual void g()                 \{ cout<<2; \}
\};
class B : public A \{
public:
void f()                         \{ cout<<3; \}
        virtual void g()                 \{ cout<<4; \}
\};
void show(A& a) \{
a.f();
a.g();
\}
int main() \{
B b;               
show(b);               
return 0;
\}
}
答案:14
题型:阅读程序题
知识点:8.3.2 动态联编
8.4 虚函数
难度:2

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