自考

各地资讯
当前位置:考试网 >> 自学考试 >> 自考真题 >> 工学类 >> C语言程序设计 >> 文章内容

排行热点

全国2013年1月自学考试C++程序设计试题_第5页

来源:考试网 [ 2013年11月23日 ] 【大 中 小】

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

46.将下划线处缺少的部分写在“答题纸”上。源程序如下:

   #include < iostream >

   using namespace std ;

class base

   {

     int a,b;

 public:

     base(int x,int y){a=x;b=y;}

     void show(________________)

     {

 cout<<p.a<<’’,’’<<p.b<<endl;

     }

   }________________

 void main( )

   {

     base b(78,87);

b.show(b);

   }

47.将下划线处缺少的部分写在“答题纸’’上。源程序如下:

 #include <iostream>

    #include <fstream>

    using namespace std ;

    void main( )

    {

        ________________myf(''ab. txt'');//定义输出流文件,并初始化

        ________________<<''This ia a TXT file'';//向文件输入字符串

     myf. close( );

    }

48.在下面程序中的下划线处填上适当的程序(答案写在“答题纸’’上),使程序的输出

结果如下:

 67,90

 源程序如下:

 #include <iostream>

   using namespace std ;

   class base

   {

   private:

     int x,y;

   public:

     void initxy( int a,int b){x=a;y=b;}

     void show( base*p);

   } ;

 inline void base::show(________________)

  {

    cout<<p- >x<<'',''<<p- >y<<endl;

  }

  void print( base *p)

  {

     p -> show(p);

}

  void main( )

  {

    base a;

a.initxy( 67 ,90);

    print(________________);

  }

49.下面程序给出了一个从普通的基类派生出一个模板类的方法,在下划线处填上正确的

    部分(答案写在“答题纸’’上)。

    #include <iostream>

    using namespace std ;

 class Base

    {

public:

      Base( int a){x=a;}

      int Getx(){return;}

      void showb(){cout<<x<<endl;}

    private:

      int x;

 } ;

    template <class T>

    class derived: public Base

    {

    public:

      derived(T a,int b): ________________

    {y=a;}

      T Gety(){return y;}

      void showd(){cout<<y<<'' ''<<Getx()<<endl;}

private:

________________

    } ;

    void main( )

    {Base A(458);

A.showb( );

    derived<char *>B ''It is'',1 357);

B.showd( );

    }

50.下面程序的运行结果如下:

    20,22

    60,22

    将下划线处缺少的部分写在“答题纸’’上。源程序如下:

    #include <iostream>

    using namespace std;

    class base

    {

private:

      const int a;

      static const int b;

    public:

      base(int);

      void Show( );

 };

    ________________=22;

    ________________:a( i ){}       //初始化

    void base::Show( )

    {cout<<a<<”,”<<b<<endl;}

    void main( )

    {

 base al(20),a2(60);

      a1.Show( );

      a2.Show( );

 }

 

责编:may1205