自考

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

排行热点

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

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

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

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

    #include<iostream>

    using namespace std;

    class base

    {

      int x;

public :

      void setx(int a) { x =a; }

 int getx( ) { return x;

};

void main( )

{

      int *p;

      base a;

      a. setx ( 15) ;

      p = new int( a. getx( )) ;

cout<< *p;

}

52.给出下列程序的输出结果

  #include < iostream >

 #include < complex >

  #include < string >

  using namespace std ;

  void main( )

    complex < int > fsl ( 5 ,6) ;

    complex < float > fs2( 7. 5 ,8.5) ;

    string strl ('' real is: '' ) ;

    string str2 ('' image is : '') ;

    cout<< strl<< fsl. real( )<< ', ' << str2<< fsl. imag( ) << endl;

cout<< strl<< fs2. real( ) << ', '<< str2<< fs2. imag( ) << endl;

}

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

  #include < iostream >

  using namespace std;

  class base

 private :

    int x;

  public :

    void setx(int a) { x = a; }

    int getx( ){ return x;}

 };

  void main( )

    base a,b;

    a. setx( 89) ;

    b=a;

    cout<< a. getx( ) << endl;

 cout<< b. getx( ) << endl;

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

 #include <iostream >

  using namespace std ;

  void main( )

  {

  int a[ ] = { 10,20,30,40 } , * pa = a;

  int * &pb =pa;

  pb + +;

  cout<< * pa<< endl;

 

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

55.在字符串类string中实现一个判断函数,该函数功能是统计某一字符串类对象(仅有单词和空格组成)有多少个单词,同时保存所有单词在字符串中的起始地址(设该字符串不超过100个单词)

 #include<iostream.h>

 #include<string>

 class str{

   string s; int n,a[100],j,1;

   public: str( string& a){s=a;n =0;j =0;l =0;}

     ....test(....);

     int*geta(){return a;}

   } ;

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

 

首页 1 2 3 4 5 6 尾页
责编:may1205