自考C++程序设计2014年4月试题

自考 责任编辑:彭雅倩 2020-03-30

摘要:自考C++程序设计2014年4月试题及答案解析,该试卷为自考C++程序设计历年真题试卷,包含答案及详细解析。

自考C++程序设计2014年4月试题及答案解析

自考C++程序设计2014年4月试题及答案解析,该试卷为自考C++程序设计历年真题试卷,包含答案及详细解析。

一、单项选择题(本大题共20小题,每小题1分,共20分。)在每小题列出的备选项中只有一项是最符合题目要求的,请将其代码填写在题后的括号内。错选、多选或未选均不得分。

1.下列关于类的权限描述错误的是(  )

A.类本身的成员函数可以访问自身的任何成员
B.类的对象只能访问公有成员
C.普通函数可以不通过对象直接访问类的公有成员
D.一个类可以包含另一个类的对象作为成员

2.只能在自身类和子类成员函数中被访问,无法通过对象在类外访问的成员属于(  )

A.private
B.protected
C.public
D.publish

3.面向对象中的“对象”是指(  )

A.行为抽象
B.数据抽象
C.行为抽象和数据抽象的统一
D.行为抽象和数据抽象的对立

4.在类外定义成员函数时,::运算符两侧分别连接(  )

A.返回值类型 函数名
B.返回值类型 类名
C.函数名 类名
D.类名 函数名

5.设函数int& index(int * a, int i)返回数组a中下标为i的元素,如存在整型数组int Array[ ]={1,2,3},在执行index(Array, 2)++后,Array中各元素值为(  )

A.{0, 1, 2}
B.{1, 1, 2}
C.{1, 2, 4}
D.{0, 2, 3}

6.类构造函数定义的位置是(  )

A.类体内或体外
B.只是在类体内
C.只在类体外
D.在类的成员函数中

7.设存在数组a,其长度为Len,则下列哪项泛型算法用于在a中寻找值Value的位置(  )

A.reverse(a, a+Len, Value);
B.sort(a, a+Len, Value);
C.find(a, a+Len, Value);
D.copy(a, a+Len, Value);

8.关于对象的性质,下列描述错误的是:(  )

A.同一类对象间可相互赋值
B.可以使用对象数组
C.对象不可以用作函数参数
D.一个对象可以用作另一个类的成员

9.声明一个没有初始化参数的对象,需调用(  )

A.指定参数构造函数
B.拷贝构造函数
C.初始化函数
D.默认构造函数

10.下列运算符不能重载的是(  )

A.!
B.sizeof
C.new
D.delete

11.如P是一指针类型表达式,则下列表达式中不是左值表达式的是(  )

A.P
B.*P
C.&P
D.P+1

12.使用下列流格式控制符能输出一个换行符的是(  )

A.dec
B.oct
C.hex
D.endl

13.下列表达式,能将P声明为常量指针的是(  )

A.const int * P;
B.int *const P;
C.const int * const P;
D.int * P;

14.C++程序文件扩展名为(  )

A..cpp
B..h
C..lib
D..obj

15.对C++中主函数描述正确的是(  )

A.名称为main,可为多个
B.名称不限,可为多个
C.名称为main,必须有且只能有一个
D.名称不限,必须有且只能有一个

16.假定有char * P="Hello";,要输出这个字符串的地址值的正确写法是(  )

A.cout﹤﹤ *P
B.cout﹤﹤P
C.cout﹤﹤&P
D.cout﹤﹤(void *)P

17.下列描述错误的是(  )

A.在没创建对象前,静态成员不存在
B.静态成员是类的成员,不是对象成员
C.静态成员不能是虚函数
D.静态成员函数不能直接访问非静态成员

18.对于友元描述正确的是(  )

A.友元是本类的成员函数
B.友元不是本类的成员函数
C.友元不是函数
D.以上皆不正确

19.一个函数功能不太复杂,但要求频繁使用,则该函数适合作为(  )

A.内联函数
B.重载函数
C.递归函数
D.嵌套函数

20.下列默认参数的声明不正确的是(  )

A.int max(int a, int b, int c, int d=0);
B.int max(int a, int b, int c=0, int d=0);
C.int max(int a=0, int b, int c=0, int d=0);
D.int max(int a, int b=0, int c=0, int d=0);

二、填空题(本大题共20小题,每小题1分,共20分)请在每小题的空格中填上正确答案。错填、不填均无分。

11.C++程序的编译是以_________为单位进行的。

12.默认参数是在_________中说明的,默认参数可以多于一个。

13.通过C++语言中的_________机制,可以从现存类中构建其子类。

14.拷贝构造函数使用_________作为参数初始化创建中的对象。

15.基类的公有成员在通过公有派生得到的子类中访问权限是_________。

16.要关闭一个输出流对象myFile,所用的C++语句是_________。

17.执行下列代码:double pi= 3.1415926; cout﹤﹤setprecision(5)﹤﹤pi; 程序的输出结果是_________。

18.对象作为函数参数,就是将实参对象的_________传递给形参对象,这种传递是单向的。

19.建立一个对象时,对象的状态是不确定的。为了使对象的状态确定,必须对其进行正确的_________。

110.C++类中的_________函数在对象的生存期结束时被自动调用。

111.C++语言中的整数常量有四种:十进制常量、长整型常量、八进制常量和_________。

112.UML中对象之间的静态关系是通过对象属性之间的连接反映的,称之为_________。

113.声明一个常成员函数Fun,返回类型为char,第一个参数类型为int,第二个参数类型为double,则该函数的声明原型是_________。

114.在C++语言中,利用向量类模板定义一个具有20个int类型且初值为1的向量C,实现此操作的语句是_________。

115.执行下列代码:int a=123,b=321; cout﹤﹤setw(3)﹤﹤a﹤﹤b﹤﹤endl; 程序输出结果是:_________。

116.将指向对象的指针作为函数参数,形参是对象指针,实参是对象的_________。

117.vector类中用于返回向量中第一个对象的方法是_________。

118.C++语言中动态分配内存的关键字是_________。

119.C++类成员的访问权限有_________、公有和保护三种。

120.写出声明一个复数对象num的语句,并使对象被初始化为单精度 2.2+ 1.3i,此声明语句是_________。

三、改错题(本大题共5小题,每小题2分,共10分)

21.#include ﹤iostream.h﹥   main( ){   int x=5, y=6;   const int *p=&x;   * p=y;   cout﹤﹤*p﹤﹤endl;  }

22.#include ﹤iostream.h﹥   class f {   private: T x, y;   public: f1(T a, T b){x=a; y=b;}   T max( ){return(x﹥y)? x: y;}   };   main( ) {   f a;   a.f1( 1.5, 3.8);   cout﹤﹤a.max( )﹤﹤endl;   }

23.#include ﹤iostream.h﹥   class point {   private: float x,y;   public: point(float a, float b){x=a; y=b; }   f( ){x=0; y=0; }   void getx( ){cout﹤﹤x﹤﹤endl;}   void gety( ){cout﹤﹤y﹤﹤endl;}   };   main( ) {   point a ( 3.5);   a.getx( );   }

24.#include ﹤iostream.h﹥class f{   private: float x,y;   float get( ){return x+y;}   public:f1(float a,float b){x=a;y=b;}   };   main( ) {   f a;   a.f1(1, 3.8);   cout﹤﹤a.get( )﹤﹤endl;   }

25.#include ﹤iostream.h﹥   class test1{   private: int x;   public: test1( ){x=2;}   void set(int a){x=a;}   void get(){cout﹤﹤x﹤﹤endl;}   };   class test2{   private: int x;   public: test2( ){x=3;}   void set(int a){x=a;}   void get( ){cout﹤﹤x﹤﹤endl;}   };   class test: public test1, public test 2. {   private: int x;   public: void set(int a){x=a;}   void gettest( ){cout﹤﹤x﹤﹤endl;}   };   main( ) {   test a; a.get( );   }

四、完成程序题(本大题共5小题,每小题4分,共20分)

31.完成下面类中的成员函数的定义。   class point   {   private:   int m, n;   public:   point(int, int);   point(point&);   };   point:: point(int a, int b)   {   m=a;   _________=b;   }   point::point( _________ )   {  m=t.m;   n=t.n;   }

32.#include ﹤iostream﹥   using namespace std;   class base   {   private: int x;   public: base(int a){x=a;}   int get( ){return x:}   void showbase( ) {cout﹤﹤"x="﹤﹤x﹤﹤endl; }   };   class Derived: public base   {private: int y;   public: Derived(int a, int b): base(a) {y=b; }   void showderived( )   {cout﹤﹤"x="﹤﹤get( )﹤﹤",y="﹤﹤y﹤﹤endl; }   };   void main( )   {   base b(3);   Derived d(6, 7);   b.showbase( );   d.showderived( );   _________;   b.showbase( );   _________;   b 1.showbase( );   base * pb=&b1;   pb-﹥showbase( );   d.showderived( );   b.showbase( );   }   输出结果如下:   x=3   x=6,y=7   x=6   x=6   x=6   x=6,y=7   x=6

33.#include ﹤iostream﹥   #include ﹤fstream﹥   using namespace std;   class complex   {   public:   int real:   int imag;   complex(int r=0, int i=0)   {   real=r;   imag=i;   }   };   complex operator+(_________,complex&b)   {   int r=a.real+b.real;   int i=a.imag+b.imag;   return _________;   }   void main( )   {   complex x(1, 2), y(3, 4), z;   z=x+y;   cout﹤﹤z.real﹤﹤"+"﹤﹤z.imag﹤﹤"i"﹤﹤endl;   }

34.下面程序的运行结果如下:   This is line1   This is line2   This is line3   将下列程序补充完整,答案写在答题纸上。源程序如下:   #include ﹤iostream﹥   #include _________   using namespace std;   void main( )   {   fstream fin, fout;   fout.open("my.txt", ios:: out);   if(!fout.is_open( ))   return;   for(int i=0; i﹤3; i=i+1)   fout﹤﹤"This is line"﹤﹤i+1﹤﹤endl;   fout.close( );   fin.open("my.txt", ios:: in);   if(! fin.is_open( ))   return;   char str[100];   while(_________)   {   fin.getline(str,100);   cout﹤﹤str﹤﹤endl;   }   fin.close( );   }

35.求两个浮点数之差的cha函数的原型声明、调用方法。   #include ﹤iostream﹥   using namespace std;   void main( )   {   float a, b;   _________; //函数cha的原型声明   a= 12.5;   b= 6.5;   float c=_____________; //调用函数cha   cout﹤﹤c﹤﹤endl;   }   float cha(float x,float y)   {   float w;   w=x-y;   return w;   }

五、程序分析题(本大题共2小题,每小题10分,共20分)

41.#lnclude ﹤iostream.h﹥   void func( );   void main( )   {   for(int i=0; i﹤6; i++)   {   func( );   }   }   void func( )   {   int x=0;   x++;   static int y=0;   y++;   cout﹤﹤"x="﹤﹤x﹤﹤";y="﹤﹤y﹤﹤endl;   }

42.#include ﹤iostream.h﹥   class A   {   public:   A( );   void Show( );   ~A( );   private:   static int c;   };   int A:: c=O;   A:: A( )   {   cout﹤﹤"constructor."﹤﹤endl;   c +=10;   }   void A:: Show( )   {   cout﹤﹤"c="﹤﹤c﹤﹤endl;   }   A:: ~A( )   {   cout﹤﹤"destrucator."﹤﹤endl;   }   void main( )   {   A a, b;   a.Show( );   b.Show( );   }

六、程序设计题(本大题共1小题,共10分)

51.在三角形类tri实现两个函数,功能是输入三个顶点坐标判断是否构成等边三角形   #include ﹤iostream.h﹥   #include ﹤math.h﹥   class point { point   private: float x, y;   public: f(float a, float b){x=a; y=b;}   f( ){x=0; y=0;}   Void set(float a, float b){x=a; y=b;}   float getx( ){return x;}   noat gety( ){return y;}   };   class tri{   point x, y, z;   float s1, s2, s3;   public....settri(....); //用于输入三个顶点坐标   ....test(....); //用于判断是否构成等边三角形   };   请写出两个函数的过程(如果需要形式参数,请给出形参类型和数量,以及返回值类型)

更多资料
更多课程
更多真题
温馨提示:因考试政策、内容不断变化与调整,本网站提供的以上信息仅供参考,如有异议,请考生以权威部门公布的内容为准!

自考备考资料免费领取

去领取

距离2024 自考考试

还有
  • 1
  • 7
  • 6
自考报名

每年3月、8月

领准考证

考前7天

考试信息

每年4月、10月

成绩查询

考后45天

专注在线职业教育23年

项目管理

信息系统项目管理师

厂商认证

信息系统项目管理师

信息系统项目管理师