欢迎访问桃李自考网,本站可为自考生提供学习指导服务,今天是

您所在的位置: 首页> 备考指导 > 历年真题 > 工学类 > 面向对象程序设计 > 全国2006年1月高等教育自学考试面向对象程序设计试题

全国2006年1月高等教育自学考试面向对象程序设计试题

发表时间:2022-07-05 12:24:36 来源:桃李自考网

全国2006年1月高等教育自学考试
 面向对象程序设计试题
 课程代码:02328

一、单项选择题(本大题共10小题,每小题2分,共20分)
 在每小题列出的四个备选项中只有一个是符合题目要求的,请将其代码填写在题后的括号内。错选、多选或未选均无分。
 1.面向对象程序设计中的数据隐藏指的是(   )
 A.输入数据必须输入保密口令 B.数据经过加密处理
 C.对象内部数据和代码合并在一起 D.对象内部数据结构的不可访问性
 2.在C++中,编写一个内联函数Fun,使用int类型的参数,求其平方并返回,返回值也为int类型,下列定义正确的是 (   )
 A.int Fun(int x){return x*x;} B.inline int Fun(int x){return x*x;}
 C.int inline Fun(int x){return x*x;} D.int Fun(int x){inline return x*x;}
 3.下面关于重载函数的叙述中正确的是 (   )
 A.重载函数必须具有不同的返回值类型
 B.重载函数的形参个数必须不同
 C.重载函数必须有不同的形参列表
 D.重载函数的函数名可以不同
 4.若有定义“int x=17;”,则语句“cout<  A.11 B.0x11
 C.21 D.021
 5.下列关于析构函数的描述中正确的是(   )
 A.析构函数可以重载 B.析构函数可以是虚函数
 C.析构函数名与类名相同 D.析构函数的返回类型为void
 6.下列关于纯虚函数的描述中,正确的是 (   )
 A.纯虚函数是一种特殊的虚函数,它是个空函数
 B.具有纯虚函数的类称为虚基类
 C.一个基类中说明有纯虚函数,其派生类一定要实现该纯虚函数
 D.具有纯虚函数的类不能创建类对象
 7.下列关于运算符重载的描述中,正确的是 (   )
 A.可以改变运算符的目数 B.可以改变运算符的优先级
 C.可以改变运算符的结合性 D.可以改变运算符的功能
 8.要将类A说明是类B的虚基类,正确的描述是 (   )
 A.class virtual B:public A B.class B:virtual public A
 C.virtual class B:public A D.class B:public A virtual
 9.下面关于静态成员的描述中,正确的是 (   )
 A.静态数据成员是类的所有对象共享的数据
 B.类的每个对象都有自己的静态数据成员
 C.类的不同对象有不同的静态数据成员值
 D.静态数据成员不能通过类的对象访问
 10.假设Sample是个类,则语句“Sample a[2],*p[3];”调用构造函数的次数为(   )
 A.0 B.2
 C.3   D.5
 二、填空题(本大题共10小题,每小题2分,共20分)
 请在每小题的空格中填上正确答案。错填、不填均无分。
 11.在面向对象的程序设计中,将一组对象的共同特性抽象出来形成________________。
 12.在C++中要创建一个文件输入流对象fin,同时该对象打开文件“Test.txt”用于输入,则正确的声明语句是________________。
 13.如果要把类B的成员函数void fun( )说明为类A的友元函数,则应在类A中加入语句________________。
 14.A是一个类,已有语句“A* p;p=new A[10];”。要释放由p指向的动态空间,正确的语句应该是________________。
 15.如果一个引用不是用作函数参数或返回值,则在说明该引用时必须对它进行________________。
 16.如果要把PI声明为值为3.14159类型为双精度实数的符号常量,该声明语句是________________。
 17.在C++中函数原型不但要标识一个函数的返回类型,同时还要标识该函数的________________。
 18.类A的后置自增运算符++以成员函数的形式进行重载,其在类内的函数声明是________________。
 19.动态联编是通过基类类型的指针或引用调用________________函数来完成。
 20.基类的保护成员通过私有派生其在派生类中的访问权限是________________。
 三、改错题(本大题共5小题,每小题2分,共10分)
 21.下面的类定义中有一处错误,请用下横线标出错误所在行并给出修改意见。
 class Sample
 {
 private:
 int data;
 Sample( ){data=10;}
 public:
 Sample(int d){data=d;}
 int operator int( ){return data;}
 };
 22.下面的类定义中有一处错误,请用下横线标出错误所在行并给出修改意见。
 #include
 class Point
 {
 int X,Y;
 public:
 Point( ){X=0;Y=0;}
 Point(int x=0,int y=0){X=x;Y=y;}
 void display( ){cout<  };
 23.下面的程序有一处错误,请用下横线标出错误所在行并说明错误原因。
 #include
 template
 void Swap(T& a,T& b)
 {
 T t;
 t=a,a=b,b=t;
 }
 void main( )
 {
 int a=3,b=4;
 char str1[5]=”abcd”,str2[5]=”hijk”;
 Swap(a,b);
 Swap(str1,str2);
 cout<<”a=”<  cout<<”str1=”<  }
 24.下面的程序有一处错误,请用下横线标出错误所在行并说明错误原因。
 #include
 class Base
 {
 public:
 virtual void fun( ){cout<<'Base function'<  };
 class Derived:public Base
 {
 public:
 void fun( ){cout<<'Derived function'<  };
 void main( )
 {
 Base b;
 Derived* p=&b;
 b.fun( );
 p->fun( );
 }
 25.下面的程序有一处错误,请用下横线标出错误所在行并说明错误原因。
 #include
 class A
 {
 int x;
 protected:
 int y;
 public:
 A(int xx,int yy){x=xx; y=yy;}
 };
 class B:public A
 {
 public:
 B(int a,int b):A(a,b){}
 void display( ){cout<  };
 void main( )
 {
 B b(5,10);
 b.display( );
 }
 四、完成程序题(本大题共5小题,每小题4分,共20分)
 根据题目要求,完成程序填空。
 26.请在下面程序的横线处填上适当内容,以使程序完整,并使程序的输出为:
 2,1
 4,3
 #include
 class A
 {
 int a;
 public:
 A(int i=0){a=i;}
 int Geta( ){return a;}
 };
 class B
 {
 A a;
 int b;
 public:
 B(int i=0,int j=0): ①        {}
 void display( ){cout<  };
 void main( )
 {
 B b[2]={B(1,2),B(3,4)};
 for(int i=0;i<2;i++)
 ②        ;
 }
 27.下面程序中A是抽象类。请在下面程序的横线处填上适当内容,以使程序完整,并使程序的输出为:
 B1 called
 B2 called
 #include
 class A
 {
 public:
 ①            ;
 };
 class B1:public A
 {
 public:
 void display( ){cout<<”B1 called”<  };
 class B2:public A
 {
 public:
 void display( ){cout<<”B2 called”<  };
 void show(②        )
 {
 p->display( );
 }
 void main( )
 {
 B1 b1;
 B2 b2;
 A* p[2]={&b1,&b2};
 for(int i=0;i<2;i++)
 show(p[i]);
 }
 28.请在下面程序的横线处填上适当内容,以使程序完整,并使程序的输出为:
 Name:王小明
 Grade:90
 #include
 #include
 class Person
 {
 char name[20];
 public:
 Person(char* s){strcpy(name,s);}
 void display( ){cout<<”Name:”<  };
 class Student:public Person
 {
 int grade;
 public:
 Student(char* s, int g): ①        {grade=g;}
 void display( )
 {
 ②        ;
 cout<<”Grade:”<  }
 };
 void main( )
 {
 Student s(“王小明”,90);
 s.display( );
 }
 29.请在下面程序的横线处填上适当内容,以使程序完整,并使程序的输出为5。
 #include
 class Integer
 {
 int x;
 public:
 Integer(int a=0){x=a;}
 void display( ){cout<  ①             ;
 };
 Integer Max(Integer a,Integer b)
 {
 if(②        )
 return a;
 return b;
 }
 void main( )
 {
 Integer a(3),b(5),c;
 c=Max(a,b);
 c.display( );
 }
 30.请在下面的横线处填上适当内容,以使类的定义完整。
 class Array
 {
 int* ptr;
 int size;
 public:
 Array( ){size=0; ptr=0;}
 Array(int n){size=n;ptr=new int[size];}
 Array(①       )    //复制初始化构造函数
 {
 size=a.size;
 ptr=new int[size];
 for(int i=0;i  ②       ;    //将源对象的动态数组内容复制到目标对象
 }
 };
 五、程序分析题(本大题共6小题,每小题5分,共30分)
 阅读下面的程序,写出程序运行的结果。
 31.#include
 class Test
 {
 private:
 int num;
 public:
 Test(int n=0){num=n;num++;}
 ~Test( ){cout<<”Destructor is active,number=”<  };
 void main( )
 {
 Test x[2];
 cout<<”Exiting main”<  }
 32.#include
 class A
 {
 public:
 virtual void fun (int data){cout<<”class A:”<  void fun(char *str){ cout<<”class A:”<  };
 class B: public A
 {
 public:
 void fun( ) {cout<<”class B”<  void fun(int data) { cout<<”class B:”<  void fun(char *str){ cout<<”class B:”<  };
 void main( )
 {
 A *pA;
 B b;
 pA=&b;
 pA->fun(1);
 pA->fun(“Hello”);
 }
 33.#include
 void main( )
 {
 cout.fill('*');
 cout.width(10);
 cout<<'123.45'<  cout.width(8);
 cout<<'123.45'<  cout.width(4);
 cout<<'123.45'<  }
 34.#include
 class Num
 {
 int X,Y;
 public:
 Num(int x,int y=0){X=x;Y=y;}
 void value(int x,int y=0){X=x;Y=y;}
 void value( ){
 cout<  if(Y!=0)
 cout<<(Y>0?’+’:’-’)<<(Y>0?Y:-Y)<<’i’;
 cout<  }
 };
 void main( )
 {
 Num n(1);
 n.value( );
 n.value(2,3);
 n.value( );
 Num m(3,-4);
 m.value( );
 }
 35.#include
 class Sample
 {
 private:
 int i;
 static int count;
 public:
 Sample( );
 void display( );
 };
 Sample::Sample( )
 {
 i=0;
 count++;
 }
 void Sample::display( )
 {
 cout<<'i='<  }
 int Sample::count=0;
 void main( )
 {
 Sample a,b;
 a.display( );
 b.display( );
 }
 36.#include
 class A
 {
 int a;
 public:
 A(int aa=0){a=aa;cout<<'a='<  };
 class B
 {
 int b;
 public:
 B(int bb=0){b=bb;cout<<'b='<  };
 class C:public B
 {
 A a;
 public:
 C( ){cout<<”C default constructor”<  C(int i,int j):a(i),B(j){cout<<”C constructor”<  };
 void main( )
 {
 C c1,c2(5,6);
 }