1、面向对象B卷(所有答案必须填写在答题纸上,写在试卷上无效。不能拆散试卷。)一、选择题(每题2分,共22040分)1. 下面有关类说法不正确的是( ) A.一个类可以有多个构造函数 B.一个类只有一个析构函数 C.析构函数需要指定参数 D.一个类中可以说明具有类类型的数据成员2. 假定一个类的构造函数为“A(int aa,int bb)a = aa; b=aa*bb;”,则执行“A x(4,5);”语句后,xa和xb的值分别为( )。A4和5 B5和4 C,4和20 D20和53. 假定AB为一个类,则执行 “AB a10;”语句时调用该类无参构造函数的次数为( )。A. 0 B. 1 C. 9
2、 D. 104. 假定M为一个类, 则该类的拷贝构造函数的声明语句为( )AM&(M x); BM(M x); CM(M * x); DM(M &);5. 下列带缺省值参数的函数说明中,正确的说明是( )A. int Fun(int x, int y=2,int z=3);B. int Fun(int x=1,int y, int z=3);C. int Fun(int x, int y=2,int z);D. int Fun(int x=1,int y=2, int z);B6. 以下程序段的输出是 ( )int trial( int& a, int b) if(b a) a=b; retu
3、rn a; else return 0; float x=0, y=10,z;z=trial(y,x);cout z x y endl;A. 10 0 0 B. 0 10 0 C. 10 0 0 D. 0 0 107. 文件流outFile已连接了文件project.txt,正确关闭文件流outFile的语句是( )A. outFile.close; B. outFile.close();C. outFile.close(project.txt); D. close(outFile);8. 以下哪一个函数声明即可以接收cin流,又可以接收输入文件流( )A. void input( fstre
4、am &inFile);B. void input( istream &inFile);C. void input( ifstream &inFile);D. void input( iostream &inFile);9. 给出类和对象的声明,正确输出bottle对象的数据成员age和cost的是( )class Winepublic: Wine(); int getAge(); float getCost();private: int age; float cost;Wine bottle;A. cout bottle;B. cout Wine.age Wine.cost;C. cout
5、bottle.getAge() bottle.getCost();D. cout bottle.getAge bottle.getCost;10. 以下选项中哪一个函数声明能保证函数执行后不改变形参表中数组的值( )A. void f1(int array, int size) const;B. void f1(int array, int size);C. void f1(const int array, int size);D. void f1(int &array, int size);11. 以下代码段的输出是什么?( ) int *p1, *p2; p1 = new int; p2
6、= new int; *p1=11; *p2=0; p2=p1; cout *p1 *p2 endl; A. 11 0 B. 0 11 C. 11 11 D. 0 0B12. 以下语句中,能够正确地从一个输入文件流fin中读一整行并存放到类string的对象line 中的是( )A. getline(fin, line); B. fin.getline(line);C. fin.getline(line,n); D. fin.getline(line,10);13. p1是指向动态数组的指针,哪一个能够正确地释放p1所指向的内存空间( )A. delete p1; B. delete p1;C
7、. delete *p1; D. delete p1;14. 下面函数模板定义中不正确的是( ) A.template B.template Q F(Q x) Q F(Q x) return x*2; return x+x; C.template D.template T F(T x) T F(T x) return x*x; return x+T; 15. 给出如下代码段,哪一条语句正确地给链表的头节点分配内存空间( )struct Nodeint item; Node* link;typedef Node* NodePtr;NodePtr head;A. head = new Node;
8、B. head = new int;C. head-link=NULL; D. head = new NodePtr;16. 执行以下代码,输出的内容是( )class Petpublic: virtual void print(); string name;class Dog: public Petpublic: void print(); string breed;void Pet:print() cout My name is name;void Dog:print() Pet:print(); cout , and my breed is a breed name= Rover;dPt
9、r-breed=Weiner;pPtr= dPtr;pPtr-print();A. My name is Rover, and my breed is a WeinerB. My name is RoverC. , and my breed is a WeinerD. 无输出17. 以下输入操作符重载函数的声明错在哪里?( )Bistream& operator (istream& in, const myClass &object);A. 对象不应该是传引用调用 B. 对象不应该是常量参数C. 返回类型不应该是引用 D. 没错18. 在公有派生的情况下,有关派生类的对象和基类的对象之间的关系
10、,不正确的叙述是( ) A.派生类的对象可以赋给基类的对象 B.派生类的对象可以直接访问基类中的成员 C.派生类的对象可以初始化基类的引用 D.派生类的对象的地址可以赋给指向基类的指针19. 一个一元操作符重载为类的友元函数时,参数的个数是? ( )A. 0 B. 1 C. 2 D. 按需设置20. 以下关于析构函数的说法正确的是( )A. 一个类中只能定义一个析构函数; B. 析构函数有返回值;C. 析构函数的定义只能在类体内; D. 析构函数可以有1个或多个参数。二、填空题(每题2分,共2510分)1. 面向对象程序设计的三大基本特性是继承性、_、封装性。2. 用关键字_声明的函数称为虚函
11、数。3. 当一个类对象离开它的作用域时, 系统将自动调用该类的_函数。4. 假定AB为一个类, 则执行AB a5; 语句时, 系统自动调用该类构造函数的次数为_。5. 假定要动态分配一个类型为Worker的具有m个元素的数组, 并由r指向这个动态数组, 则使用的语句为_。三、读程序,写结果(每题5分,共5420分)1. # include #include using namespace std;class Point int x,y; public: Point()x=1;y=1; Point(int tx,int ty) x=tx; y=ty; Point()coutPoint: x,y
12、is deleted.endl; ;void main() Point obj1;Point obj2(10,20); 2. #includeusing namespace std; class My Class public: int number; void set(int i); ; Bvoid MyClass:set (int i) number=i; void main() MyClass my1; int number=10; my1.set(5); coutmy1.numberend1; my1.set(number); coutmy1.numberendl; 3. #inclu
13、deusing namespace std;void sample_function(double test) throw (int);int main() try cout “Trying.n”; sample_function(212); cout “Trying after call.n”; catch(int) cout “Catching.n”;cout “End of program.n”;return 0;void sample_function(double test) throw (int) cout”Starting sample_function.n”; if(test
14、100) throw 42;4#include class A public:A()coutA:A() called.n;virtual A()coutA:A() called.n;class B: public Apublic:B(int i)coutB:B() called.n;buf=new chari;virtual B()delete buf;cout(istream& ins, ComplexB & c); ComplexB operator+( ComplexB & c1); ;2定义抽象类Shape,它派生出两个类:Square(正方形)和Trapezoid(梯形),用虚函数分别计算各种图形的面积。 并在主函数中定义如下对象:Square s(3. 5); /3.5为正方形的边长 Trapezoid t(2. 0, 4. 5, 3. 2); /2. 0, 4. 5, 3. 2分别为梯形的上底、下底和高求出它们的面积之和,并输出。要求用基类指针数组,使它的每一个元素指向一个派生类的对象(20分)。
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1