自考真题答案

3773考试网自学考试自考真题答案正文

全国2008年10月自学考试C++程序设计试题

来源:招生考试网 2008-12-12 14:12:39

全国200810月自学考试C++程序设计试题

课程代码:04737

一、单项选择题(本大题共20小题,每小题1分,共20)

在每小题列出的四个备选项中只有一个是符合题目要求的,请将其代码填写在题后的括号内。错选、多选或未选均无分。

1.对C++语言和C语言的兼容性,描述正确的是(     

AC++兼容C    BC++部分兼容C

CC++不兼容C DC兼容C++

2.在C++中使用流进行输入输出,其中用于屏幕输出的对象是(     

Acerr  Bcin

Ccout  Dcfile

3.对使用关键字new所开辟的动态存储空间,释放时必须使用(     

Afree  Bcreate

Cdelete      Drealse

4.如没有使用private关键字定义类的数据成员,则默认为(     

Aprivate     Bpublic

Cprotected Dfriend

5.使用值传递方式将实参传给形参,下列说法正确的是(     

A.形参是实参的备份      B.实参是形参的备份

C.形参和实参是同一对象     D.形参和实参无联系

6.在函数调用时,如某一默认参数要指明一个特定值,则有(     

A.其之前所有参数都必须赋值     B.其之后所有参数都必须赋值

C.其前、后所有参数都必须赋值 D.其前、后所有参数都不必赋值

7.设存在函数int max(intint)返回两参数中较大值,若求225970三者中最大值,下列表达式不正确的是(     

Aint m = max(22max(5970))      Bint m = max(max(2259)70)

Cint m = max(225970) Dint m = max(59max(2270))

8.下列哪个类型函数不适合声明为内联函数(     

A.函数体语句较多  B.函数体语句较少

C.函数执行时间较短      D.函数执行时间过长

9int Func(intint);不可与下列哪个函数构成重载(     

Aint Func(intintint)       Bdouble Func(intint)

Cdouble Func(doubledouble)   Ddouble Func(intdouble)

10.对类中声明的变量,下列描述中正确的是(     

A.属于全局变量

B.只属于该类

C.属于该类,某些情况下也可被该类不同实例所共享

D.任何情况下都可被该类所有实例共享

11.类的私有成员可在何处访问(     

A.通过子类的对象访问  B.本类及子类的成员函数中

C.通过该类对象访问      D.本类的成员函数中

12.如果没有为一个类定义任何构造函数的情况下,下列描述正确的是(     

A.编译器总是自动创建一个不带参数的构造函数

B.这个类没有构造函数

C.这个类不需要构造函数

D.该类不能通过编译

13.一个类可包含析构函数的个数是(     

A0 B1

C.至少一个       D0个或多个

14this指针存在的目的是(     

A.保证基类公有成员在子类中可以被访问

B.保证每个对象拥有自己的数据成员,但共享处理这些数据成员的代码

C.保证基类保护成员在子类中可以被访问

D.保证基类私有成员在子类中可以被访问

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

A.类本身的成员函数只能访问自身的私有成员

B.类的对象只能访问该类的公有成员

C.普通函数不能直接访问类的公有成员,必须通过对象访问

D.一个类可以将另一个类的对象作为成员

16.在编译指令中,宏定义使用哪个指令(     

A#include  B#define

C#if    D#else

17.设类A将其它类对象作为成员,则建立A类对象时,下列描述正确的是(     

AA类构造函数先执行  B.成员构造函数先执行

C.两者并行执行      D.不能确定

18.下列描述错误的是(     

A.在创建对象前,静态成员不存在    B.静态成员是类的成员

C.静态成员不能是虚函数     D.静态成员函数不能直接访问非静态成员

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

A.友元是本类的成员函数     B.友元不是本类的成员函数

C.友元不是函数      D.友元不能访问本类私有成员

20.在哪种派生方式中,派生类可以访问基类中的protected成员(     

Apublicprivate     Bpublicprotected

Cprotectedprivate       D.仅protected

二、填空题(本大题共20小题,每小题1分,共20)

请在每小题的空格中填上正确答案。错填、不填均无分。

21.设要把一个文件输出流对象myFile与文件“f:\myText.txt相关联,所用的C++语句是:__________

22C++ostream类的直接基类是________

23.运算符[  ]只能用________运算符来重载,不能用友元运算符来重载。

24.定义虚函数所用的关键字是________

25vector类中用于返回向量中第1个对象的方法是________

26.在C++中,利用向量类模板定义一个具有20char的向量E,其元素均被置为字符‘t’,实现此操作的语句是________

27.类的继承是指子类继承基类的________和成员函数。

28.不同对象可以调用相同名称的函数,但可导致完全不同的行为的现象称为________

29________指令指示编译器将一个源文件嵌入到带该指令的源文件之中。

30.设类A有成员函数

void Fun(void)

若要定义一个指向类成员函数的指针变量pafn来指向Fun,该指针变量的声明语句是:________

31.设在程序中使用如下语句申请了一个对象数组:

Point * ptr = new Point[2]

则在需要释放ptr指向的动态数组对象时,所使用的语句是________

32.在保护派生中,基类权限为Private的成员在派生类中________

33.类A有如下成员函数

int A::fun(double x){return (int) x2}

int A::fun(int x){return x*2}

a为类A的对象,在主函数中有int s=afun(6.0)+a.fun(2),则执行该语句后,s的值为________

34.对象传送的消息一般由3部分组成:接收对象名、调用操作名和________

35.将指向对象的指针作为函数参数,形参是对象指针,实参是对象的________

36.在使用string类的find成员函数来检索主串中是否含有指定的子串时,若在主串中不含指定的子串,find函数的返回值是________

37.在C++中,声明布尔类型变量所用的关键字是________

38.执行下列代码

int a=29b=100

cout <<setw (3) << a << b << endl

程序的输出结果是:________

39.执行下列代码

cout <<Hex:″<< hex << 255

程序的输出结果为________

40C++语言中可以实现输出一个换行符并刷新流功能的操控符是________

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

下面的类定义中有一处错误,请用下横线标出错误所在行并给出修改意见。

41#include<iostreamh>

main( ) {

int x=5y=6

const int * p=x

*p=y

cout<<*p<<endl

}

42#include<iostreamh>

class f{

privateint xy

publicf1( ){x=0y=0}

print( ){cout<<x<<<<y<<endl}

}

main( ){

f a

a.f1(1,1)

a.print( )

}

43#include<iostream.h>

    class f{

    privateint x=0y=0

    publicvoid f1(int aint b){x=ay=b}

        void get( ){cout<<x<<’<<y<<endl}

    }

    main( ){

    f a

    a.f1(1,3)

    a.get ( )

    }

44#include<iostream.h>

  class point{privatefloat x

    publicvoid f(float a){x=a;}

        void f( ){x=0;}

        friend float max(point& apoint& b)

        }

    float max(point& apoint& b)

{return(a.x>b.x)? a.xb.x}

main( ){

    point ab

    a.f(2.2)b.f(3.3)

    cout<<a.max(a,b)

    }

45#include<iostream.h>

    template<class T>

class f{

privateT xy

publicvoid f1(T aT b){x=ay=b}

T max( ){retum(x>y)?x:y;}

}

main( ){

f a

a.f1(1.5,3.8)   

cout<<a.x<<a.y<<a.max( )<<endl

}

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

46.完成下面类中的成员函数的定义。

    class point

    {

    private

    int mn

    public

    point(intint)

    point(point&)

    }

    point::point(int aint b)

    {

    m=a

________=b

}

    point::point(________)

    {

    m=t.m

    n=t.n

    }

47.下面是一个输入半径,输出其面积和周长的C++程序,在下划线处填上正确的语句。

  #include<iostream>

    using namespace std

    ________pi=3.14159

  void main( )

  {

  double r

    cout<<r=″;

    ___________ ;

    double l=2.0*pi*r

double s=pi*r*r

cout<<″\n The long is:″<<l<<endl

    cout<<The area is:″<<s<<endl

    }

48.在下划线处填上缺少的部分。

    #include<iostream>

    #include<fstream>

    using namespace std

    class complex

    {

    public

    int real

    int imag

    complex(int r=0int 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(12)y(34)z

    z=x+y

    cout<<z.real<<+<<z.imag<<i<<endl

    }

49.程序的输出结果如下:

  19

  5030

  请根据输出数据在下面程序中的下划线处填写正确的语句。

  源程序如下:

  #include<iostream>

  using namespace std

  class base

  {

  private

  int m

  public

  base( ){ }

  base(int a):m(a){}

  int get( ){return m;}

  void set(int a){m=a;}

  }

  void main()

  {

  base*ptr=new base[2]

  ptr- >set(30)

  ptr= _________;

  ptr- >set(50)

  base a[2]={19}

  cout<<a[0].get( )<<″,″<<a[1].get( )<<endl

  cout<<ptr- >get( )<<″,″;

  ptr=ptr-1

  cout<<________<<endl

  delete[ ]ptr

  }

50.在下面横线处填上求两个浮点数之差的cha函数的原型声明、调用方法。

  #include <iostream>

  using namespace std

  void main( )

  {

  float ab

  ________//函数cha的原型声明

  a=12.5

  b=6.5

  float c=_________    //调用函数cha

    cout<<c<<endl

  }

  float cha(float xfloat y)

  {

  float w

  w=x-y

  return w

  }

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

51.给出下面程序的输出结果。

  #include <iostreamh>

  template <class T>

  class Sample

  {

  T n

  public

  Sample(T i){n=i;}

  int operator==(Sample &)

  }

  template <class T>

  int Sample<T>::operator==(Samples)

  {

  if(n==s.n)

  return 1

  else

    return 0

    }

  void main( )

  {

  Sample<int>sl(2)s2(3)   

  cout<<s1s2的数据成员″<<(sl==s2 ?″相等″:″不相等″)<<endl

  Sample<double>s3(2.5)s4(2.5)

  cout<<s3s4的数据成员″<<(s3==s4 ? ″相等″:″不相等″)<<endl

  }   

52.给出下面程序的输出结果。

  #include<iostream>

  using namespace std

  template<class T>

  T max(T mlT m2)

  {return(m1>m2)?ml:m2:}

  void main( )  {

  cout<<max(17)<< \t<<max(2.05.0)<<endl

  cout<<max(y,b<<″\t<<max(A″,″a)<<endl

  }

53.给出下面程序的输出结果

  #include <iostream>

  using namespace std

  class A  {

  public

  int x

  A( ) { }

  A(int a){x=a;}

  int get(int a){return x+a;}  }

  void main( )  {

  A a(8)

  int(A::*p)(int)

  p=A::get

  cout<<(a.*p)(5)<<endl

  A*pi=a

  cout<<(pi- >*P)(7)<<endl}

54.给出下面程序的输出结果。

  include<iostream>

  #include<string>

  using namespace std

  class Book  {

  char*title

  char*author;

  int numsold

  public

    Book( ){ }

    Book(const char*strlconst char*str2const int num)  {

      int len=strlen(strl)

      title=new char[len+1]

      strcpy(titlestr1)

      len=strlen(str2)

      author=new char[len+1]

      strcpy(authorstr2)

      numsold=num  }

      void setbook(const char*str1const char*str2const int num)  {

      int len=strlen(str1)

        title=new char[len+1]

    strcpy(titlestr1)

    len=strlen(str2)

    author=new char[len+1]

        strcpy(authorstr2)

    numsold=num

      }

      Book( )  {

        delete title

        delete author

      }

      void print(ostream&output)  {

        output<<″书名:″<<title<<endl

        output<<″作者:″<<author<<endl

        output<<″月销售量:″<<numsold<<endl

      }   

    }

    void main( )  {

    Book obj1(″数据结构″,″严蔚敏″,200)obj2

    obj1.print(cout)

    obj2.setbook(C++语言程序设计″,″李春葆″,210)

    obj2.print(cout)

    }

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

55.在三角形类TRI实现两个函数,功能是输入三个顶点坐标判断是否构成三角形

    #include<iostream.h>

    #include<math.h>

    class point{

    privatefloat xy

    publicpoint(float afloat b){x=a;y=b;}

      point( ){x=0y=0}   

      void set(float afloat b){x=a;y=b;}

      float getx( ){return x;}

      float gety( ){return y;}

    }

    class tri{

point xyz

float s1s2s3

    public;...settri(....);//用于输入三个顶点坐标

         ....test(....);//用于判断是否构成三角形

    }  请写出两个函数的过程(如果需要形式参数,请给出形参类型和数量,以及返回值

    类型)

触屏版 电脑版
3773考试网 琼ICP备12003406号-1