自考

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

排行热点

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

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

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

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

41.#include<iostream.h>

     class point{

     private: float x,y;

public: point( float a,float b) { x = a;y = b; }

   void f( ) {x=0;y=0;}

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

void gety( ) { cout<< y<< endl; }

} ;

  main() {

 point a (3.5) ;

a.getx( )

}

42. #include < iostream. h >

   main( ) {

 int x =7;

   const int * p = &x;

* p=99

   cout<< * p<< endl;

}

43. #include < iostream. h >

   class test{

 private: int x;y;

 public: void f( int a,int b) { x = a;y = b; }

 int max( ) { return(x > y) ? x:y; }

} ;

 main( ) {

 test a;

 a.f(1,3);

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

}

44. #include < iostream. h >

   class test{

     private: int x;

     public:test( int a) { x = a; }

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

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

} ;

   class testl: public test{

     private: int x;

 public : testl ( int a) { x = a; }

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

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

 } ;

45. #include < iostream. h >

   class f{

     private: int x,y;

     public:void fl ( int a,int b) { x = a;y = b ;}

void print( ){ cout<< x<< ''<< y<< endl; }

     } ;

   main( ) {

     f a;

 float x = 1.5 y = 2.0;

a.fl(x,y);

     a.print( );

     }

 

责编:may1205