- 首頁(yè)|
- 網(wǎng)校|
- 焚題庫(kù)|
- APP |
- 微信公眾號(hào)
三、改錯(cuò)題(本大題共5小題,每小題2分,共10分)
下面的類定義中有一處錯(cuò)誤,請(qǐng)寫出錯(cuò)誤所在行并給出修改意見
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( );
}